]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5188 Fix bug when issues are on multiple projects
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 31 Oct 2014 10:49:30 +0000 (11:49 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 31 Oct 2014 10:56:34 +0000 (11:56 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issues_on_different_projects.json [new file with mode: 0644]

index 4853acc9bed3779bf17217810534b4e63834f41c..2a22865aaf1b885b4bf6f960476f8b23999e7586 100644 (file)
@@ -584,8 +584,8 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
     for (final ComponentDto component : components) {
       projectsByComponentUuid.put(component.uuid(), Iterables.find(projects, new Predicate<ComponentDto>() {
         @Override
-        public boolean apply(@Nullable ComponentDto input) {
-          return input != null && input.uuid().equals(input.projectUuid());
+        public boolean apply(@Nullable ComponentDto project) {
+          return project != null && project.uuid().equals(component.projectUuid());
         }
       }));
     }
index b4d7537d0f011d3abbb7e1cd6790ebaba728af5d..b8b20f2155545b877163c74b94cb798e58247d86 100644 (file)
@@ -146,10 +146,7 @@ public class SearchActionMediumTest {
     db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
 
     IssueDto issue = IssueTesting.newDto(rule, file, project)
-      .setRule(rule)
       .setDebt(10L)
-      .setProject(project)
-      .setComponent(file)
       .setStatus("OPEN").setResolution("OPEN")
       .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")
       .setSeverity("MAJOR")
@@ -167,6 +164,45 @@ public class SearchActionMediumTest {
     result.assertJson(this.getClass(), "issue.json", false);
   }
 
+  @Test
+  public void issues_on_different_projects() throws Exception {
+    db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com"));
+
+    IssueDto issue = IssueTesting.newDto(rule, file, project)
+      .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")
+      .setStatus("OPEN").setResolution("OPEN")
+      .setSeverity("MAJOR")
+      .setIssueCreationDate(DateUtils.parseDate("2014-09-04"))
+      .setIssueUpdateDate(DateUtils.parseDate("2014-12-04"));
+    db.issueDao().insert(session, issue);
+
+    ComponentDto project2 = ComponentTesting.newProjectDto().setUuid("DBCA").setProjectUuid("DBCA")
+      .setKey("MyProject2");
+    db.componentDao().insert(session, project2);
+    db.snapshotDao().insert(session, SnapshotTesting.createForProject(project2));
+    tester.get(PermissionFacade.class).insertGroupPermission(project2.getId(), DefaultGroups.ANYONE, UserRole.USER, session);
+    tester.get(PermissionFacade.class).insertGroupPermission(project2.getId(), DefaultGroups.ANYONE, UserRole.CODEVIEWER, session);
+    db.issueAuthorizationDao().synchronizeAfter(session, new Date(0));
+
+    ComponentDto file2 = ComponentTesting.newFileDto(project2).setUuid("EDCB")
+      .setKey("MyComponent2")
+      .setSubProjectId(project2.getId());
+    db.componentDao().insert(session, file2);
+
+    IssueDto issue2 = IssueTesting.newDto(rule, file2, project2)
+      .setKee("92fd47d4-b650-4037-80bc-7b112bd4eac2")
+      .setStatus("OPEN").setResolution("OPEN")
+      .setSeverity("MAJOR")
+      .setIssueCreationDate(DateUtils.parseDate("2014-09-04"))
+      .setIssueUpdateDate(DateUtils.parseDate("2014-12-04"));
+    db.issueDao().insert(session, issue2);
+
+    session.commit();
+
+    WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
+    result.assertJson(this.getClass(), "issues_on_different_projects.json", false);
+  }
+
   @Test
   public void issue_with_comment() throws Exception {
     db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
@@ -266,8 +302,6 @@ public class SearchActionMediumTest {
 
     IssueDto issue = IssueTesting.newDto(rule, removedFile, project)
       .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")
-      .setRule(rule)
-      .setProject(project)
       .setComponent(removedFile)
       .setStatus("OPEN").setResolution("OPEN")
       .setSeverity("MAJOR")
@@ -335,10 +369,7 @@ public class SearchActionMediumTest {
     IssueDto issue = IssueTesting.newDto(rule, file, project)
       .setIssueCreationDate(DateUtils.parseDate("2014-09-04"))
       .setIssueUpdateDate(DateUtils.parseDate("2014-12-04"))
-      .setRule(rule)
       .setDebt(10L)
-      .setProject(project)
-      .setComponent(file)
       .setStatus("OPEN")
       .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")
       .setSeverity("MAJOR");
@@ -357,10 +388,7 @@ public class SearchActionMediumTest {
     IssueDto issue = IssueTesting.newDto(rule, file, project)
       .setIssueCreationDate(DateUtils.parseDate("2014-09-04"))
       .setIssueUpdateDate(DateUtils.parseDate("2014-12-04"))
-      .setRule(rule)
       .setDebt(10L)
-      .setProject(project)
-      .setComponent(file)
       .setStatus("OPEN")
       .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")
       .setSeverity("MAJOR");
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issues_on_different_projects.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issues_on_different_projects.json
new file mode 100644 (file)
index 0000000..521cd83
--- /dev/null
@@ -0,0 +1,58 @@
+{
+  "issues": [
+    {
+      "key": "82fd47d4-b650-4037-80bc-7b112bd4eac2",
+      "component": "MyComponent",
+      "project": "MyProject",
+      "rule": "xoo:x1",
+      "status": "OPEN",
+      "resolution": "OPEN",
+      "severity": "MAJOR",
+      "updateDate": "2014-12-04T00:00:00+0100",
+      "fUpdateAge": "less than a minute"
+    },
+    {
+      "key": "92fd47d4-b650-4037-80bc-7b112bd4eac2",
+      "component": "MyComponent2",
+      "project": "MyProject2",
+      "rule": "xoo:x1",
+      "status": "OPEN",
+      "resolution": "OPEN",
+      "severity": "MAJOR",
+      "updateDate": "2014-12-04T00:00:00+0100",
+      "fUpdateAge": "less than a minute"
+    }
+  ],
+  "components": [
+    {
+      "uuid": "BCDE",
+      "key": "MyComponent",
+      "enabled" : true
+    },
+    {
+      "uuid": "ABCD",
+      "key": "MyProject",
+      "enabled" : true
+    },
+    {
+      "uuid": "EDCB",
+      "key": "MyComponent2",
+      "enabled" : true
+    },
+    {
+      "uuid": "DBCA",
+      "key": "MyProject2",
+      "enabled" : true
+    }
+  ],
+  "projects": [
+    {
+      "uuid": "ABCD",
+      "key": "MyProject"
+    },
+    {
+      "uuid": "DBCA",
+      "key": "MyProject2"
+    }
+  ]
+}