From f55222d86df4f24636ee3d1ae6d7877a9e952bc6 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 7 Dec 2015 14:22:52 +0100 Subject: [PATCH] Add ITs for auto assign feature --- .../xoo-with-scm/sonar-project.properties | 4 + .../src/main/xoo/sample/Sample.xoo | 12 +++ .../src/main/xoo/sample/Sample.xoo.measures | 2 + .../src/main/xoo/sample/Sample.xoo.scm | 13 +++ .../test/java/it/issue/AutoAssignTest.java | 79 +++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 it/it-projects/issue/xoo-with-scm/sonar-project.properties create mode 100644 it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo create mode 100644 it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.measures create mode 100644 it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.scm create mode 100644 it/it-tests/src/test/java/it/issue/AutoAssignTest.java diff --git a/it/it-projects/issue/xoo-with-scm/sonar-project.properties b/it/it-projects/issue/xoo-with-scm/sonar-project.properties new file mode 100644 index 00000000000..90da9733771 --- /dev/null +++ b/it/it-projects/issue/xoo-with-scm/sonar-project.properties @@ -0,0 +1,4 @@ +sonar.projectKey=sample +sonar.projectName=Sample +sonar.projectVersion=1.0-SNAPSHOT +sonar.sources=src/main/xoo diff --git a/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo b/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo new file mode 100644 index 00000000000..b1210973dd9 --- /dev/null +++ b/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo @@ -0,0 +1,12 @@ +package sample; + +public class Sample { + + public Sample(int i) { + int j = i++; + } + + private String myMethod() { + return "hello"; + } +} diff --git a/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.measures b/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.measures new file mode 100644 index 00000000000..592bb930674 --- /dev/null +++ b/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.measures @@ -0,0 +1,2 @@ +lines:13 +ncloc:13 diff --git a/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.scm b/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.scm new file mode 100644 index 00000000000..f77a3b3930f --- /dev/null +++ b/it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.scm @@ -0,0 +1,13 @@ +1,fabrice,2011-12-04 +1,fabrice,2011-12-04 +2,simon,2015-12-04 +2,simon,2015-12-04 +2,simon,2015-12-04 +3,seb,2015-01-01 +4,julien,2015-12-01 +4,julien,2015-12-01 +4,julien,2015-12-01 +4,julien,2015-12-01 +4,julien,2015-12-01 +4,julien,2015-12-01 +4,julien,2015-12-01 diff --git a/it/it-tests/src/test/java/it/issue/AutoAssignTest.java b/it/it-tests/src/test/java/it/issue/AutoAssignTest.java new file mode 100644 index 00000000000..ad083ada417 --- /dev/null +++ b/it/it-tests/src/test/java/it/issue/AutoAssignTest.java @@ -0,0 +1,79 @@ +package it.issue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.wsclient.issue.IssueQuery; +import org.sonarqube.ws.client.PostRequest; +import org.sonarqube.ws.client.WsResponse; +import util.ProjectAnalysis; +import util.ProjectAnalysisRule; + +import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.newAdminWsClient; +import static util.ItUtils.setServerProperty; + +public class AutoAssignTest extends AbstractIssueTest { + + static final String SIMON_USER = "simon"; + + @Rule + public final ProjectAnalysisRule projectAnalysisRule = ProjectAnalysisRule.from(ORCHESTRATOR); + + ProjectAnalysis projectAnalysis; + + @Before + public void setup() { + ORCHESTRATOR.resetData(); + + String qualityProfileKey = projectAnalysisRule.registerProfile("/issue/IssueActionTest/xoo-one-issue-per-line-profile.xml"); + String projectKey = projectAnalysisRule.registerProject("issue/xoo-with-scm"); + projectAnalysis = projectAnalysisRule.newProjectAnalysis(projectKey) + .withQualityProfile(qualityProfileKey) + .withProperties("sonar.scm.disabled", "false", "sonar.scm.provider", "xoo"); + } + + @After + public void resetData() throws Exception { + // Remove user simon + newAdminWsClient(ORCHESTRATOR).wsConnector().call( + new PostRequest("api/users/deactivate") + .setParam("login", SIMON_USER)); + + // Reset default assignee + setServerProperty(ORCHESTRATOR, "sonar.issues.defaultAssigneeLogin", null); + } + + @Test + public void auto_assign_issues_to_user() throws Exception { + createUser(SIMON_USER, SIMON_USER); + projectAnalysis.run(); + + // Simon has 3 issues + assertThat(search(IssueQuery.create().assignees(SIMON_USER)).list()).hasSize(3); + // Other issues are not assigned as no user have been created on their author + assertThat(search(IssueQuery.create().assigned(false)).list()).hasSize(10); + } + + @Test + public void auto_assign_issues_to_default_assignee() throws Exception { + createUser(SIMON_USER, SIMON_USER); + setServerProperty(ORCHESTRATOR, "sonar.issues.defaultAssigneeLogin", SIMON_USER); + projectAnalysis.run(); + + // Simon has all issues + assertThat(search(IssueQuery.create().assignees(SIMON_USER)).list()).hasSize(13); + // No unassigned issues + assertThat(search(IssueQuery.create().assigned(false)).list()).isEmpty(); + } + + private void createUser(String login, String password) { + WsResponse response = newAdminWsClient(ORCHESTRATOR).wsConnector().call( + new PostRequest("api/users/create") + .setParam("login", login) + .setParam("name", login) + .setParam("password", password)); + assertThat(response.code()).isEqualTo(200); + } +} -- 2.39.5