]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7871 Fix searching issues by type in IssueService client WS
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 13 Jul 2016 15:52:54 +0000 (17:52 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 15 Jul 2016 06:28:31 +0000 (08:28 +0200)
it/it-tests/src/test/java/it/issue/IssueSearchTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java

index 59b509effe67bac716cc15a996a300c90afe6eed..12ceaa1ac3b12426e27c8944d4b84113dd77b3bc 100644 (file)
@@ -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<org.sonarqube.ws.Issues.Issue> 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<Component> components, final String key) {
-    return Iterables.find(components, new Predicate<Component>() {
-      @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.<String, Object>of(
-      "manual_key", "invalidclassname",
-      "name", "InvalidClassName",
-      "markdown_description", "Invalid class name"));
+  private static Component findComponent(Collection<Component> components, final String key) {
+    return Iterables.find(components, input -> key.equals(input.key()));
   }
 
 }
index 6b2766e45273d9b7641cbf2ea90b67fde29169fc..080653b08b5765f83a75a2a475e4c5cebf5ead9a 100644 (file)
@@ -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());
   }
 }