From: Julien Lancelot Date: Mon, 28 Apr 2014 16:27:49 +0000 (+0200) Subject: SONAR-5111 Declare "api/action_plans" WS with org.sonar.api.server.WebService X-Git-Tag: 4.4-RC1~1368 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=06c69c318fc3e744da3c8de992a0637f51de76bd;p=sonarqube.git SONAR-5111 Declare "api/action_plans" WS with org.sonar.api.server.WebService --- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java index e4aa651dba7..31fd348d2a5 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java @@ -289,6 +289,10 @@ public interface WebService extends ServerExtension { return newParam; } + /** + * @deprecated since 4.4. Use {@link #createParam(String paramKey)} instead. + */ + @Deprecated public NewAction createParam(String paramKey, @Nullable String description) { createParam(paramKey).setDescription(description); return this; diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ws/ActionPlanWs.java b/sonar-server/src/main/java/org/sonar/server/issue/ws/ActionPlanWs.java new file mode 100644 index 00000000000..894518843f8 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/issue/ws/ActionPlanWs.java @@ -0,0 +1,115 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.sonar.server.issue.ws; + +import org.sonar.api.server.ws.RailsHandler; +import org.sonar.api.server.ws.WebService; + +public class ActionPlanWs implements WebService { + + @Override + public void define(Context context) { + NewController controller = context.createController("api/action_plans"); + controller.setDescription("Action plans"); + + WebService.NewAction search = controller.createAction("search") + .setDescription("Get a list of action plans. Requires Browse permission on project") + .setSince("3.6") + .setHandler(RailsHandler.INSTANCE); + addProjectParam(search); + + WebService.NewAction create = controller.createAction("create") + .setDescription("Create an action plan. Requires Administer permission on project") + .setSince("3.6") + .setPost(true) + .setHandler(RailsHandler.INSTANCE); + addNameParam(create); + addDescriptionParam(create); + addDeadLineParam(create); + addProjectParam(create); + + WebService.NewAction update = controller.createAction("update") + .setDescription("Update an action plan. Requires Administer permission on project") + .setSince("3.6") + .setPost(true) + .setHandler(RailsHandler.INSTANCE); + addKeyParam(update); + addNameParam(update); + addDescriptionParam(update); + addDeadLineParam(update); + + WebService.NewAction delete = controller.createAction("delete") + .setDescription("Delete an action plan. Requires Administer permission on project") + .setSince("3.6") + .setPost(true) + .setHandler(RailsHandler.INSTANCE); + addKeyParam(delete); + + WebService.NewAction open = controller.createAction("open") + .setDescription("Open an action plan. Requires Administer permission on project") + .setSince("3.6") + .setPost(true) + .setHandler(RailsHandler.INSTANCE); + addKeyParam(open); + + WebService.NewAction close = controller.createAction("close") + .setDescription("Close an action plan. Requires Administer permission on project") + .setSince("3.6") + .setPost(true) + .setHandler(RailsHandler.INSTANCE); + addKeyParam(close); + + controller.done(); + } + + private static NewParam addKeyParam(WebService.NewAction action) { + return action.createParam("key") + .setDescription("Key of the action plan") + .setExampleValue("3f19de90-1521-4482-a737-a311758ff513") + .setRequired(true); + } + + private static NewParam addNameParam(WebService.NewAction action) { + return action.createParam("name") + .setDescription("Name of the action plan") + .setExampleValue("Version 3.6") + .setRequired(true); + } + + private static NewParam addDescriptionParam(WebService.NewAction action) { + return action.createParam("description") + .setDescription("Description of the action plan") + .setExampleValue("Version 3.6"); + } + + private static NewParam addDeadLineParam(WebService.NewAction action) { + return action.createParam("deadLine") + .setDescription("Due date of the action plan. Format: YYYY-MM-DD") + .setExampleValue("2013-12-31"); + } + + private static NewParam addProjectParam(WebService.NewAction action) { + return action.createParam("project") + .setDescription("Project key") + .setExampleValue("org.codehaus.sonar:sonar") + .setRequired(true); + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index bd2ceb9d76f..e1d1a899d40 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -19,8 +19,6 @@ */ package org.sonar.server.platform; -import org.sonar.core.cluster.LocalNonBlockingWorkQueue; - import com.google.common.collect.Lists; import org.apache.commons.configuration.BaseConfiguration; import org.sonar.api.config.EmailSettings; @@ -39,6 +37,7 @@ import org.sonar.api.utils.HttpDownloader; import org.sonar.api.utils.System2; import org.sonar.api.utils.UriReader; import org.sonar.api.utils.internal.TempFolderCleaner; +import org.sonar.core.cluster.LocalNonBlockingWorkQueue; import org.sonar.core.component.SnapshotPerspectives; import org.sonar.core.component.db.ComponentDao; import org.sonar.core.config.CorePropertyDefinitions; @@ -90,6 +89,7 @@ import org.sonar.server.es.ESNode; import org.sonar.server.issue.*; import org.sonar.server.issue.filter.IssueFilterService; import org.sonar.server.issue.filter.IssueFilterWs; +import org.sonar.server.issue.ws.ActionPlanWs; import org.sonar.server.issue.ws.IssueShowWsHandler; import org.sonar.server.issue.ws.IssuesWs; import org.sonar.server.notifications.NotificationCenter; @@ -351,6 +351,7 @@ class ServerComponents { pico.addSingleton(IssueFilterWs.class); pico.addSingleton(IssueShowWsHandler.class); pico.addSingleton(IssuesWs.class); + pico.addSingleton(ActionPlanWs.class); // issues actions pico.addSingleton(AssignAction.class); diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ws/ActionPlanWsTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ws/ActionPlanWsTest.java new file mode 100644 index 00000000000..ec3223d1f09 --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/issue/ws/ActionPlanWsTest.java @@ -0,0 +1,189 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.sonar.server.issue.ws; + +import org.junit.Test; +import org.sonar.api.server.ws.RailsHandler; +import org.sonar.api.server.ws.WebService; +import org.sonar.server.ws.WsTester; + +import static org.fest.assertions.Assertions.assertThat; + +public class ActionPlanWsTest { + + WsTester tester = new WsTester(new ActionPlanWs()); + + @Test + public void define_action_plan_controller() throws Exception { + WebService.Controller controller = tester.controller("api/action_plans"); + assertThat(controller).isNotNull(); + assertThat(controller.description()).isNotEmpty(); + assertThat(controller.actions()).hasSize(6); + } + + @Test + public void define_search_action() throws Exception { + WebService.Controller controller = tester.controller("api/action_plans"); + + WebService.Action action = controller.action("search"); + assertThat(action).isNotNull(); + assertThat(action.handler()).isInstanceOf(RailsHandler.class); + assertThat(action.since()).isEqualTo("3.6"); + assertThat(action.isPost()).isFalse(); + assertThat(action.isInternal()).isFalse(); + assertThat(action.params()).hasSize(1); + + WebService.Param project = action.param("project"); + assertThat(project).isNotNull(); + assertThat(project.description()).isNotNull(); + assertThat(project.exampleValue()).isNotNull(); + assertThat(project.isRequired()).isTrue(); + } + + @Test + public void define_create_action() throws Exception { + WebService.Controller controller = tester.controller("api/action_plans"); + + WebService.Action action = controller.action("create"); + assertThat(action).isNotNull(); + assertThat(action.handler()).isInstanceOf(RailsHandler.class); + assertThat(action.since()).isEqualTo("3.6"); + assertThat(action.isPost()).isTrue(); + assertThat(action.isInternal()).isFalse(); + assertThat(action.params()).hasSize(4); + + WebService.Param name = action.param("name"); + assertThat(name).isNotNull(); + assertThat(name.description()).isNotNull(); + assertThat(name.exampleValue()).isNotNull(); + assertThat(name.isRequired()).isTrue(); + + WebService.Param description = action.param("description"); + assertThat(description).isNotNull(); + assertThat(description.description()).isNotNull(); + assertThat(description.isRequired()).isFalse(); + + WebService.Param project = action.param("project"); + assertThat(project).isNotNull(); + assertThat(project.description()).isNotNull(); + assertThat(project.exampleValue()).isNotNull(); + assertThat(project.isRequired()).isTrue(); + + WebService.Param deadLine = action.param("deadLine"); + assertThat(deadLine).isNotNull(); + assertThat(deadLine.description()).isNotNull(); + assertThat(deadLine.exampleValue()).isNotNull(); + assertThat(deadLine.isRequired()).isFalse(); + } + + @Test + public void define_delete_action() throws Exception { + WebService.Controller controller = tester.controller("api/action_plans"); + + WebService.Action action = controller.action("delete"); + assertThat(action).isNotNull(); + assertThat(action.handler()).isInstanceOf(RailsHandler.class); + assertThat(action.since()).isEqualTo("3.6"); + assertThat(action.isPost()).isTrue(); + assertThat(action.isInternal()).isFalse(); + assertThat(action.params()).hasSize(1); + + WebService.Param key = action.param("key"); + assertThat(key).isNotNull(); + assertThat(key.description()).isNotNull(); + assertThat(key.exampleValue()).isNotNull(); + assertThat(key.isRequired()).isTrue(); + } + + @Test + public void define_update_action() throws Exception { + WebService.Controller controller = tester.controller("api/action_plans"); + + WebService.Action action = controller.action("update"); + assertThat(action).isNotNull(); + assertThat(action.handler()).isInstanceOf(RailsHandler.class); + assertThat(action.since()).isEqualTo("3.6"); + assertThat(action.isPost()).isTrue(); + assertThat(action.isInternal()).isFalse(); + assertThat(action.params()).hasSize(4); + + WebService.Param project = action.param("key"); + assertThat(project).isNotNull(); + assertThat(project.description()).isNotNull(); + assertThat(project.exampleValue()).isNotNull(); + assertThat(project.isRequired()).isTrue(); + + WebService.Param name = action.param("name"); + assertThat(name).isNotNull(); + assertThat(name.description()).isNotNull(); + assertThat(name.exampleValue()).isNotNull(); + assertThat(name.isRequired()).isTrue(); + + WebService.Param description = action.param("description"); + assertThat(description).isNotNull(); + assertThat(description.description()).isNotNull(); + assertThat(description.isRequired()).isFalse(); + + WebService.Param deadLine = action.param("deadLine"); + assertThat(deadLine).isNotNull(); + assertThat(deadLine.description()).isNotNull(); + assertThat(deadLine.exampleValue()).isNotNull(); + assertThat(deadLine.isRequired()).isFalse(); + } + + @Test + public void define_open_action() throws Exception { + WebService.Controller controller = tester.controller("api/action_plans"); + + WebService.Action action = controller.action("open"); + assertThat(action).isNotNull(); + assertThat(action.handler()).isInstanceOf(RailsHandler.class); + assertThat(action.since()).isEqualTo("3.6"); + assertThat(action.isPost()).isTrue(); + assertThat(action.isInternal()).isFalse(); + assertThat(action.params()).hasSize(1); + + WebService.Param key = action.param("key"); + assertThat(key).isNotNull(); + assertThat(key.description()).isNotNull(); + assertThat(key.exampleValue()).isNotNull(); + assertThat(key.isRequired()).isTrue(); + } + + @Test + public void define_close_action() throws Exception { + WebService.Controller controller = tester.controller("api/action_plans"); + + WebService.Action action = controller.action("close"); + assertThat(action).isNotNull(); + assertThat(action.handler()).isInstanceOf(RailsHandler.class); + assertThat(action.since()).isEqualTo("3.6"); + assertThat(action.isPost()).isTrue(); + assertThat(action.isInternal()).isFalse(); + assertThat(action.params()).hasSize(1); + + WebService.Param key = action.param("key"); + assertThat(key).isNotNull(); + assertThat(key.description()).isNotNull(); + assertThat(key.exampleValue()).isNotNull(); + assertThat(key.isRequired()).isTrue(); + } +}