aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-10-10 16:21:55 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-12 16:45:33 +0200
commitb081169a1d0ed70c29678d28271baea8885494db (patch)
treedec26c9de431f31ff34294f0dc6a6779b7afc03f /sonar-ws
parent55dfa5865f5de6ae44f37dcf28985e7501d16fe5 (diff)
downloadsonarqube-b081169a1d0ed70c29678d28271baea8885494db.tar.gz
sonarqube-b081169a1d0ed70c29678d28271baea8885494db.zip
SONAR-8221 Create WS api/components/search_projects paginate and sort
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java80
-rw-r--r--sonar-ws/src/main/protobuf/ws-components.proto6
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/component/SearchProjectsRequestTest.java59
3 files changed, 145 insertions, 0 deletions
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
new file mode 100644
index 00000000000..03292b2bf32
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java
@@ -0,0 +1,80 @@
+/*
+ * 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 static com.google.common.base.Preconditions.checkArgument;
+
+public class SearchProjectsRequest {
+ public static final int MAX_PAGE_SIZE = 500;
+ public static final int DEFAULT_PAGE_SIZE = 100;
+
+ private final int page;
+ private final int pageSize;
+
+ private SearchProjectsRequest(Builder builder) {
+ this.page = builder.page;
+ this.pageSize = builder.pageSize;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public int getPage() {
+ return page;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private Integer page;
+ private Integer pageSize;
+
+ private Builder() {
+ // enforce static factory method
+ }
+
+ public Builder setPage(int page) {
+ this.page = page;
+ return this;
+ }
+
+ public Builder setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ return this;
+ }
+
+ public SearchProjectsRequest build() {
+ if (page == null) {
+ page = 1;
+ }
+ if (pageSize == null) {
+ pageSize = DEFAULT_PAGE_SIZE;
+ }
+
+ checkArgument(pageSize <= MAX_PAGE_SIZE, "Page size must not be greater than %s", MAX_PAGE_SIZE);
+
+ return new SearchProjectsRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/protobuf/ws-components.proto b/sonar-ws/src/main/protobuf/ws-components.proto
index a14966e8acd..4feaf85aa0a 100644
--- a/sonar-ws/src/main/protobuf/ws-components.proto
+++ b/sonar-ws/src/main/protobuf/ws-components.proto
@@ -57,6 +57,12 @@ message BulkUpdateKeyWsResponse {
}
}
+// WS api/components/search_projects
+message SearchProjectsWsResponse {
+ optional sonarqube.ws.commons.Paging paging = 1;
+ repeated Component components = 2;
+}
+
message Component {
optional string id = 1;
optional string key = 2;
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
new file mode 100644
index 00000000000..1db380272ee
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/SearchProjectsRequestTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SearchProjectsRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ SearchProjectsRequest.Builder underTest = SearchProjectsRequest.builder();
+
+ @Test
+ public void default_page_values() {
+ SearchProjectsRequest result = underTest.build();
+
+ assertThat(result.getPage()).isEqualTo(1);
+ assertThat(result.getPageSize()).isEqualTo(100);
+ }
+
+ @Test
+ public void handle_paging_limit_values() {
+ SearchProjectsRequest result = underTest.setPageSize(500).build();
+
+ assertThat(result.getPage()).isEqualTo(1);
+ assertThat(result.getPageSize()).isEqualTo(500);
+ }
+
+ @Test
+ public void fail_if_page_size_greater_than_500() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Page size must not be greater than 500");
+
+ underTest.setPageSize(501).build();
+ }
+}