aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-12-12 17:16:05 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-12-13 14:48:31 +0100
commita01c99bb547c5f9318eb536f03e473e8cb6f1126 (patch)
treeb830158f84979d9ba83b8bd43617326949be9775 /sonar-ws
parentfb9f4f8314cc44d45aef2f41a82520d969080444 (diff)
downloadsonarqube-a01c99bb547c5f9318eb536f03e473e8cb6f1126.tar.gz
sonarqube-a01c99bb547c5f9318eb536f03e473e8cb6f1126.zip
SONAR-8467 Create WS api/project_analyses/search
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/EventCategory.java2
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java1
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/SearchRequest.java102
-rw-r--r--sonar-ws/src/main/protobuf/ws-projectanalyses.proto14
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/SearchRequestTest.java75
5 files changed, 193 insertions, 1 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/EventCategory.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/EventCategory.java
index bb5e878996f..7c2dc512ee6 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/EventCategory.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/EventCategory.java
@@ -21,7 +21,7 @@
package org.sonarqube.ws.client.projectanalysis;
public enum EventCategory {
- VERSION("Version"), OTHER("Other");
+ VERSION("Version"), OTHER("Other"), QUALITY_PROFILE("Profile"), QUALITY_GATE("Alert");
private final String label;
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java
index 7241726019d..abf1e0840b8 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java
@@ -26,6 +26,7 @@ public class ProjectAnalysesWsParameters {
public static final String PARAM_NAME = "name";
public static final String PARAM_DESCRIPTION = "description";
public static final String PARAM_EVENT = "event";
+ public static final String PARAM_PROJECT = "project";
private ProjectAnalysesWsParameters() {
// static access only
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/SearchRequest.java
new file mode 100644
index 00000000000..3f914a869b6
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/SearchRequest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.projectanalysis;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
+public class SearchRequest {
+ public static final int DEFAULT_PAGE_SIZE = 100;
+ public static final int MAX_SIZE = 500;
+
+ private final String project;
+ private final EventCategory category;
+ private final int page;
+ private final int pageSize;
+
+ public SearchRequest(Builder builder) {
+ this.project = builder.project;
+ this.category = builder.category;
+ this.page = builder.page;
+ this.pageSize = builder.pageSize;
+ }
+
+ public String getProject() {
+ return project;
+ }
+
+ @CheckForNull
+ public EventCategory getCategory() {
+ return category;
+ }
+
+ public int getPage() {
+ return page;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String project;
+ private EventCategory category;
+ private int page = 1;
+ private int pageSize = DEFAULT_PAGE_SIZE;
+
+ private Builder() {
+ // enforce static factory method
+ }
+
+ public Builder setProject(String project) {
+ this.project = project;
+ return this;
+ }
+
+ public Builder setCategory(@Nullable EventCategory category) {
+ this.category = category;
+ return this;
+ }
+
+ public Builder setPage(int page) {
+ this.page = page;
+ return this;
+ }
+
+ public Builder setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ return this;
+ }
+
+ public SearchRequest build() {
+ requireNonNull(project, "Project is required");
+ checkArgument(pageSize <= MAX_SIZE, "Page size must be lower than or equal to " + MAX_SIZE);
+ return new SearchRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/protobuf/ws-projectanalyses.proto b/sonar-ws/src/main/protobuf/ws-projectanalyses.proto
index b06aca07713..3b4ea562bb9 100644
--- a/sonar-ws/src/main/protobuf/ws-projectanalyses.proto
+++ b/sonar-ws/src/main/protobuf/ws-projectanalyses.proto
@@ -20,6 +20,8 @@ syntax = "proto2";
package sonarqube.ws.projectanalysis;
+import "ws-commons.proto";
+
option java_package = "org.sonarqube.ws";
option java_outer_classname = "ProjectAnalyses";
option optimize_for = SPEED;
@@ -34,6 +36,12 @@ message UpdateEventResponse {
optional Event event = 1;
}
+// WS api/project_analyses/search
+message SearchResponse {
+ optional sonarqube.ws.commons.Paging paging = 1;
+ repeated Analysis analyses = 2;
+}
+
message Event {
optional string key = 1;
optional string analysis = 2;
@@ -41,3 +49,9 @@ message Event {
optional string name = 4;
optional string description = 5;
}
+
+message Analysis {
+ optional string key = 1;
+ optional string date = 2;
+ repeated Event events = 3;
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/SearchRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/SearchRequestTest.java
new file mode 100644
index 00000000000..7b21661df95
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/SearchRequestTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.projectanalysis;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonarqube.ws.client.projectanalysis.EventCategory.QUALITY_GATE;
+
+public class SearchRequestTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private SearchRequest.Builder underTest = SearchRequest.builder();
+
+ @Test
+ public void search_request() {
+ SearchRequest result = underTest
+ .setProject("P1")
+ .setCategory(QUALITY_GATE)
+ .setPage(2)
+ .setPageSize(500)
+ .build();
+
+ assertThat(result.getProject()).isEqualTo("P1");
+ assertThat(result.getPage()).isEqualTo(2);
+ assertThat(result.getPageSize()).isEqualTo(500);
+ assertThat(result.getCategory()).isEqualTo(QUALITY_GATE);
+ }
+
+ @Test
+ public void page_default_values() {
+ SearchRequest result = underTest.setProject("P1").build();
+
+ assertThat(result.getPage()).isEqualTo(1);
+ assertThat(result.getPageSize()).isEqualTo(100);
+ }
+
+ @Test
+ public void fail_if_project_is_null() {
+ expectedException.expect(NullPointerException.class);
+
+ underTest.build();
+ }
+
+ @Test
+ public void fail_if_page_size_greater_than_500() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Page size must be lower than or equal to 500");
+
+ underTest.setProject("P1")
+ .setPageSize(501)
+ .build();
+ }
+}