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;
}
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);
}
}
}
}
- // 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);
}
*/
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;
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
@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())
*/
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;
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;
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());
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());
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();
}
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();
}
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
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;
@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));
}
.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);
}
}