diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-11 21:20:18 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-15 13:44:59 +0100 |
commit | 89a93e795af89c98f5e99de60620c21287f7889e (patch) | |
tree | 105152b4d0ac83e11cdc6749b2e37c8b3b24e338 /sonar-ws | |
parent | 8909ccd99b9bc5874f24395519d66e2bcb9bdacb (diff) | |
download | sonarqube-89a93e795af89c98f5e99de60620c21287f7889e.tar.gz sonarqube-89a93e795af89c98f5e99de60620c21287f7889e.zip |
SONAR-7187 WS api/ce/activity handles queue and past CE tasks
Diffstat (limited to 'sonar-ws')
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java | 10 | ||||
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java | 3 | ||||
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/ce/ActivityWsRequest.java | 127 | ||||
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java | 57 | ||||
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeWsParameters.java | 35 | ||||
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/ce/package-info.java | 25 | ||||
-rw-r--r-- | sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java | 90 | ||||
-rw-r--r-- | sonar-ws/src/test/java/org/sonarqube/ws/client/issue/ActivityWsRequestTest.java (renamed from sonar-ws/src/test/java/org/sonarqube/ws/client/issue/SearchWsRequestTest.java) | 2 |
8 files changed, 347 insertions, 2 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java index 664960aec8d..abec779c8c5 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpWsClient.java @@ -19,6 +19,7 @@ */ package org.sonarqube.ws.client; +import org.sonarqube.ws.client.ce.CeService; import org.sonarqube.ws.client.component.ComponentsService; import org.sonarqube.ws.client.issue.IssuesService; import org.sonarqube.ws.client.measure.MeasuresService; @@ -35,6 +36,7 @@ import org.sonarqube.ws.client.usertoken.UserTokensService; */ public class HttpWsClient implements WsClient { + private final WsConnector wsConnector; private final PermissionsService permissionsService; private final ComponentsService componentsService; private final QualityProfilesService qualityProfilesService; @@ -43,7 +45,7 @@ public class HttpWsClient implements WsClient { private final QualityGatesService qualityGatesService; private final MeasuresService measuresService; private final SystemService systemService; - private final WsConnector wsConnector; + private final CeService ceService; public HttpWsClient(WsConnector wsConnector) { this.wsConnector = wsConnector; @@ -55,6 +57,7 @@ public class HttpWsClient implements WsClient { this.qualityGatesService = new QualityGatesService(wsConnector); this.measuresService = new MeasuresService(wsConnector); this.systemService = new SystemService(wsConnector); + this.ceService = new CeService(wsConnector); } @Override @@ -101,4 +104,9 @@ public class HttpWsClient implements WsClient { public SystemService system() { return systemService; } + + @Override + public CeService ce() { + return ceService; + } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java index db7ab7ba245..7f865292fc7 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java @@ -19,6 +19,7 @@ */ package org.sonarqube.ws.client; +import org.sonarqube.ws.client.ce.CeService; import org.sonarqube.ws.client.component.ComponentsService; import org.sonarqube.ws.client.issue.IssuesService; import org.sonarqube.ws.client.measure.MeasuresService; @@ -48,5 +49,7 @@ public interface WsClient { SystemService system(); + CeService ce(); + WsConnector wsConnector(); } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/ActivityWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/ActivityWsRequest.java new file mode 100644 index 00000000000..a0e53ace029 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/ActivityWsRequest.java @@ -0,0 +1,127 @@ +/* + * 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.ce; + +import java.util.List; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class ActivityWsRequest { + private String componentId; + private String componentQuery; + private List<String> status; + private String type; + private Boolean onlyCurrents; + private String minSubmittedAt; + private String maxExecutedAt; + private Integer page; + private Integer pageSize; + + @CheckForNull + public String getComponentId() { + return componentId; + } + + public ActivityWsRequest setComponentId(@Nullable String componentId) { + this.componentId = componentId; + return this; + } + + @CheckForNull + public String getComponentQuery() { + return componentQuery; + } + + public ActivityWsRequest setComponentQuery(@Nullable String componentQuery) { + this.componentQuery = componentQuery; + return this; + } + + @CheckForNull + public List<String> getStatus() { + return status; + } + + public ActivityWsRequest setStatus(@Nullable List<String> status) { + this.status = status; + return this; + } + + @CheckForNull + public String getType() { + return type; + } + + public ActivityWsRequest setType(@Nullable String type) { + this.type = type; + return this; + } + + @CheckForNull + public Boolean getOnlyCurrents() { + return onlyCurrents; + } + + public ActivityWsRequest setOnlyCurrents(@Nullable Boolean onlyCurrents) { + this.onlyCurrents = onlyCurrents; + return this; + } + + @CheckForNull + public String getMinSubmittedAt() { + return minSubmittedAt; + } + + public ActivityWsRequest setMinSubmittedAt(@Nullable String minSubmittedAt) { + this.minSubmittedAt = minSubmittedAt; + return this; + } + + @CheckForNull + public String getMaxExecutedAt() { + return maxExecutedAt; + } + + public ActivityWsRequest setMaxExecutedAt(@Nullable String maxExecutedAt) { + this.maxExecutedAt = maxExecutedAt; + return this; + } + + @CheckForNull + public Integer getPage() { + return page; + } + + public ActivityWsRequest setPage(@Nullable Integer page) { + this.page = page; + return this; + } + + @CheckForNull + public Integer getPageSize() { + return pageSize; + } + + public ActivityWsRequest setPageSize(@Nullable Integer pageSize) { + this.pageSize = pageSize; + return this; + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java new file mode 100644 index 00000000000..b11cfdfb60e --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java @@ -0,0 +1,57 @@ +/* + * 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.ce; + +import org.sonarqube.ws.WsCe.ActivityResponse; +import org.sonarqube.ws.client.BaseService; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.WsConnector; + +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MAX_EXECUTED_AT; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MIN_SUBMITTED_AT; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_ONLY_CURRENTS; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_STATUS; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_TYPE; + +public class CeService extends BaseService { + + public CeService(WsConnector wsConnector) { + super(wsConnector, "api/ce"); + } + + public ActivityResponse activity(ActivityWsRequest request) { + return call( + new GetRequest(path("activity")) + .setParam(PARAM_COMPONENT_ID, request.getComponentId()) + .setParam(PARAM_COMPONENT_QUERY, request.getComponentQuery()) + .setParam(PARAM_STATUS, inlineMultipleParamValue(request.getStatus())) + .setParam(PARAM_TYPE, request.getType()) + .setParam(PARAM_MAX_EXECUTED_AT, request.getMaxExecutedAt()) + .setParam(PARAM_MIN_SUBMITTED_AT, request.getMinSubmittedAt()) + .setParam(PARAM_ONLY_CURRENTS, request.getOnlyCurrents()) + .setParam("p", request.getPage()) + .setParam("ps", request.getPageSize()), + ActivityResponse.parser()); + } + +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeWsParameters.java new file mode 100644 index 00000000000..3b4fc97e4f1 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeWsParameters.java @@ -0,0 +1,35 @@ +/* + * 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.ce; + +public class CeWsParameters { + public static final String PARAM_COMPONENT_ID = "componentId"; + public static final String PARAM_COMPONENT_QUERY = "componentQuery"; + public static final String PARAM_TYPE = "type"; + public static final String PARAM_STATUS = "status"; + public static final String PARAM_ONLY_CURRENTS = "onlyCurrents"; + public static final String PARAM_MIN_SUBMITTED_AT = "minSubmittedAt"; + public static final String PARAM_MAX_EXECUTED_AT = "maxExecutedAt"; + + private CeWsParameters() { + // prevent instantiation + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/package-info.java new file mode 100644 index 00000000000..46846e51219 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/package-info.java @@ -0,0 +1,25 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonarqube.ws.client.ce; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java new file mode 100644 index 00000000000..d7094f75495 --- /dev/null +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java @@ -0,0 +1,90 @@ +/* + * 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.ce; + +import com.google.common.collect.ImmutableList; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.ws.WsCe.ActivityResponse; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.ServiceTester; +import org.sonarqube.ws.client.WsConnector; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MAX_EXECUTED_AT; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MIN_SUBMITTED_AT; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_ONLY_CURRENTS; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_STATUS; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_TYPE; + +public class CeServiceTest { + private static final String VALUE_COMPONENT_ID = "component-uuid"; + private static final String VALUE_COMPONENT_QUERY = "component-query"; + private static final String VALUE_TASK_STATUS_1 = "task-status"; + private static final String VALUE_TASK_STATUS_2 = "task-status-2"; + private static final String VALUE_TASK_TYPE = "task-type"; + private static final int VALUE_PAGE = 1; + private static final int VALUE_PAGE_SIZE = 10; + private static final String VALUE_MAX_EXECUTED_AT = "2015-09-17T23:34:59+0200"; + private static final String VALUE_MIN_SUBMITTED_AT = "2015-09-17T23:34:59+0200"; + private static final boolean VALUE_ONLY_CURRENTS = true; + + @Rule + public ServiceTester<CeService> serviceTester = new ServiceTester<>(new CeService(mock(WsConnector.class))); + + CeService underTest = serviceTester.getInstanceUnderTest(); + + @Test + public void search() { + ActivityWsRequest request = new ActivityWsRequest() + .setComponentId(VALUE_COMPONENT_ID) + .setComponentQuery(VALUE_COMPONENT_QUERY) + .setStatus(ImmutableList.of(VALUE_TASK_STATUS_1, VALUE_TASK_STATUS_2)) + .setType(VALUE_TASK_TYPE) + .setPage(VALUE_PAGE) + .setPageSize(VALUE_PAGE_SIZE) + .setMaxExecutedAt(VALUE_MAX_EXECUTED_AT) + .setMinSubmittedAt(VALUE_MIN_SUBMITTED_AT) + .setOnlyCurrents(VALUE_ONLY_CURRENTS) + .setPage(1) + .setPageSize(1); + + underTest.activity(request); + GetRequest result = serviceTester.getGetRequest(); + + assertThat(serviceTester.getGetParser()).isSameAs(ActivityResponse.parser()); + serviceTester.assertThat(result) + .hasPath("activity") + .hasParam(PARAM_COMPONENT_ID, VALUE_COMPONENT_ID) + .hasParam(PARAM_COMPONENT_QUERY, VALUE_COMPONENT_QUERY) + .hasParam(PARAM_STATUS, VALUE_TASK_STATUS_1 + "," + VALUE_TASK_STATUS_2) + .hasParam(PARAM_TYPE, VALUE_TASK_TYPE) + .hasParam(PARAM_MAX_EXECUTED_AT, VALUE_MAX_EXECUTED_AT) + .hasParam(PARAM_MIN_SUBMITTED_AT, VALUE_MIN_SUBMITTED_AT) + .hasParam(PARAM_ONLY_CURRENTS, VALUE_ONLY_CURRENTS) + .hasParam("p", 1) + .hasParam("ps", 1) + .andNoOtherParam(); + } +} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/issue/SearchWsRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/issue/ActivityWsRequestTest.java index 9fc4bac7ccd..c8115e322d0 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/issue/SearchWsRequestTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/issue/ActivityWsRequestTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -public class SearchWsRequestTest { +public class ActivityWsRequestTest { private static final ImmutableList<String> LIST_OF_STRINGS = ImmutableList.of("A", "B"); private static final String SOME_STRING = "some string"; public static final int SOME_INT = 894352; |