]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5111 Declare "api/action_plans" WS with org.sonar.api.server.WebService
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 28 Apr 2014 16:27:49 +0000 (18:27 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 28 Apr 2014 16:27:49 +0000 (18:27 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
sonar-server/src/main/java/org/sonar/server/issue/ws/ActionPlanWs.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
sonar-server/src/test/java/org/sonar/server/issue/ws/ActionPlanWsTest.java [new file with mode: 0644]

index e4aa651dba7dd25e0ba6b6c0d78f356a5cb65c5c..31fd348d2a5b4c0f7a1f3f9b2e46508803f9154f 100644 (file)
@@ -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 (file)
index 0000000..8945188
--- /dev/null
@@ -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);
+  }
+}
index bd2ceb9d76f5381a287b1be3ca70257987f07833..e1d1a899d4092c9d03c8def22e253ee85766d6af 100644 (file)
@@ -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 (file)
index 0000000..ec3223d
--- /dev/null
@@ -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();
+  }
+}