diff options
Diffstat (limited to 'sonar-ws-client/src')
5 files changed, 41 insertions, 1 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultIssueClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultIssueClient.java index ecef1bf2677..cf82f66e74e 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultIssueClient.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultIssueClient.java @@ -24,6 +24,7 @@ import org.sonar.wsclient.internal.EncodingUtils; import org.sonar.wsclient.internal.HttpRequestFactory; import javax.annotation.Nullable; + import java.util.List; import java.util.Map; @@ -79,6 +80,15 @@ public class DefaultIssueClient implements IssueClient { } @Override + public void plan(String issueKey, @Nullable String actionPlanKey) { + Map<String, Object> params = EncodingUtils.toMap("issue", issueKey, "plan", actionPlanKey); + HttpRequest request = requestFactory.post("/api/issues/plan", params); + if (!request.ok()) { + throw new IllegalStateException("Fail to link action plan. Bad HTTP response status: " + request.code()); + } + } + + @Override public List<String> transitions(String issueKey) { Map<String, Object> queryParams = EncodingUtils.toMap("issue", issueKey); HttpRequest request = requestFactory.get("/api/issues/transitions", queryParams); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java index 5cfe1b2728c..805ba49fbef 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java @@ -20,6 +20,7 @@ package org.sonar.wsclient.issue; import javax.annotation.Nullable; + import java.util.List; /** @@ -33,6 +34,8 @@ public interface IssueClient { void setSeverity(String issueKey, String severity); + void plan(String issueKey, @Nullable String actionPlan); + void create(NewIssue issue); List<String> transitions(String issueKey); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java index 011fb506db6..3a1036f18cd 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java @@ -72,6 +72,10 @@ public class IssueQuery { return addParam("rules", s); } + public IssueQuery actionPlans(String... s) { + return addParam("actionPlans", s); + } + public IssueQuery userLogins(String... s) { return addParam("userLogins", s); } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java index 2c0fdaea03f..a098d39e2c9 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java @@ -92,6 +92,26 @@ public class DefaultIssueClientTest { } @Test + public void should_plan() { + HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + + IssueClient client = new DefaultIssueClient(requestFactory); + client.plan("ABCDE", "DEFGH"); + + assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/plan?issue=ABCDE&plan=DEFGH"); + } + + @Test + public void should_unplan() { + HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + + IssueClient client = new DefaultIssueClient(requestFactory); + client.plan("ABCDE", null); + + assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/plan?issue=ABCDE"); + } + + @Test public void should_create_issue() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java index 7daca96782d..ff001a067ad 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java @@ -42,6 +42,7 @@ public class IssueQueryTest { .componentRoots("struts") .resolutions("FIXED", "FALSE-POSITIVE") .rules("squid:AvoidCycle") + .actionPlans("ABC") .statuses("OPEN", "CLOSED") .severities("BLOCKER", "INFO") .userLogins("login1", "login2") @@ -50,13 +51,15 @@ public class IssueQueryTest { .pageSize(5) .pageIndex(4); - assertThat(query.urlParams()).hasSize(15); + assertThat(query.urlParams()).hasSize(16); assertThat(query.urlParams()).includes(entry("issues", "ABCDE,FGHIJ")); assertThat(query.urlParams()).includes(entry("assignees", "arthur,perceval")); assertThat(query.urlParams()).includes(entry("assigned", true)); assertThat(query.urlParams()).includes(entry("planned", true)); assertThat(query.urlParams()).includes(entry("components", "Action.java,Filter.java")); assertThat(query.urlParams()).includes(entry("componentRoots", "struts")); + assertThat(query.urlParams()).includes(entry("rules", "squid:AvoidCycle")); + assertThat(query.urlParams()).includes(entry("actionPlans", "ABC")); assertThat(query.urlParams()).includes(entry("resolutions", "FIXED,FALSE-POSITIVE")); assertThat(query.urlParams()).includes(entry("statuses", "OPEN,CLOSED")); assertThat(query.urlParams()).includes(entry("severities", "BLOCKER,INFO")); |