From 8557587c5a9622113071e2e968ef6dd3e8c279e6 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 13 Jul 2016 17:52:54 +0200 Subject: [PATCH] SONAR-7871 Fix searching issues by type in IssueService client WS --- .../test/java/it/issue/IssueSearchTest.java | 41 ++++++++----------- .../ws/client/issue/IssuesService.java | 4 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/it/it-tests/src/test/java/it/issue/IssueSearchTest.java b/it/it-tests/src/test/java/it/issue/IssueSearchTest.java index 59b509effe6..12ceaa1ac3b 100644 --- a/it/it-tests/src/test/java/it/issue/IssueSearchTest.java +++ b/it/it-tests/src/test/java/it/issue/IssueSearchTest.java @@ -19,9 +19,6 @@ */ package it.issue; -import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.selenium.Selenese; @@ -42,12 +39,13 @@ import org.sonar.wsclient.issue.Issue; import org.sonar.wsclient.issue.IssueQuery; import org.sonar.wsclient.issue.Issues; import org.sonarqube.ws.Common; -import org.sonarqube.ws.MediaTypes; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.WsResponse; +import org.sonarqube.ws.client.issue.SearchWsRequest; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; +import static org.sonarqube.ws.Issues.SearchWsResponse; import static util.ItUtils.newAdminWsClient; import static util.ItUtils.runProjectAnalysis; import static util.ItUtils.setServerProperty; @@ -305,30 +303,23 @@ public class IssueSearchTest extends AbstractIssueTest { assertThat(issue.getType()).isEqualTo(Common.RuleType.CODE_SMELL); } + @Test + public void search_issues_by_types() throws IOException { + assertThat(searchIssues(new SearchWsRequest().setTypes(singletonList("CODE_SMELL"))).getPaging().getTotal()).isEqualTo(142); + assertThat(searchIssues(new SearchWsRequest().setTypes(singletonList("BUG"))).getPaging().getTotal()).isEqualTo(122); + assertThat(searchIssues(new SearchWsRequest().setTypes(singletonList("VULNERABILITY"))).getPaging().getTotal()).isEqualTo(8); + } + private List searchByRuleKey(String... ruleKey) throws IOException { - WsResponse response = newAdminWsClient(ORCHESTRATOR) - .wsConnector() - .call(new GetRequest("api/issues/search") - .setParam("rules", Joiner.on(",").join(ruleKey)) - .setMediaType(MediaTypes.PROTOBUF)); - org.sonarqube.ws.Issues.SearchWsResponse searchWsResponse = org.sonarqube.ws.Issues.SearchWsResponse.parseFrom(response.contentStream()); - return searchWsResponse.getIssuesList(); + return searchIssues(new SearchWsRequest().setRules(asList(ruleKey))).getIssuesList(); } - private static Component findComponent(Collection components, final String key) { - return Iterables.find(components, new Predicate() { - @Override - public boolean apply(Component input) { - return key.equals(input.key()); - } - }); + private SearchWsResponse searchIssues(SearchWsRequest request) throws IOException { + return newAdminWsClient(ORCHESTRATOR).issues().search(request); } - private static void createManualRule() { - ORCHESTRATOR.getServer().adminWsClient().post("/api/rules/create", ImmutableMap.of( - "manual_key", "invalidclassname", - "name", "InvalidClassName", - "markdown_description", "Invalid class name")); + private static Component findComponent(Collection components, final String key) { + return Iterables.find(components, input -> key.equals(input.key())); } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java index 6b2766e4527..080653b08b5 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java @@ -56,6 +56,7 @@ import static org.sonarqube.ws.client.issue.IssueFilterParameters.SEVERITIES; import static org.sonarqube.ws.client.issue.IssueFilterParameters.SINCE_LEAK_PERIOD; import static org.sonarqube.ws.client.issue.IssueFilterParameters.STATUSES; import static org.sonarqube.ws.client.issue.IssueFilterParameters.TAGS; +import static org.sonarqube.ws.client.issue.IssueFilterParameters.TYPES; public class IssuesService extends BaseService { @@ -101,7 +102,8 @@ public class IssuesService extends BaseService { .setParam(SEVERITIES, inlineMultipleParamValue(request.getSeverities())) .setParam(SINCE_LEAK_PERIOD, request.getSinceLeakPeriod()) .setParam(STATUSES, inlineMultipleParamValue(request.getStatuses())) - .setParam(TAGS, inlineMultipleParamValue(request.getTags())), + .setParam(TAGS, inlineMultipleParamValue(request.getTags())) + .setParam(TYPES, inlineMultipleParamValue(request.getTypes())), SearchWsResponse.parser()); } } -- 2.39.5