diff options
8 files changed, 177 insertions, 6 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java index 258bcce04df..ceb76423220 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java @@ -22,6 +22,8 @@ package org.sonar.server.projectbranch.ws; import java.util.Arrays; import org.sonar.api.server.ws.WebService; +import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.CONTROLLER; + public class BranchesWs implements WebService { private final BranchWsAction[] actions; @@ -32,7 +34,7 @@ public class BranchesWs implements WebService { @Override public void define(Context context) { - NewController controller = context.createController("api/project_branches") + NewController controller = context.createController(CONTROLLER) .setSince("6.6"); Arrays.stream(actions).forEach(action -> action.define(controller)); controller.done(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java index 1e65b16598a..09c27e8eb4f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java @@ -37,11 +37,11 @@ import org.sonarqube.ws.WsBranches; import static org.sonar.core.util.Protobuf.setNullable; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; +import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_LIST; +import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT; public class ListAction implements BranchWsAction { - private static final String PROJECT_PARAM = "project"; - private final DbClient dbClient; private final UserSession userSession; @@ -52,14 +52,14 @@ public class ListAction implements BranchWsAction { @Override public void define(WebService.NewController context) { - WebService.NewAction action = context.createAction("list") + WebService.NewAction action = context.createAction(ACTION_LIST) .setSince("6.6") .setDescription("List the branches of a project") .setResponseExample(Resources.getResource(getClass(), "list-example.json")) .setHandler(this); action - .createParam(PROJECT_PARAM) + .createParam(PARAM_PROJECT) .setDescription("Project key") .setExampleValue(KEY_PROJECT_EXAMPLE_001) .setRequired(true); @@ -67,7 +67,7 @@ public class ListAction implements BranchWsAction { @Override public void handle(Request request, Response response) throws Exception { - String projectKey = request.mandatoryParam(PROJECT_PARAM); + String projectKey = request.mandatoryParam(PARAM_PROJECT); try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto project = dbClient.componentDao().selectOrFailByKey(dbSession, projectKey); 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 3560fb98efb..f0d0e841f86 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 @@ -28,6 +28,7 @@ import org.sonarqube.ws.client.organization.OrganizationService; import org.sonarqube.ws.client.permission.PermissionsService; import org.sonarqube.ws.client.project.ProjectsService; import org.sonarqube.ws.client.projectanalysis.ProjectAnalysisService; +import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; import org.sonarqube.ws.client.projectlinks.ProjectLinksService; import org.sonarqube.ws.client.qualitygate.QualityGatesService; import org.sonarqube.ws.client.qualityprofile.QualityProfilesService; @@ -69,6 +70,7 @@ class DefaultWsClient implements WsClient { private final RootsService rootsService; private final WebhooksService webhooksService; private final ProjectAnalysisService projectAnalysisService; + private final ProjectBranchesService projectBranchesService; DefaultWsClient(WsConnector wsConnector) { this.wsConnector = wsConnector; @@ -92,6 +94,7 @@ class DefaultWsClient implements WsClient { this.rootsService = new RootsService(wsConnector); this.webhooksService = new WebhooksService(wsConnector); this.projectAnalysisService = new ProjectAnalysisService(wsConnector); + this.projectBranchesService = new ProjectBranchesService(wsConnector); } @Override @@ -198,4 +201,9 @@ class DefaultWsClient implements WsClient { public ProjectAnalysisService projectAnalysis() { return projectAnalysisService; } + + @Override + public ProjectBranchesService projectBranches() { + return projectBranchesService; + } } 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 ec9ba3ef6d0..6083afd01d4 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 @@ -28,6 +28,7 @@ import org.sonarqube.ws.client.organization.OrganizationService; import org.sonarqube.ws.client.permission.PermissionsService; import org.sonarqube.ws.client.project.ProjectsService; import org.sonarqube.ws.client.projectanalysis.ProjectAnalysisService; +import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; import org.sonarqube.ws.client.projectlinks.ProjectLinksService; import org.sonarqube.ws.client.qualitygate.QualityGatesService; import org.sonarqube.ws.client.qualityprofile.QualityProfilesService; @@ -118,4 +119,9 @@ public interface WsClient { * @since 6.3 */ ProjectAnalysisService projectAnalysis(); + + /** + * @since 6.6> + */ + ProjectBranchesService projectBranches(); } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesParameters.java new file mode 100644 index 00000000000..9b056ef0bc7 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesParameters.java @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.projectbranches; + +public class ProjectBranchesParameters { + + public static final String CONTROLLER = "api/project_branches"; + + // actions + public static final String ACTION_LIST = "list"; + + // parameters + public static final String PARAM_PROJECT = "project"; + + private ProjectBranchesParameters() { + // static utility class + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesService.java new file mode 100644 index 00000000000..bb0aecba3d5 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesService.java @@ -0,0 +1,43 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.projectbranches; + +import org.sonarqube.ws.WsBranches.ListWsResponse; +import org.sonarqube.ws.client.BaseService; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.WsConnector; + +import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_LIST; +import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.CONTROLLER; +import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT; + +public class ProjectBranchesService extends BaseService { + + public ProjectBranchesService(WsConnector wsConnector) { + super(wsConnector, CONTROLLER); + } + + public ListWsResponse list(String project) { + GetRequest get = new GetRequest(path(ACTION_LIST)) + .setParam(PARAM_PROJECT, project); + return call(get, ListWsResponse.parser()); + } + +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/package-info.java new file mode 100644 index 00000000000..82e37431572 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbranches/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.projectbranches; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesServiceTest.java new file mode 100644 index 00000000000..c3dbc7c581b --- /dev/null +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectbranches/ProjectBranchesServiceTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.projectbranches; + +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.ws.WsBranches.ListWsResponse; +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.projectbranches.ProjectBranchesParameters.PARAM_PROJECT; + +public class ProjectBranchesServiceTest { + + @Rule + public ServiceTester<ProjectBranchesService> serviceTester = new ServiceTester<>(new ProjectBranchesService(mock(WsConnector.class))); + + private ProjectBranchesService underTest = serviceTester.getInstanceUnderTest(); + + @Test + public void list() { + underTest.list("projectKey"); + + assertThat(serviceTester.getGetParser()).isSameAs(ListWsResponse.parser()); + + GetRequest getRequest = serviceTester.getGetRequest(); + serviceTester.assertThat(getRequest) + .hasPath("list") + .hasParam(PARAM_PROJECT, "projectKey") + .andNoOtherParam(); + } + +} |