aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-24 16:21:30 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-24 16:21:30 +0200
commit2415c0342d0d36fd070332256c6a752d4556e6d9 (patch)
tree322378084b085a034750bce754cf53df0f46e8e9 /sonar-ws
parent7fbdae0b91dd971fe4f5f5991987369319faf3de (diff)
downloadsonarqube-2415c0342d0d36fd070332256c6a752d4556e6d9.tar.gz
sonarqube-2415c0342d0d36fd070332256c6a752d4556e6d9.zip
SONAR-8315 Make facets optional in WS api/components/search_projects
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java1
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java15
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java3
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/component/SearchProjectsRequestTest.java24
4 files changed, 43 insertions, 0 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 2deb2884b23..eb648f24109 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
@@ -106,6 +106,7 @@ public class ComponentsService extends BaseService {
public SearchProjectsWsResponse searchProjects(SearchProjectsRequest request) {
GetRequest get = new GetRequest(path(ACTION_SEARCH_PROJECTS))
.setParam(PARAM_FILTER, request.getFilter())
+ .setParam(Param.FACETS, request.getFacets())
.setParam(Param.PAGE, request.getPage())
.setParam(Param.PAGE_SIZE, request.getPageSize());
return call(get, SearchProjectsWsResponse.parser());
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java
index 8ae6cb22d8e..3b6ebceeceb 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java
@@ -20,9 +20,12 @@
package org.sonarqube.ws.client.component;
+import java.util.ArrayList;
+import java.util.List;
import javax.annotation.CheckForNull;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
public class SearchProjectsRequest {
public static final int MAX_PAGE_SIZE = 500;
@@ -31,11 +34,13 @@ public class SearchProjectsRequest {
private final int page;
private final int pageSize;
private final String filter;
+ private final List<String> facets;
private SearchProjectsRequest(Builder builder) {
this.page = builder.page;
this.pageSize = builder.pageSize;
this.filter = builder.filter;
+ this.facets = builder.facets;
}
@CheckForNull
@@ -43,6 +48,10 @@ public class SearchProjectsRequest {
return filter;
}
+ public List<String> getFacets() {
+ return facets;
+ }
+
public int getPageSize() {
return pageSize;
}
@@ -59,6 +68,7 @@ public class SearchProjectsRequest {
private Integer page;
private Integer pageSize;
private String filter;
+ private List<String> facets = new ArrayList<>();
private Builder() {
// enforce static factory method
@@ -69,6 +79,11 @@ public class SearchProjectsRequest {
return this;
}
+ public Builder setFacets(List<String> facets) {
+ this.facets = requireNonNull(facets);
+ return this;
+ }
+
public Builder setPage(int page) {
this.page = page;
return this;
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 5627eaf8beb..b79214d3983 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
@@ -26,6 +26,7 @@ import org.sonar.api.server.ws.WebService.Param;
import org.sonarqube.ws.client.ServiceTester;
import org.sonarqube.ws.client.WsConnector;
+import static java.util.Collections.singletonList;
import static org.mockito.Mockito.mock;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER;
@@ -40,6 +41,7 @@ public class ComponentsServiceTest {
public void search_projects() {
underTest.searchProjects(SearchProjectsRequest.builder()
.setFilter("ncloc > 10")
+ .setFacets(singletonList("ncloc"))
.setPage(3)
.setPageSize(10)
.build());
@@ -47,6 +49,7 @@ public class ComponentsServiceTest {
serviceTester.assertThat(serviceTester.getGetRequest())
.hasPath("search_projects")
.hasParam(PARAM_FILTER, "ncloc > 10")
+ .hasParam(Param.FACETS, singletonList("ncloc"))
.hasParam(Param.PAGE, 3)
.hasParam(Param.PAGE_SIZE, 10)
.andNoOtherParam();
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/component/SearchProjectsRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/SearchProjectsRequestTest.java
index 49aaafa722f..023d89a8600 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/component/SearchProjectsRequestTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/SearchProjectsRequestTest.java
@@ -24,6 +24,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
public class SearchProjectsRequestTest {
@@ -43,6 +44,29 @@ public class SearchProjectsRequestTest {
}
@Test
+ public void set_facets() throws Exception {
+ SearchProjectsRequest result = underTest
+ .setFacets(singletonList("ncloc"))
+ .build();
+
+ assertThat(result.getFacets()).containsOnly("ncloc");
+ }
+
+ @Test
+ public void facets_are_empty_by_default() throws Exception {
+ SearchProjectsRequest result = underTest.build();
+
+ assertThat(result.getFacets()).isEmpty();
+ }
+
+ @Test
+ public void fail_if_facets_is_null() {
+ expectedException.expect(NullPointerException.class);
+
+ underTest.setFacets(null);
+ }
+
+ @Test
public void default_page_values() {
SearchProjectsRequest result = underTest.build();