aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-05-13 20:37:52 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-05-13 20:37:52 +0200
commit45735e2ff74a65f843a914bdc93e16637ebea2f7 (patch)
treee9d33837bd58263f9d542b438b2e90e9e8018b8e /sonar-ws-client/src
parent2d4b079141608ec417e284ff714bfe0b7d6dd040 (diff)
downloadsonarqube-45735e2ff74a65f843a914bdc93e16637ebea2f7.tar.gz
sonarqube-45735e2ff74a65f843a914bdc93e16637ebea2f7.zip
SONAR-4282 Fix issue in rub API and add save, update and delete actions on WS
Diffstat (limited to 'sonar-ws-client/src')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanClient.java12
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanParser.java83
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanQuery.java1
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultActionPlanClient.java56
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/NewActionPlan.java68
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/UpdateActionPlan.java68
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java80
7 files changed, 284 insertions, 84 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanClient.java
index cdeab14c359..d1261508c0d 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanClient.java
@@ -28,4 +28,16 @@ public interface ActionPlanClient {
List<ActionPlan> find();
+ ActionPlan find(String actionPlanKey);
+
+ void create(NewActionPlan newActionPlan);
+
+ void update(UpdateActionPlan updateActionPlan);
+
+ void delete(String actionPlanKey);
+
+ void open(String actionPlanKey);
+
+ void close(String actionPlanKey);
+
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanParser.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanParser.java
deleted file mode 100644
index 2ab624142b0..00000000000
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanParser.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.wsclient.issue;
-
-import org.json.simple.JSONValue;
-import org.sonar.wsclient.component.Component;
-import org.sonar.wsclient.rule.Rule;
-import org.sonar.wsclient.unmarshallers.JsonUtils;
-import org.sonar.wsclient.user.User;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @since 3.6
- */
-class ActionPlanParser {
-
- Issues parseIssues(String json) {
- Issues result = new Issues();
- Map jsonRoot = (Map) JSONValue.parse(json);
- List<Map> jsonIssues = (List) jsonRoot.get("issues");
- if (jsonIssues != null) {
- for (Map jsonIssue : jsonIssues) {
- result.add(new Issue(jsonIssue));
- }
- }
-
- List<Map> jsonRules = (List) jsonRoot.get("rules");
- if (jsonRules != null) {
- for (Map jsonRule : jsonRules) {
- result.add(new Rule(jsonRule));
- }
- }
-
- List<Map> jsonUsers = (List) jsonRoot.get("users");
- if (jsonUsers != null) {
- for (Map jsonUser : jsonUsers) {
- result.add(new User(jsonUser));
- }
- }
-
- List<Map> jsonComponents = (List) jsonRoot.get("components");
- if (jsonComponents != null) {
- for (Map jsonComponent : jsonComponents) {
- result.add(new Component(jsonComponent));
- }
- }
-
- Map paging = (Map) jsonRoot.get("paging");
- result.setPaging(new Paging(paging));
- result.setSecurityExclusions(JsonUtils.getBoolean(jsonRoot, "securityExclusions"));
- return result;
- }
-
- List<String> parseTransitions(String json) {
- List<String> transitions = new ArrayList<String>();
- Map jRoot = (Map) JSONValue.parse(json);
- List<String> jTransitions = (List) jRoot.get("transitions");
- for (String jTransition : jTransitions) {
- transitions.add(jTransition);
- }
- return transitions;
- }
-}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanQuery.java
index 1ae43e56914..aa7124f5cd0 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlanQuery.java
@@ -26,6 +26,7 @@ import java.util.Map;
* @since 3.6
*/
public class ActionPlanQuery {
+
static final String BASE_URL = "/api/action_plans/search";
private final Map<String, Object> params = new HashMap<String, Object>();
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultActionPlanClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultActionPlanClient.java
index 7f4ad8750f6..67175a6828d 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultActionPlanClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultActionPlanClient.java
@@ -21,6 +21,7 @@ package org.sonar.wsclient.issue;
import com.github.kevinsawicki.http.HttpRequest;
import org.json.simple.JSONValue;
+import org.sonar.wsclient.internal.EncodingUtils;
import org.sonar.wsclient.internal.HttpRequestFactory;
import java.util.ArrayList;
@@ -45,7 +46,7 @@ public class DefaultActionPlanClient implements ActionPlanClient {
public List<ActionPlan> find() {
HttpRequest request = requestFactory.get(ActionPlanQuery.BASE_URL, null);
if (!request.ok()) {
- throw new IllegalStateException("Fail to search for users. Bad HTTP response status: " + request.code());
+ throw new IllegalStateException("Fail to search for action plans. Bad HTTP response status: " + request.code());
}
List<ActionPlan> result = new ArrayList<ActionPlan>();
String json = request.body("UTF-8");
@@ -59,4 +60,57 @@ public class DefaultActionPlanClient implements ActionPlanClient {
return result;
}
+ @Override
+ public ActionPlan find(String actionPlanKey) {
+ HttpRequest request = requestFactory.get("/api/action_plans/show", null);
+ if (!request.ok()) {
+ throw new IllegalStateException("Fail to search action plan. Bad HTTP response status: " + request.code());
+ }
+ String json = request.body("UTF-8");
+ Map jsonRoot = (Map) JSONValue.parse(json);
+ List<Map> jsonActionPlans = (List) jsonRoot.get("actionPlans");
+ if (jsonActionPlans != null) {
+ return new ActionPlan(jsonActionPlans.get(0));
+ }
+ return null;
+ }
+
+ @Override
+ public void create(NewActionPlan newActionPlan) {
+ HttpRequest request = requestFactory.post(NewActionPlan.BASE_URL, newActionPlan.urlParams());
+ if (!request.ok()) {
+ throw new IllegalStateException("Fail to create action plan. Bad HTTP response status: " + request.code());
+ }
+ }
+
+ @Override
+ public void update(UpdateActionPlan updateActionPlan) {
+ HttpRequest request = requestFactory.post(UpdateActionPlan.BASE_URL, updateActionPlan.urlParams());
+ if (!request.ok()) {
+ throw new IllegalStateException("Fail to update action plan. Bad HTTP response status: " + request.code());
+ }
+ }
+
+ @Override
+ public void delete(String actionPlanKey) {
+ executeSimpleAction(actionPlanKey, "delete");
+ }
+
+ @Override
+ public void open(String actionPlanKey) {
+ executeSimpleAction(actionPlanKey, "open");
+ }
+
+ @Override
+ public void close(String actionPlanKey) {
+ executeSimpleAction(actionPlanKey, "close");
+ }
+
+ private void executeSimpleAction(String actionPlanKey, String action) {
+ HttpRequest request = requestFactory.post("/api/action_plans/" + action, EncodingUtils.toMap("key", actionPlanKey));
+ if (!request.ok()) {
+ throw new IllegalStateException("Fail to " + action + " action plan. Bad HTTP response status: " + request.code());
+ }
+ }
+
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/NewActionPlan.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/NewActionPlan.java
new file mode 100644
index 00000000000..fa5cf71b662
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/NewActionPlan.java
@@ -0,0 +1,68 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.wsclient.issue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @since 3.6
+ */
+public class NewActionPlan {
+
+ static final String BASE_URL = "/api/action_plans/create";
+
+ private final Map<String, Object> params = new HashMap<String, Object>();
+
+ private NewActionPlan() {
+ }
+
+ public static NewActionPlan create() {
+ return new NewActionPlan();
+ }
+
+ Map<String, Object> urlParams() {
+ return params;
+ }
+
+ public NewActionPlan name(String s) {
+ params.put("name", s);
+ return this;
+ }
+
+ public NewActionPlan project(String s) {
+ params.put("project", s);
+ return this;
+ }
+
+ public NewActionPlan description(String s) {
+ params.put("desc", s);
+ return this;
+ }
+
+ /**
+ * Due date of the action plan. Format is 'day/month/year', for instance, '31/12/2013'.
+ */
+ public NewActionPlan deadLine(String s) {
+ params.put("deadLine", s);
+ return this;
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/UpdateActionPlan.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/UpdateActionPlan.java
new file mode 100644
index 00000000000..43265f42c72
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/UpdateActionPlan.java
@@ -0,0 +1,68 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.wsclient.issue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @since 3.6
+ */
+public class UpdateActionPlan {
+
+ static final String BASE_URL = "/api/action_plans/update";
+
+ private final Map<String, Object> params = new HashMap<String, Object>();
+
+ private UpdateActionPlan() {
+ }
+
+ public static UpdateActionPlan create() {
+ return new UpdateActionPlan();
+ }
+
+ Map<String, Object> urlParams() {
+ return params;
+ }
+
+ public UpdateActionPlan key(String s) {
+ params.put("key", s);
+ return this;
+ }
+
+ public UpdateActionPlan name(String s) {
+ params.put("name", s);
+ return this;
+ }
+
+ public UpdateActionPlan description(String s) {
+ params.put("desc", s);
+ return this;
+ }
+
+ /**
+ * Due date of the action plan. Format is 'day/month/year', for instance, '31/12/2013'.
+ */
+ public UpdateActionPlan deadLine(String s) {
+ params.put("deadLine", s);
+ return this;
+ }
+
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java
index 3ce0afb9f59..4d6011abed1 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java
@@ -65,4 +65,84 @@ public class DefaultActionPlanClientTest {
assertThat(actionPlan.updatedAt()).isNotNull();
}
+ @Test
+ public void should_find_action_plan() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+ httpServer.doReturnBody("{\"actionPlans\": [{\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\",\n" +
+ "\"name\": \"Long term\",\n" +
+ "\"status\": \"CLOSED\",\n" +
+ "\"project\": \"com.sonarsource.it.samples:simple-sample\",\n" +
+ "\"userLogin\": \"admin\",\n" +
+ "\"deadLine\": \"2013-05-30T00:00:00+0200\",\n" +
+ "\"totalIssues\": 0,\n" +
+ "\"openIssues\": 0,\n" +
+ "\"createdAt\": \"2013-05-13T12:50:29+0200\",\n" +
+ "\"updatedAt\": \"2013-05-13T12:50:44+0200\"}]}");
+
+ ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
+ ActionPlan actionPlan = client.find("382f6f2e-ad9d-424a-b973-9b065e04348a");
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/show");
+ assertThat(actionPlan).isNotNull();
+ assertThat(actionPlan.key()).isEqualTo("382f6f2e-ad9d-424a-b973-9b065e04348a");
+ assertThat(actionPlan.name()).isEqualTo("Long term");
+ assertThat(actionPlan.status()).isEqualTo("CLOSED");
+ assertThat(actionPlan.userLogin()).isEqualTo("admin");
+ assertThat(actionPlan.deadLine()).isNotNull();
+ assertThat(actionPlan.totalIssues()).isEqualTo(0);
+ assertThat(actionPlan.openIssues()).isEqualTo(0);
+ assertThat(actionPlan.createdAt()).isNotNull();
+ assertThat(actionPlan.updatedAt()).isNotNull();
+ }
+
+ @Test
+ public void should_create_action_plan() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+
+ ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
+ client.create(NewActionPlan.create().name("Short term").project("org.sonar.Sample").description("Short term issues").deadLine("01/01/2014"));
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/create?project=org.sonar.Sample&desc=Short%20term%20issues&name=Short%20term&deadLine=01/01/2014");
+ }
+
+ @Test
+ public void should_update_action_plan() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+
+ ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
+ client.update(UpdateActionPlan.create().key("382f6f2e-ad9d-424a-b973-9b065e04348a").name("Short term").description("Short term issues").deadLine("01/01/2014"));
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/update?desc=Short%20term%20issues&name=Short%20term&deadLine=01/01/2014&key=382f6f2e-ad9d-424a-b973-9b065e04348a");
+ }
+
+ @Test
+ public void should_delete_action_plan() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+
+ ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
+ client.delete("382f6f2e-ad9d-424a-b973-9b065e04348a");
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/delete?key=382f6f2e-ad9d-424a-b973-9b065e04348a");
+ }
+
+ @Test
+ public void should_open_action_plan() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+
+ ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
+ client.open("382f6f2e-ad9d-424a-b973-9b065e04348a");
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/open?key=382f6f2e-ad9d-424a-b973-9b065e04348a");
+ }
+
+ @Test
+ public void should_close_action_plan() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+
+ ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
+ client.close("382f6f2e-ad9d-424a-b973-9b065e04348a");
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/close?key=382f6f2e-ad9d-424a-b973-9b065e04348a");
+ }
+
}