]> source.dussan.org Git - sonarqube.git/commitdiff
Add ITs for auto assign feature
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 7 Dec 2015 13:22:52 +0000 (14:22 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 7 Dec 2015 16:58:31 +0000 (17:58 +0100)
it/it-projects/issue/xoo-with-scm/sonar-project.properties [new file with mode: 0644]
it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo [new file with mode: 0644]
it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.measures [new file with mode: 0644]
it/it-projects/issue/xoo-with-scm/src/main/xoo/sample/Sample.xoo.scm [new file with mode: 0644]
it/it-tests/src/test/java/it/issue/AutoAssignTest.java [new file with mode: 0644]

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 (file)
index 0000000..90da973
--- /dev/null
@@ -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 (file)
index 0000000..b121097
--- /dev/null
@@ -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 (file)
index 0000000..592bb93
--- /dev/null
@@ -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 (file)
index 0000000..f77a3b3
--- /dev/null
@@ -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 (file)
index 0000000..ad083ad
--- /dev/null
@@ -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);
+  }
+}