aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-10-19 13:28:32 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-10-19 16:33:51 +0200
commit5ad6fee42b1b74f36c3df201fe37d14c969dec44 (patch)
treef897c7de94dfe6840a6af73bed66b8d3d685564a
parent760bbafc902e846a14213f687407a8cd275f8f64 (diff)
downloadsonarqube-5ad6fee42b1b74f36c3df201fe37d14c969dec44.tar.gz
sonarqube-5ad6fee42b1b74f36c3df201fe37d14c969dec44.zip
SONAR-6582 do not return module key on single-module projects
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java36
2 files changed, 40 insertions, 4 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
index ba7ba678e19..8fbc8f83cd1 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
@@ -152,10 +152,10 @@ public class SearchResponseFormat {
ComponentDto project = data.getComponentByUuid(dto.getProjectUuid());
if (project != null) {
issueBuilder.setProject(project.getKey());
- }
- ComponentDto subProject = data.getComponentByUuid(dto.getModuleUuid());
- if (subProject != null) {
- issueBuilder.setSubProject(subProject.getKey());
+ ComponentDto subProject = data.getComponentByUuid(dto.getModuleUuid());
+ if (subProject != null && !subProject.getKey().equals(project.getKey())) {
+ issueBuilder.setSubProject(subProject.getKey());
+ }
}
issueBuilder.setRule(dto.getRuleKey().toString());
issueBuilder.setSeverity(Common.Severity.valueOf(dto.getSeverity()));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
index 88c1e8cfd18..57ad3a5a90c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.issue.ws;
+import java.io.IOException;
import java.util.List;
import org.junit.After;
import org.junit.Before;
@@ -45,15 +46,20 @@ import org.sonar.server.issue.filter.IssueFilterParameters;
import org.sonar.server.issue.index.IssueIndexer;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionUpdater;
+import org.sonar.server.plugins.MimeTypes;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.view.index.ViewDoc;
import org.sonar.server.view.index.ViewIndexer;
+import org.sonar.server.ws.TestResponse;
+import org.sonar.server.ws.WsActionTester;
import org.sonar.server.ws.WsTester;
import org.sonar.server.ws.WsTester.Result;
+import org.sonarqube.ws.Issues;
import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
public class SearchActionComponentsMediumTest {
@@ -112,6 +118,36 @@ public class SearchActionComponentsMediumTest {
}
@Test
+ public void do_not_return_module_key_on_single_module_projects() throws IOException {
+ ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1"));
+ setDefaultProjectPermission(project);
+ ComponentDto module = insertComponent(ComponentTesting.newModuleDto("M1", project).setKey("MK1"));
+ ComponentDto file = insertComponent(ComponentTesting.newFileDto(module, "F1").setKey("FK1"));
+ RuleDto newRule = newRule();
+ IssueDto issueInModule = IssueTesting.newDto(newRule, file, project).setKee("ISSUE_IN_MODULE");
+ IssueDto issueInRootModule = IssueTesting.newDto(newRule, project, project).setKee("ISSUE_IN_ROOT_MODULE");
+ db.issueDao().insert(session, issueInModule, issueInRootModule);
+ session.commit();
+ tester.get(IssueIndexer.class).indexAll();
+
+ WsActionTester actionTester = new WsActionTester(tester.get(SearchAction.class));
+ TestResponse response = actionTester.newRequest()
+ .setMediaType(MimeTypes.PROTOBUF)
+ .execute();
+ Issues.Search searchResponse = Issues.Search.parseFrom(response.getInputStream());
+ assertThat(searchResponse.getIssuesCount()).isEqualTo(2);
+
+ for (Issues.Issue issue : searchResponse.getIssuesList()) {
+ assertThat(issue.getProject()).isEqualTo("PK1");
+ if (issue.getKey().equals("ISSUE_IN_MODULE")) {
+ assertThat(issue.getSubProject()).isEqualTo("MK1");
+ } else if (issue.getKey().equals("ISSUE_IN_ROOT_MODULE")) {
+ assertThat(issue.hasSubProject()).isFalse();
+ }
+ }
+ }
+
+ @Test
public void search_by_project_uuid() throws Exception {
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1"));
setDefaultProjectPermission(project);