aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-02-10 15:16:50 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-02-11 16:55:31 +0100
commit804d9277a03a85d6731b0b4c04a8991c781f0f1d (patch)
tree2478faa0efecc413dd54477d09592c5b146dcbe7
parent85b3058678d7a5d7508f44cc5e40d6c27f255be4 (diff)
downloadsonarqube-804d9277a03a85d6731b0b4c04a8991c781f0f1d.tar.gz
sonarqube-804d9277a03a85d6731b0b4c04a8991c781f0f1d.zip
SONAR-4400 Make tag cloud widget compatible w/ all component types
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java7
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/ComponentTagsAction.java13
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java25
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java19
5 files changed, 47 insertions, 27 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
index d20fc825c44..daf8e70a7d5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
@@ -23,6 +23,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
@@ -654,7 +655,11 @@ public class InternalRubyIssueService implements ServerComponent {
}
public Map<String, Long> listTagsForComponent(String componentUuid, int pageSize) {
- return issueService.listTagsForComponent(componentUuid, pageSize);
+ IssueQuery query = issueQueryService.createFromMap(
+ ImmutableMap.<String, Object>of(
+ "componentUuids", componentUuid,
+ "resolved", false));
+ return issueService.listTagsForComponent(query, pageSize);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
index a7fd194c2bd..307fce9270b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
@@ -389,15 +389,7 @@ public class IssueService implements ServerComponent {
}
}
- // TODO check compatibility with Views, projects, etc.
- public Map<String, Long> listTagsForComponent(String componentUuid, int pageSize) {
- IssueQuery query = IssueQuery.builder()
- .userLogin(UserSession.get().login())
- .userGroups(UserSession.get().userGroups())
- .moduleRootUuids(Arrays.asList(componentUuid))
- .onComponentOnly(false)
- .resolved(false)
- .build();
+ public Map<String, Long> listTagsForComponent(IssueQuery query, int pageSize) {
return issueIndex.countTags(query, pageSize);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ComponentTagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ComponentTagsAction.java
index c68e9d00b78..27bd3393c9f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ComponentTagsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ComponentTagsAction.java
@@ -19,12 +19,15 @@
*/
package org.sonar.server.issue.ws;
+import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.server.issue.IssueQuery;
+import org.sonar.server.issue.IssueQueryService;
import org.sonar.server.issue.IssueService;
import java.util.Map;
@@ -36,9 +39,11 @@ import java.util.Map;
public class ComponentTagsAction implements BaseIssuesWsAction {
private final IssueService service;
+ private final IssueQueryService queryService;
- public ComponentTagsAction(IssueService service) {
+ public ComponentTagsAction(IssueService service, IssueQueryService queryService) {
this.service = service;
+ this.queryService = queryService;
}
@Override
@@ -62,9 +67,13 @@ public class ComponentTagsAction implements BaseIssuesWsAction {
@Override
public void handle(Request request, Response response) throws Exception {
String componentUuid = request.mandatoryParam("componentUuid");
+ IssueQuery query = queryService.createFromMap(
+ ImmutableMap.<String, Object>of(
+ "componentUuids", componentUuid,
+ "resolved", false));
int pageSize = request.mandatoryParamAsInt("ps");
JsonWriter json = response.newJsonWriter().beginObject().name("tags").beginArray();
- for (Map.Entry<String, Long> tag : service.listTagsForComponent(componentUuid, pageSize).entrySet()) {
+ for (Map.Entry<String, Long> tag : service.listTagsForComponent(query, pageSize).entrySet()) {
json.beginObject()
.prop("key", tag.getKey())
.prop("value", tag.getValue())
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
index 0ae5cf970a6..44223ac2208 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
@@ -19,11 +19,7 @@
*/
package org.sonar.server.issue;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Multiset;
-import com.google.common.collect.Sets;
+import com.google.common.collect.*;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -70,6 +66,7 @@ import org.sonar.server.user.NewUser;
import org.sonar.server.user.UserService;
import org.sonar.server.user.db.GroupDao;
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -314,7 +311,7 @@ public class IssueServiceMediumTest {
Issue result = service.createManualIssue(file.key(), manualRule.getKey(), null, "Fix it", Severity.MINOR, 2d);
- IssueDoc manualIssue = (IssueDoc) IssueIndex.getByKey(result.key());
+ IssueDoc manualIssue = IssueIndex.getByKey(result.key());
assertThat(manualIssue.componentUuid()).isEqualTo(file.uuid());
assertThat(manualIssue.projectUuid()).isEqualTo(project.uuid());
assertThat(manualIssue.ruleKey()).isEqualTo(manualRule.getKey());
@@ -340,7 +337,7 @@ public class IssueServiceMediumTest {
Issue result = service.createManualIssue(file.key(), manualRule.getKey(), 1, "Fix it", Severity.MINOR, 2d);
- IssueDoc manualIssue = (IssueDoc) IssueIndex.getByKey(result.key());
+ IssueDoc manualIssue = IssueIndex.getByKey(result.key());
assertThat(manualIssue.componentUuid()).isEqualTo(file.uuid());
assertThat(manualIssue.projectUuid()).isEqualTo(project.uuid());
assertThat(manualIssue.ruleKey()).isEqualTo(manualRule.getKey());
@@ -400,7 +397,7 @@ public class IssueServiceMediumTest {
Issue result = service.createManualIssue(file.key(), manualRule.getKey(), 1, "Fix it", Severity.MINOR, 2d);
- IssueDoc manualIssue = (IssueDoc) IssueIndex.getByKey(result.key());
+ IssueDoc manualIssue = IssueIndex.getByKey(result.key());
assertThat(manualIssue.assignee()).isNull();
}
@@ -418,7 +415,7 @@ public class IssueServiceMediumTest {
Issue result = service.createManualIssue(file.key(), manualRule.getKey(), 1, "Fix it", Severity.MINOR, 2d);
- IssueDoc manualIssue = (IssueDoc) IssueIndex.getByKey(result.key());
+ IssueDoc manualIssue = IssueIndex.getByKey(result.key());
assertThat(manualIssue.assignee()).isNull();
}
@@ -588,9 +585,13 @@ public class IssueServiceMediumTest {
saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED));
saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention")));
- assertThat(service.listTagsForComponent(project.uuid(), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L));
- assertThat(service.listTagsForComponent(project.uuid(), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L);
- assertThat(service.listTagsForComponent("other", 10)).isEmpty();
+ assertThat(service.listTagsForComponent(projectQuery(project.uuid()), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L));
+ assertThat(service.listTagsForComponent(projectQuery(project.uuid()), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L);
+ assertThat(service.listTagsForComponent(projectQuery("other"), 10)).isEmpty();
+ }
+
+ private IssueQuery projectQuery(String projectUuid) {
+ return IssueQuery.builder().projectUuids(Arrays.asList(projectUuid)).resolved(false).build();
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java
index 5ea8d46672d..1948a436690 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java
@@ -23,16 +23,20 @@ import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.server.ws.WebService.Action;
import org.sonar.api.server.ws.WebService.Param;
+import org.sonar.server.issue.IssueQuery;
+import org.sonar.server.issue.IssueQueryService;
import org.sonar.server.issue.IssueService;
import org.sonar.server.ws.WsTester;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -42,13 +46,16 @@ public class ComponentTagsActionTest {
@Mock
private IssueService service;
+ @Mock
+ private IssueQueryService queryService;
+
private ComponentTagsAction componentTagsAction;
private WsTester tester;
@Before
public void setUp() {
- componentTagsAction = new ComponentTagsAction(service);
+ componentTagsAction = new ComponentTagsAction(service, queryService);
tester = new WsTester(new IssuesWs(componentTagsAction));
}
@@ -87,9 +94,15 @@ public class ComponentTagsActionTest {
.put("bug", 32L)
.put("cert", 2L)
.build();
- when(service.listTagsForComponent("polop", 5)).thenReturn(tags);
+ IssueQuery query = mock(IssueQuery.class);
+ ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
+ when(queryService.createFromMap(captor.capture())).thenReturn(query);
+ when(service.listTagsForComponent(query, 5)).thenReturn(tags);
tester.newGetRequest("api/issues", "component_tags").setParam("componentUuid", "polop").setParam("ps", "5").execute()
.assertJson(getClass(), "component-tags.json");
- verify(service).listTagsForComponent("polop", 5);
+ assertThat(captor.getValue())
+ .containsEntry("componentUuids", "polop")
+ .containsEntry("resolved", false);
+ verify(service).listTagsForComponent(query, 5);
}
}