aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-14 17:28:11 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-10-18 17:01:19 +0200
commit3ecbbba4ff5fa8062a7d52ad01051c9785dbbcd2 (patch)
tree6eeb8f056b262c99048bd0c8c59f29d583567ca5 /sonar-ws
parent84fcbdd5a897a26faf0177e57f30c8f611fdd732 (diff)
downloadsonarqube-3ecbbba4ff5fa8062a7d52ad01051c9785dbbcd2.tar.gz
sonarqube-3ecbbba4ff5fa8062a7d52ad01051c9785dbbcd2.zip
SONAR-8287 Add filter parameter in api/components/search_projects
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java40
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java11
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java12
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java55
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/component/SearchProjectsRequestTest.java9
5 files changed, 113 insertions, 14 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 b7e71d43a3e..2deb2884b23 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
@@ -21,6 +21,7 @@ package org.sonarqube.ws.client.component;
import com.google.common.base.Joiner;
import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse;
+import org.sonarqube.ws.WsComponents.SearchProjectsWsResponse;
import org.sonarqube.ws.WsComponents.SearchWsResponse;
import org.sonarqube.ws.WsComponents.ShowWsResponse;
import org.sonarqube.ws.WsComponents.TreeWsResponse;
@@ -29,10 +30,17 @@ import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;
+import static org.sonar.api.server.ws.WebService.Param;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_BULK_UPDATE_KEY;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH_PROJECTS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SHOW;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_UPDATE_KEY;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.CONTROLLER_COMPONENTS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_KEY;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FROM;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_KEY;
@@ -44,15 +52,15 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_TO;
public class ComponentsService extends BaseService {
public ComponentsService(WsConnector wsConnector) {
- super(wsConnector, "api/components");
+ super(wsConnector, CONTROLLER_COMPONENTS);
}
public SearchWsResponse search(SearchWsRequest request) {
- GetRequest get = new GetRequest(path("search"))
- .setParam("qualifiers", Joiner.on(",").join(request.getQualifiers()))
- .setParam("p", request.getPage())
- .setParam("ps", request.getPageSize())
- .setParam("q", request.getQuery());
+ GetRequest get = new GetRequest(path(ACTION_SEARCH))
+ .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(request.getQualifiers()))
+ .setParam(Param.PAGE, request.getPage())
+ .setParam(Param.PAGE_SIZE, request.getPageSize())
+ .setParam(Param.TEXT_QUERY, request.getQuery());
return call(get, SearchWsResponse.parser());
}
@@ -62,10 +70,10 @@ public class ComponentsService extends BaseService {
.setParam(PARAM_BASE_COMPONENT_KEY, request.getBaseComponentKey())
.setParam(PARAM_QUALIFIERS, inlineMultipleParamValue(request.getQualifiers()))
.setParam(PARAM_STRATEGY, request.getStrategy())
- .setParam("p", request.getPage())
- .setParam("ps", request.getPageSize())
- .setParam("q", request.getQuery())
- .setParam("s", request.getSort());
+ .setParam(Param.PAGE, request.getPage())
+ .setParam(Param.PAGE_SIZE, request.getPageSize())
+ .setParam(Param.TEXT_QUERY, request.getQuery())
+ .setParam(Param.SORT, request.getSort());
return call(get, TreeWsResponse.parser());
}
@@ -77,7 +85,7 @@ public class ComponentsService extends BaseService {
}
public void updateKey(UpdateWsRequest request) {
- PostRequest post = new PostRequest(path("update_key"))
+ PostRequest post = new PostRequest(path(ACTION_UPDATE_KEY))
.setParam(PARAM_ID, request.getId())
.setParam(PARAM_KEY, request.getKey())
.setParam(PARAM_NEW_KEY, request.getNewKey());
@@ -86,7 +94,7 @@ public class ComponentsService extends BaseService {
}
public BulkUpdateKeyWsResponse bulkUpdateKey(BulkUpdateWsRequest request) {
- PostRequest post = new PostRequest(path("bulk_update_key"))
+ PostRequest post = new PostRequest(path(ACTION_BULK_UPDATE_KEY))
.setParam(PARAM_ID, request.getId())
.setParam(PARAM_KEY, request.getKey())
.setParam(PARAM_FROM, request.getFrom())
@@ -94,4 +102,12 @@ public class ComponentsService extends BaseService {
return call(post, BulkUpdateKeyWsResponse.parser());
}
+
+ public SearchProjectsWsResponse searchProjects(SearchProjectsRequest request) {
+ GetRequest get = new GetRequest(path(ACTION_SEARCH_PROJECTS))
+ .setParam(PARAM_FILTER, request.getFilter())
+ .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/ComponentsWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
index 4ae95bf46b0..7301b14808b 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
@@ -20,13 +20,19 @@
package org.sonarqube.ws.client.component;
public class ComponentsWsParameters {
+
+ public static final String CONTROLLER_COMPONENTS = "api/components";
+
// actions
+ public static final String ACTION_SEARCH = "search";
+ public static final String ACTION_UPDATE_KEY = "update_key";
public static final String ACTION_TREE = "tree";
-
public static final String ACTION_SHOW = "show";
+ public static final String ACTION_BULK_UPDATE_KEY = "bulk_update_key";
+ public static final String ACTION_SEARCH_PROJECTS = "search_projects";
+
// parameters
public static final String PARAM_QUALIFIERS = "qualifiers";
-
public static final String PARAM_LANGUAGE = "language";
public static final String PARAM_BASE_COMPONENT_ID = "baseComponentId";
public static final String PARAM_BASE_COMPONENT_KEY = "baseComponentKey";
@@ -37,6 +43,7 @@ public class ComponentsWsParameters {
public static final String PARAM_FROM = "from";
public static final String PARAM_TO = "to";
public static final String PARAM_DRY_RUN = "dryRun";
+ public static final String PARAM_FILTER = "filter";
private ComponentsWsParameters() {
// static utility class
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 03292b2bf32..c8ba9187cb5 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
@@ -28,10 +28,16 @@ public class SearchProjectsRequest {
private final int page;
private final int pageSize;
+ private final String filter;
private SearchProjectsRequest(Builder builder) {
this.page = builder.page;
this.pageSize = builder.pageSize;
+ this.filter = builder.filter;
+ }
+
+ public String getFilter() {
+ return filter;
}
public int getPageSize() {
@@ -49,11 +55,17 @@ public class SearchProjectsRequest {
public static class Builder {
private Integer page;
private Integer pageSize;
+ private String filter;
private Builder() {
// enforce static factory method
}
+ public Builder setFilter(String filter) {
+ this.filter = filter;
+ 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
new file mode 100644
index 00000000000..5627eaf8beb
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonarqube.ws.client.component;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService.Param;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.mockito.Mockito.mock;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER;
+
+public class ComponentsServiceTest {
+
+ @Rule
+ public ServiceTester<ComponentsService> serviceTester = new ServiceTester<>(new ComponentsService(mock(WsConnector.class)));
+
+ private ComponentsService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void search_projects() {
+ underTest.searchProjects(SearchProjectsRequest.builder()
+ .setFilter("ncloc > 10")
+ .setPage(3)
+ .setPageSize(10)
+ .build());
+
+ serviceTester.assertThat(serviceTester.getGetRequest())
+ .hasPath("search_projects")
+ .hasParam(PARAM_FILTER, "ncloc > 10")
+ .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 1db380272ee..49aaafa722f 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
@@ -34,6 +34,15 @@ public class SearchProjectsRequestTest {
SearchProjectsRequest.Builder underTest = SearchProjectsRequest.builder();
@Test
+ public void filter_parameter() throws Exception {
+ SearchProjectsRequest result = underTest
+ .setFilter("ncloc > 10")
+ .build();
+
+ assertThat(result.getFilter()).isEqualTo("ncloc > 10");
+ }
+
+ @Test
public void default_page_values() {
SearchProjectsRequest result = underTest.build();