diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-07-28 13:41:21 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2016-07-28 17:31:15 +0200 |
commit | 9823de5d25275b7cf8df914243f0f71fd13c0b71 (patch) | |
tree | 437eca51bf6865743db69c6b90c64f1cc9dcd457 | |
parent | 7d256b42cf12089fc468b99c0a44204f2879d87b (diff) | |
download | sonarqube-9823de5d25275b7cf8df914243f0f71fd13c0b71.tar.gz sonarqube-9823de5d25275b7cf8df914243f0f71fd13c0b71.zip |
add ProjectLinksService
4 files changed, 180 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java index 110c8d0377a..28eb7b0d8b0 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java @@ -25,6 +25,7 @@ import org.sonarqube.ws.client.issue.IssuesService; import org.sonarqube.ws.client.measure.MeasuresService; import org.sonarqube.ws.client.permission.PermissionsService; import org.sonarqube.ws.client.project.ProjectsService; +import org.sonarqube.ws.client.projectlinks.ProjectLinksService; import org.sonarqube.ws.client.qualitygate.QualityGatesService; import org.sonarqube.ws.client.qualityprofile.QualityProfilesService; import org.sonarqube.ws.client.rule.RulesService; @@ -51,6 +52,7 @@ class DefaultWsClient implements WsClient { private final CeService ceService; private final RulesService rulesService; private final ProjectsService projectsService; + private final ProjectLinksService projectLinksService; DefaultWsClient(WsConnector wsConnector) { this.wsConnector = wsConnector; @@ -65,6 +67,7 @@ class DefaultWsClient implements WsClient { this.ceService = new CeService(wsConnector); this.rulesService = new RulesService(wsConnector); this.projectsService = new ProjectsService(wsConnector); + this.projectLinksService = new ProjectLinksService(wsConnector); } @Override @@ -126,4 +129,9 @@ class DefaultWsClient implements WsClient { public ProjectsService projects() { return projectsService; } + + @Override + public ProjectLinksService projectLinks() { + return projectLinksService; + } } 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 36369c45e5c..869b871c869 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 @@ -25,6 +25,7 @@ import org.sonarqube.ws.client.issue.IssuesService; import org.sonarqube.ws.client.measure.MeasuresService; import org.sonarqube.ws.client.permission.PermissionsService; import org.sonarqube.ws.client.project.ProjectsService; +import org.sonarqube.ws.client.projectlinks.ProjectLinksService; import org.sonarqube.ws.client.qualitygate.QualityGatesService; import org.sonarqube.ws.client.qualityprofile.QualityProfilesService; import org.sonarqube.ws.client.rule.RulesService; @@ -76,4 +77,9 @@ public interface WsClient { * @since 5.5 */ ProjectsService projects(); + + /** + * @since 6.1 + */ + ProjectLinksService projectLinks(); } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksService.java new file mode 100644 index 00000000000..9e18e85043e --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksService.java @@ -0,0 +1,64 @@ +/* + * 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.projectlinks; + +import org.sonarqube.ws.WsProjectLinks.CreateWsResponse; +import org.sonarqube.ws.WsProjectLinks.SearchWsResponse; +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.projectlinks.ProjectLinksWsParameters.ACTION_CREATE; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.ACTION_DELETE; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.ACTION_SEARCH; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_ID; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_NAME; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_ID; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_KEY; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_URL; + +public class ProjectLinksService extends BaseService { + + public ProjectLinksService(WsConnector wsConnector) { + super(wsConnector, "api/project_links"); + } + + public SearchWsResponse search(SearchWsRequest request) { + return call(new GetRequest(path(ACTION_SEARCH)) + .setParam(PARAM_PROJECT_KEY, request.getProjectKey()) + .setParam(PARAM_PROJECT_ID, request.getProjectId()), + SearchWsResponse.parser()); + } + + public CreateWsResponse create(CreateWsRequest request) { + return call(new PostRequest(path(ACTION_CREATE)) + .setParam(PARAM_PROJECT_KEY, request.getProjectKey()) + .setParam(PARAM_PROJECT_ID, request.getProjectId()) + .setParam(PARAM_NAME, request.getName()) + .setParam(PARAM_URL, request.getUrl()), + CreateWsResponse.parser()); + } + + public void delete(DeleteWsRequest request) { + call(new PostRequest(path(ACTION_DELETE)) + .setParam(PARAM_ID, request.getId())); + } +} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectlinks/ProjectLinksServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectlinks/ProjectLinksServiceTest.java new file mode 100644 index 00000000000..4127c8727bf --- /dev/null +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectlinks/ProjectLinksServiceTest.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.projectlinks; + +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.ws.WsProjectLinks.CreateWsResponse; +import org.sonarqube.ws.WsProjectLinks.SearchWsResponse; +import org.sonarqube.ws.client.GetRequest; +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.projectlinks.ProjectLinksWsParameters.PARAM_ID; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_NAME; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_ID; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_KEY; +import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_URL; + +public class ProjectLinksServiceTest { + private static final String PROJECT_ID_VALUE = "project_id_value"; + private static final String PROJECT_KEY_VALUE = "project_key_value"; + private static final String NAME_VALUE = "name_value"; + private static final String URL_VALUE = "url_value"; + private static final long ID_VALUE = 175; + + @Rule + public ServiceTester<ProjectLinksService> serviceTester = new ServiceTester<>(new ProjectLinksService(mock(WsConnector.class))); + + private ProjectLinksService underTest = serviceTester.getInstanceUnderTest(); + + @Test + public void search_does_GET_request() { + underTest.search(new SearchWsRequest() + .setProjectId(PROJECT_ID_VALUE) + .setProjectKey(PROJECT_KEY_VALUE)); + + assertThat(serviceTester.getGetParser()).isSameAs(SearchWsResponse.parser()); + + GetRequest getRequest = serviceTester.getGetRequest(); + + serviceTester.assertThat(getRequest) + .hasPath("search") + .hasParam(PARAM_PROJECT_ID, PROJECT_ID_VALUE) + .hasParam(PARAM_PROJECT_KEY, PROJECT_KEY_VALUE) + .andNoOtherParam(); + } + + @Test + public void create_does_POST_request() { + underTest.create(new CreateWsRequest() + .setProjectId(PROJECT_ID_VALUE) + .setProjectKey(PROJECT_KEY_VALUE) + .setName(NAME_VALUE) + .setUrl(URL_VALUE)); + + assertThat(serviceTester.getPostParser()).isSameAs(CreateWsResponse.parser()); + + PostRequest postRequest = serviceTester.getPostRequest(); + + serviceTester.assertThat(postRequest) + .hasPath("create") + .hasParam(PARAM_PROJECT_ID, PROJECT_ID_VALUE) + .hasParam(PARAM_PROJECT_KEY, PROJECT_KEY_VALUE) + .hasParam(PARAM_NAME, NAME_VALUE) + .hasParam(PARAM_URL, URL_VALUE) + .andNoOtherParam(); + } + + @Test + public void delete_does_POST_request() { + underTest.delete(new DeleteWsRequest().setId(ID_VALUE)); + + assertThat(serviceTester.getPostParser()).isNull(); + + PostRequest postRequest = serviceTester.getPostRequest(); + + serviceTester.assertThat(postRequest) + .hasPath("delete") + .hasParam(PARAM_ID, String.valueOf(ID_VALUE)) + .andNoOtherParam(); + } +} |