]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5953 Fix search for issues on unit tests
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 29 Jan 2015 10:13:50 +0000 (11:13 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 29 Jan 2015 10:13:50 +0000 (11:13 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionComponentsMediumTest/search_by_file_key.json [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionComponentsMediumTest/search_by_test_key.json [new file with mode: 0644]

index e44236e77f4c8b250e4f9454b8947d0604743b2e..a1881f884489add6004a3cb72a0ba02ff144dff3 100644 (file)
@@ -236,7 +236,7 @@ public class IssueQueryService implements ServerComponent {
         builder.moduleUuids(directoryModuleUuids);
         builder.directories(directoryPaths);
         addComponentsBelowDirectory(builder, fileUuids);
-      } else if (Qualifiers.FILE.equals(uniqueQualifier)) {
+      } else if (Qualifiers.FILE.equals(uniqueQualifier) || Qualifiers.UNIT_TEST_FILE.equals(uniqueQualifier)) {
         builder.fileUuids(allComponentUuids);
       } else {
         throw new IllegalArgumentException("Unable to set search root context for components " + Joiner.on(',').join(allComponentUuids));
index 39abbf50bb46445e460fb441084cf6411dedf655..bd2103c30e4dabecb804eb28aadb0d6268d72978 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.utils.DateUtils;
@@ -193,6 +194,31 @@ public class SearchActionComponentsMediumTest {
       .assertJson(this.getClass(), "no_issue.json", false);
   }
 
+  @Test
+  public void search_by_file_key() throws Exception {
+    ComponentDto project = insertComponent(ComponentTesting.newProjectDto("ABCD").setKey("MyProject"));
+    setDefaultProjectPermission(project);
+    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, "BCDE").setKey("MyComponent"));
+    ComponentDto unitTest = insertComponent(ComponentTesting.newFileDto(project, "CDEF").setQualifier(Qualifiers.UNIT_TEST_FILE).setKey("MyComponentTest"));
+    RuleDto rule = newRule();
+    IssueDto issueOnFile = IssueTesting.newDto(rule, file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
+    IssueDto issueOnTest = IssueTesting.newDto(rule, unitTest, project).setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4");
+    db.issueDao().insert(session, issueOnFile, issueOnTest);
+    session.commit();
+    tester.get(IssueIndexer.class).indexAll();
+
+    wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+      .setParam(IssueFilterParameters.COMPONENTS, file.key())
+      .execute()
+      .assertJson(this.getClass(), "search_by_file_key.json", false);
+
+    wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+      .setParam(IssueFilterParameters.COMPONENTS, unitTest.key())
+      .execute()
+      .assertJson(this.getClass(), "search_by_test_key.json", false);
+
+  }
+
   @Test
   public void display_file_facet() throws Exception {
     ComponentDto project = insertComponent(ComponentTesting.newProjectDto("ABCD").setKey("MyProject"));
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionComponentsMediumTest/search_by_file_key.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionComponentsMediumTest/search_by_file_key.json
new file mode 100644 (file)
index 0000000..f13cd2e
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "total": 1,
+  "p": 1,
+  "issues": [
+    {
+      "key": "82fd47d4-b650-4037-80bc-7b112bd4eac2",
+      "component": "MyComponent",
+      "project": "MyProject",
+      "rule": "xoo:x1"
+    }
+  ]
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionComponentsMediumTest/search_by_test_key.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionComponentsMediumTest/search_by_test_key.json
new file mode 100644 (file)
index 0000000..76968ce
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "total": 1,
+  "p": 1,
+  "issues": [
+    {
+      "key": "2bd4eac2-b650-4037-80bc-7b1182fd47d4",
+      "component": "MyComponentTest",
+      "project": "MyProject",
+      "rule": "xoo:x1"
+    }
+  ]
+}