aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-05-13 22:09:53 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-05-13 22:09:53 +0200
commit7cac4cf9e95cb0da0ea387e28a7513a0b8989a13 (patch)
treeb25a589872978b16b8d3a812918b8c56dd353691 /sonar-ws-client
parent45735e2ff74a65f843a914bdc93e16637ebea2f7 (diff)
downloadsonarqube-7cac4cf9e95cb0da0ea387e28a7513a0b8989a13.tar.gz
sonarqube-7cac4cf9e95cb0da0ea387e28a7513a0b8989a13.zip
SONAR-4282 Improve Action Plan WS
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlan.java3
-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/DefaultActionPlanClient.java41
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/NewActionPlan.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/UpdateActionPlan.java2
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java49
6 files changed, 69 insertions, 40 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlan.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlan.java
index 5d524e5c5d4..2b73d5975f3 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlan.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/ActionPlan.java
@@ -22,7 +22,6 @@ package org.sonar.wsclient.issue;
import org.sonar.wsclient.unmarshallers.JsonUtils;
import javax.annotation.CheckForNull;
-
import java.util.Date;
import java.util.Map;
@@ -44,7 +43,7 @@ public class ActionPlan {
return JsonUtils.getString(json, "key");
}
- public String projectKey() {
+ public String project() {
return JsonUtils.getString(json, "project");
}
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 d1261508c0d..e4e0e1c1e7b 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
@@ -26,18 +26,18 @@ import java.util.List;
*/
public interface ActionPlanClient {
- List<ActionPlan> find();
+ List<ActionPlan> find(String projectKey);
- ActionPlan find(String actionPlanKey);
+ ActionPlan get(String actionPlanKey);
- void create(NewActionPlan newActionPlan);
+ ActionPlan create(NewActionPlan newActionPlan);
- void update(UpdateActionPlan updateActionPlan);
+ ActionPlan update(UpdateActionPlan updateActionPlan);
void delete(String actionPlanKey);
- void open(String actionPlanKey);
+ ActionPlan open(String actionPlanKey);
- void close(String actionPlanKey);
+ ActionPlan close(String actionPlanKey);
}
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 67175a6828d..eccdf5038f5 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
@@ -43,8 +43,8 @@ public class DefaultActionPlanClient implements ActionPlanClient {
}
@Override
- public List<ActionPlan> find() {
- HttpRequest request = requestFactory.get(ActionPlanQuery.BASE_URL, null);
+ public List<ActionPlan> find(String projectKey) {
+ HttpRequest request = requestFactory.get(ActionPlanQuery.BASE_URL, EncodingUtils.toMap("project", projectKey));
if (!request.ok()) {
throw new IllegalStateException("Fail to search for action plans. Bad HTTP response status: " + request.code());
}
@@ -61,34 +61,30 @@ public class DefaultActionPlanClient implements ActionPlanClient {
}
@Override
- public ActionPlan find(String actionPlanKey) {
- HttpRequest request = requestFactory.get("/api/action_plans/show", null);
+ public ActionPlan get(String actionPlanKey) {
+ HttpRequest request = requestFactory.get("/api/action_plans/show", EncodingUtils.toMap("key", actionPlanKey));
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;
+ return createActionPlanResult(request);
}
@Override
- public void create(NewActionPlan newActionPlan) {
+ public ActionPlan 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());
}
+ return createActionPlanResult(request);
}
@Override
- public void update(UpdateActionPlan updateActionPlan) {
+ public ActionPlan 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());
}
+ return createActionPlanResult(request);
}
@Override
@@ -97,20 +93,29 @@ public class DefaultActionPlanClient implements ActionPlanClient {
}
@Override
- public void open(String actionPlanKey) {
- executeSimpleAction(actionPlanKey, "open");
+ public ActionPlan open(String actionPlanKey) {
+ HttpRequest request = executeSimpleAction(actionPlanKey, "open");
+ return createActionPlanResult(request);
}
@Override
- public void close(String actionPlanKey) {
- executeSimpleAction(actionPlanKey, "close");
+ public ActionPlan close(String actionPlanKey) {
+ HttpRequest request = executeSimpleAction(actionPlanKey, "close");
+ return createActionPlanResult(request);
}
- private void executeSimpleAction(String actionPlanKey, String action) {
+ private HttpRequest 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());
}
+ return request;
+ }
+
+ private ActionPlan createActionPlanResult(HttpRequest request){
+ String json = request.body("UTF-8");
+ Map jsonRoot = (Map) JSONValue.parse(json);
+ return new ActionPlan((Map) jsonRoot.get("actionPlan"));
}
}
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
index fa5cf71b662..4b9460f44bd 100644
--- 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
@@ -53,7 +53,7 @@ public class NewActionPlan {
}
public NewActionPlan description(String s) {
- params.put("desc", s);
+ params.put("description", 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
index 43265f42c72..8914e898fce 100644
--- 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
@@ -53,7 +53,7 @@ public class UpdateActionPlan {
}
public UpdateActionPlan description(String s) {
- params.put("desc", s);
+ params.put("description", 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 4d6011abed1..6b56706c8de 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
@@ -28,6 +28,7 @@ import org.sonar.wsclient.internal.HttpRequestFactory;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
public class DefaultActionPlanClientTest {
@@ -49,13 +50,14 @@ public class DefaultActionPlanClientTest {
"\"updatedAt\": \"2013-05-13T12:50:44+0200\"}]}");
ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
- List<ActionPlan> actionPlans = client.find();
+ List<ActionPlan> actionPlans = client.find("com.sonarsource.it.samples:simple-sample");
- assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/search");
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/search?project=com.sonarsource.it.samples:simple-sample");
assertThat(actionPlans).hasSize(1);
ActionPlan actionPlan = actionPlans.get(0);
assertThat(actionPlan.key()).isEqualTo("382f6f2e-ad9d-424a-b973-9b065e04348a");
assertThat(actionPlan.name()).isEqualTo("Long term");
+ assertThat(actionPlan.project()).isEqualTo("com.sonarsource.it.samples:simple-sample");
assertThat(actionPlan.status()).isEqualTo("CLOSED");
assertThat(actionPlan.userLogin()).isEqualTo("admin");
assertThat(actionPlan.deadLine()).isNotNull();
@@ -68,7 +70,7 @@ public class DefaultActionPlanClientTest {
@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" +
+ httpServer.doReturnBody("{\"actionPlan\": {\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\",\n" +
"\"name\": \"Long term\",\n" +
"\"status\": \"CLOSED\",\n" +
"\"project\": \"com.sonarsource.it.samples:simple-sample\",\n" +
@@ -77,15 +79,16 @@ public class DefaultActionPlanClientTest {
"\"totalIssues\": 0,\n" +
"\"openIssues\": 0,\n" +
"\"createdAt\": \"2013-05-13T12:50:29+0200\",\n" +
- "\"updatedAt\": \"2013-05-13T12:50:44+0200\"}]}");
+ "\"updatedAt\": \"2013-05-13T12:50:44+0200\"}}");
ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
- ActionPlan actionPlan = client.find("382f6f2e-ad9d-424a-b973-9b065e04348a");
+ ActionPlan actionPlan = client.get("382f6f2e-ad9d-424a-b973-9b065e04348a");
- assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/show");
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/show?key=382f6f2e-ad9d-424a-b973-9b065e04348a");
assertThat(actionPlan).isNotNull();
assertThat(actionPlan.key()).isEqualTo("382f6f2e-ad9d-424a-b973-9b065e04348a");
assertThat(actionPlan.name()).isEqualTo("Long term");
+ assertThat(actionPlan.project()).isEqualTo("com.sonarsource.it.samples:simple-sample");
assertThat(actionPlan.status()).isEqualTo("CLOSED");
assertThat(actionPlan.userLogin()).isEqualTo("admin");
assertThat(actionPlan.deadLine()).isNotNull();
@@ -98,21 +101,25 @@ public class DefaultActionPlanClientTest {
@Test
public void should_create_action_plan() {
HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+ httpServer.doReturnBody("{\"actionPlan\": {\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\"}}");
ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
- client.create(NewActionPlan.create().name("Short term").project("org.sonar.Sample").description("Short term issues").deadLine("01/01/2014"));
+ ActionPlan result = 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");
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/create?project=org.sonar.Sample&description=Short%20term%20issues&name=Short%20term&deadLine=01/01/2014");
+ assertThat(result).isNotNull();
}
@Test
public void should_update_action_plan() {
HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+ httpServer.doReturnBody("{\"actionPlan\": {\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\"}}");
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"));
+ ActionPlan result = 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");
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/update?description=Short%20term%20issues&name=Short%20term&deadLine=01/01/2014&key=382f6f2e-ad9d-424a-b973-9b065e04348a");
+ assertThat(result).isNotNull();
}
@Test
@@ -126,23 +133,41 @@ public class DefaultActionPlanClientTest {
}
@Test
+ public void should_fail_to_delete_action_plan() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+ httpServer.doReturnStatus(500);
+
+ ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
+ try {
+ client.delete("382f6f2e-ad9d-424a-b973-9b065e04348a");
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e).hasMessage("Fail to delete action plan. Bad HTTP response status: 500");
+ }
+ }
+
+ @Test
public void should_open_action_plan() {
HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+ httpServer.doReturnBody("{\"actionPlan\": {\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\"}}");
ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
- client.open("382f6f2e-ad9d-424a-b973-9b065e04348a");
+ ActionPlan result = client.open("382f6f2e-ad9d-424a-b973-9b065e04348a");
assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/open?key=382f6f2e-ad9d-424a-b973-9b065e04348a");
+ assertThat(result).isNotNull();
}
@Test
public void should_close_action_plan() {
HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+ httpServer.doReturnBody("{\"actionPlan\": {\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\"}}");
ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
- client.close("382f6f2e-ad9d-424a-b973-9b065e04348a");
+ ActionPlan result = client.close("382f6f2e-ad9d-424a-b973-9b065e04348a");
assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/close?key=382f6f2e-ad9d-424a-b973-9b065e04348a");
+ assertThat(result).isNotNull();
}
}