]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4400 Make tag cloud widget compatible w/ all component types
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 10 Feb 2015 14:16:50 +0000 (15:16 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 11 Feb 2015 15:55:31 +0000 (16:55 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/ComponentTagsAction.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java

index d20fc825c446e1fec47e52f70b0a33ecad5ed14f..daf8e70a7d5b7775f7b7ef895db778da0f13982d 100644 (file)
@@ -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);
   }
 
 }
index a7fd194c2bd1b0600e8fc11d88d6d9630589cf0e..307fce9270b2ebcb7e9413adc8de93291bfc04dc 100644 (file)
@@ -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);
   }
 
index c68e9d00b78bc588b8b62279937619d1cfdbb80a..27bd3393c9facaacce78cee96d1b7c0b81b15044 100644 (file)
  */
 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())
index 0ae5cf970a6cd00381c11ecee9d7e9b4e241800b..44223ac2208eea067d94fbbe9756e3cf41f97926 100644 (file)
  */
 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
index 5ea8d46672dd3b6f767d2500578c03b80a313f36..1948a4366905f341586bf2a672d57fd005157aee 100644 (file)
@@ -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);
   }
 }