diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-07-29 17:41:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-29 17:41:48 +0200 |
commit | 7b93c4de175621ce43236126a4a239534bed229e (patch) | |
tree | 25d9743ec3e0610a24bd877ee878e50a2386e2cc /sonar-ws | |
parent | f6f754fc4a291b18ea4c9d183b7a2bfecbe1e2e3 (diff) | |
download | sonarqube-7b93c4de175621ce43236126a4a239534bed229e.tar.gz sonarqube-7b93c4de175621ce43236126a4a239534bed229e.zip |
SONAR-7924 Modify WS api/qualitygates/select to accept project key (#1126)
Diffstat (limited to 'sonar-ws')
3 files changed, 129 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java index bd00874f57a..fa8a57ab4b9 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java @@ -22,9 +22,11 @@ package org.sonarqube.ws.client.qualitygate; import org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse; import org.sonarqube.ws.client.BaseService; import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsConnector; import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_ANALYSIS_ID; +import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_GATE_ID; import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_ID; import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_KEY; @@ -41,4 +43,11 @@ public class QualityGatesService extends BaseService { .setParam(PARAM_PROJECT_KEY, request.getProjectKey()), ProjectStatusWsResponse.parser()); } + + public void associateProject(SelectWsRequest request) { + call(new PostRequest(path("select")) + .setParam(PARAM_GATE_ID, request.getGateId()) + .setParam(PARAM_PROJECT_ID, request.getProjectId()) + .setParam(PARAM_PROJECT_KEY, request.getProjectKey())); + } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/SelectWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/SelectWsRequest.java new file mode 100644 index 00000000000..a3dc530f7b7 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/SelectWsRequest.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.qualitygate; + +import javax.annotation.CheckForNull; + +public class SelectWsRequest { + private long gateId; + private Long projectId; + private String projectKey; + + public long getGateId() { + return gateId; + } + + public SelectWsRequest setGateId(long gateId) { + this.gateId = gateId; + return this; + } + + @CheckForNull + public Long getProjectId() { + return projectId; + } + + public SelectWsRequest setProjectId(Long projectId) { + this.projectId = projectId; + return this; + } + + @CheckForNull + public String getProjectKey() { + return projectKey; + } + + public SelectWsRequest setProjectKey(String projectKey) { + this.projectKey = projectKey; + return this; + } +} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/qualitygate/QualityGatesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualitygate/QualityGatesServiceTest.java new file mode 100644 index 00000000000..3000be63863 --- /dev/null +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualitygate/QualityGatesServiceTest.java @@ -0,0 +1,63 @@ + +/* + * 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.qualitygate; + +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.ws.client.PostRequest; +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.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_ID; +import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_KEY; +import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_GATE_ID; + +public class QualityGatesServiceTest { + private static final Long PROJECT_ID_VALUE = 195L; + private static final String PROJECT_KEY_VALUE = "project_key_value"; + private static final Long GATE_ID_VALUE = 243L; + + @Rule + public ServiceTester<QualityGatesService> serviceTester = new ServiceTester<>(new QualityGatesService(mock(WsConnector.class))); + + private QualityGatesService underTest = serviceTester.getInstanceUnderTest(); + + @Test + public void associate_project_does_POST_request() { + underTest.associateProject(new SelectWsRequest() + .setGateId(GATE_ID_VALUE) + .setProjectId(PROJECT_ID_VALUE) + .setProjectKey(PROJECT_KEY_VALUE)); + + assertThat(serviceTester.getPostParser()).isNull(); + + PostRequest postRequest = serviceTester.getPostRequest(); + + serviceTester.assertThat(postRequest) + .hasPath("select") + .hasParam(PARAM_GATE_ID, String.valueOf(GATE_ID_VALUE)) + .hasParam(PARAM_PROJECT_ID, String.valueOf(PROJECT_ID_VALUE)) + .hasParam(PARAM_PROJECT_KEY, PROJECT_KEY_VALUE) + .andNoOtherParam(); + } +} |