diff options
author | Daniel Schwarz <daniel.schwarz@sonarsource.com> | 2017-08-16 11:39:01 +0200 |
---|---|---|
committer | Daniel Schwarz <bartfastiel@users.noreply.github.com> | 2017-08-16 13:31:41 +0200 |
commit | 7ea165042aa3af5f656249bd0cf5acadeef29dba (patch) | |
tree | 77d33677835b6ebd43d1d914ffff303b60d90d9c /sonar-ws | |
parent | 664eb7854d14ac3b45bae30cfc7d9243bf7ddb2a (diff) | |
download | sonarqube-7ea165042aa3af5f656249bd0cf5acadeef29dba.tar.gz sonarqube-7ea165042aa3af5f656249bd0cf5acadeef29dba.zip |
improve tests of api/components
Diffstat (limited to 'sonar-ws')
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java | 2 | ||||
-rw-r--r-- | sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java | 98 |
2 files changed, 99 insertions, 1 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java index b7186af495f..496511543f8 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java @@ -70,7 +70,7 @@ public class ComponentsService extends BaseService { .setParam(Param.PAGE, request.getPage()) .setParam(Param.PAGE_SIZE, request.getPageSize()) .setParam(Param.TEXT_QUERY, request.getQuery()) - .setParam(Param.SORT, request.getSort()); + .setParam(Param.SORT, inlineMultipleParamValue(request.getSort())); return call(get, TreeWsResponse.parser()); } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java index 36d6b5d565e..7316d14e93a 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java @@ -21,11 +21,14 @@ package org.sonarqube.ws.client.component; import org.junit.Rule; import org.junit.Test; +import org.sonarqube.ws.WsComponents; import org.sonarqube.ws.client.ServiceTester; import org.sonarqube.ws.client.WsConnector; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; +import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.sonar.api.server.ws.WebService.Param.ASCENDING; import static org.sonar.api.server.ws.WebService.Param.FACETS; @@ -54,6 +57,7 @@ public class ComponentsServiceTest { .setAdditionalFields(singletonList("analysisDate")) .build()); + assertThat(serviceTester.getGetParser()).isSameAs(WsComponents.SearchProjectsWsResponse.parser()); serviceTester.assertThat(serviceTester.getGetRequest()) .hasPath("search_projects") .hasParam(PARAM_FILTER, "ncloc > 10") @@ -75,6 +79,7 @@ public class ComponentsServiceTest { .setPageSize(10) .build()); + assertThat(serviceTester.getGetParser()).isSameAs(WsComponents.SearchProjectsWsResponse.parser()); serviceTester.assertThat(serviceTester.getGetRequest()) .hasPath("search_projects") .hasParam(PARAM_FILTER, "ncloc > 10") @@ -84,4 +89,97 @@ public class ComponentsServiceTest { .andNoOtherParam(); } + @Test + public void show() { + String key = randomAlphanumeric(20); + String id = randomAlphanumeric(20); + underTest.show(new ShowWsRequest() + .setKey(key) + .setId(id)); + + assertThat(serviceTester.getGetParser()).isSameAs(WsComponents.ShowWsResponse.parser()); + serviceTester.assertThat(serviceTester.getGetRequest()) + .hasPath("show") + .hasParam("component", key) + .hasParam("componentId", id) + .andNoOtherParam(); + } + + @Test + public void suggestions() { + SuggestionsWsRequest.More more = SuggestionsWsRequest.More.BRC; + String s = randomAlphanumeric(20); + underTest.suggestions(SuggestionsWsRequest.builder() + .setMore(more) + .setS(s) + .setRecentlyBrowsed(asList("key-1", "key-2")) + .build()); + + // in this case no protobuf parser is used + assertThat(serviceTester.getGetParser()).isNull(); + + serviceTester.assertThat(serviceTester.getGetRequest()) + .hasPath("suggestions") + .hasParam("more", more.toString()) + .hasParam("s", s) + .hasParam("recentlyBrowsed", "key-1,key-2") + .andNoOtherParam(); + } + + @Test + public void search() { + String organization = randomAlphanumeric(20); + int page = 17; + int pageSize = 39; + String textQuery = randomAlphanumeric(20); + underTest.search(new SearchWsRequest() + .setOrganization(organization) + .setQualifiers(asList("q1", "q2")) + .setPage(page) + .setPageSize(pageSize) + .setQuery(textQuery) + ); + + assertThat(serviceTester.getGetParser()).isSameAs(WsComponents.SearchWsResponse.parser()); + serviceTester.assertThat(serviceTester.getGetRequest()) + .hasPath("search") + .hasParam("organization", organization) + .hasParam("qualifiers", "q1,q2") + .hasParam("p", page) + .hasParam("ps", pageSize) + .hasParam("q", textQuery) + .andNoOtherParam(); + } + + @Test + public void tree() { + String componentId = randomAlphanumeric(20); + String componentKey = randomAlphanumeric(20); + String strategy = randomAlphanumeric(20); + int page = 17; + int pageSize = 39; + String query = randomAlphanumeric(20); + underTest.tree(new TreeWsRequest() + .setBaseComponentId(componentId) + .setBaseComponentKey(componentKey) + .setQualifiers(asList("q1", "q2")) + .setStrategy(strategy) + .setPage(page) + .setPageSize(pageSize) + .setQuery(query) + .setSort(asList("sort1", "sort2"))); + + assertThat(serviceTester.getGetParser()).isSameAs(WsComponents.TreeWsResponse.parser()); + serviceTester.assertThat(serviceTester.getGetRequest()) + .hasPath("tree") + .hasParam("componentId", componentId) + .hasParam("component", componentKey) + .hasParam("qualifiers", "q1,q2") + .hasParam("strategy", strategy) + .hasParam("p", page) + .hasParam("ps", pageSize) + .hasParam("q", query) + .hasParam("s", "sort1,sort2") + .andNoOtherParam(); + } } |