diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-29 10:21:01 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-29 10:21:01 +0200 |
commit | 89636790c88a41156293cab10bd18669e285867d (patch) | |
tree | 9f7aa8bc900c39b783d66dc39a848b3de9036887 | |
parent | 3e7c244c67ab7095d90e3730acfac04b227559e3 (diff) | |
download | sonarqube-89636790c88a41156293cab10bd18669e285867d.tar.gz sonarqube-89636790c88a41156293cab10bd18669e285867d.zip |
SONAR-3755 Issues WS Client now always returned the created/modified issue
3 files changed, 42 insertions, 17 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 3d9e37c44b9..ceef7fe98fc 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 @@ -25,6 +25,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; @@ -54,38 +55,42 @@ public class DefaultIssueClient implements IssueClient { } @Override - public void create(NewIssue newIssue) { + public Issue create(NewIssue newIssue) { HttpRequest request = requestFactory.post(NewIssue.BASE_URL, newIssue.urlParams()); if (!request.ok()) { throw new IllegalStateException("Fail to create issue. Bad HTTP response status: " + request.code()); } + return createIssueResult(request); } @Override - public void setSeverity(String issueKey, String severity) { + public Issue setSeverity(String issueKey, String severity) { Map<String, Object> params = EncodingUtils.toMap("issue", issueKey, "severity", severity); HttpRequest request = requestFactory.post("/api/issues/set_severity", params); if (!request.ok()) { throw new IllegalStateException("Fail to set severity. Bad HTTP response status: " + request.code()); } + return createIssueResult(request); } @Override - public void assign(String issueKey, @Nullable String assignee) { + public Issue assign(String issueKey, @Nullable String assignee) { Map<String, Object> params = EncodingUtils.toMap("issue", issueKey, "assignee", assignee); HttpRequest request = requestFactory.post("/api/issues/assign", params); if (!request.ok()) { throw new IllegalStateException("Fail to assign issue to user. Bad HTTP response status: " + request.code()); } + return createIssueResult(request); } @Override - public void plan(String issueKey, @Nullable String actionPlanKey) { + public Issue 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()); } + return createIssueResult(request); } @Override @@ -111,13 +116,19 @@ public class DefaultIssueClient implements IssueClient { } @Override - public void doTransition(String issueKey, String transition) { + public Issue doTransition(String issueKey, String transition) { Map<String, Object> params = EncodingUtils.toMap("issue", issueKey, "transition", transition); HttpRequest request = requestFactory.post("/api/issues/do_transition", params); if (!request.ok()) { throw new IllegalStateException("Fail to execute transition on issue " + issueKey + ".Bad HTTP response status: " + request.code()); } + return createIssueResult(request); } + private Issue createIssueResult(HttpRequest request){ + String json = request.body("UTF-8"); + Map jsonRoot = (Map) JSONValue.parse(json); + return new Issue((Map) jsonRoot.get("issue")); + } } 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 324c9e79132..2130d3c92ae 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 @@ -30,18 +30,18 @@ public interface IssueClient { Issues find(IssueQuery query); - void assign(String issueKey, @Nullable String assignee); + Issue assign(String issueKey, @Nullable String assignee); - void setSeverity(String issueKey, String severity); + Issue setSeverity(String issueKey, String severity); - void plan(String issueKey, @Nullable String actionPlan); + Issue plan(String issueKey, @Nullable String actionPlan); IssueComment addComment(String issueKey, String markdownText); - void create(NewIssue issue); + Issue create(NewIssue issue); List<String> transitions(String issueKey); - void doTransition(String issueKey, String transition); + Issue doTransition(String issueKey, String transition); } 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 a9cc0bc4629..ae0d4c587ba 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 @@ -65,61 +65,73 @@ public class DefaultIssueClientTest { @Test public void should_set_severity() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + httpServer.doReturnBody("{\"issue\": {\"key\": \"ABCDE\"}}"); IssueClient client = new DefaultIssueClient(requestFactory); - client.setSeverity("ABCDE", "BLOCKER"); + Issue result = client.setSeverity("ABCDE", "BLOCKER"); assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/set_severity?issue=ABCDE&severity=BLOCKER"); + assertThat(result).isNotNull(); } @Test public void should_assign() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + httpServer.doReturnBody("{\"issue\": {\"key\": \"ABCDE\"}}"); IssueClient client = new DefaultIssueClient(requestFactory); - client.assign("ABCDE", "emmerik"); + Issue result = client.assign("ABCDE", "emmerik"); assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/assign?issue=ABCDE&assignee=emmerik"); + assertThat(result).isNotNull(); } @Test public void should_unassign() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + httpServer.doReturnBody("{\"issue\": {\"key\": \"ABCDE\"}}"); IssueClient client = new DefaultIssueClient(requestFactory); - client.assign("ABCDE", null); + Issue result = client.assign("ABCDE", null); assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/assign?issue=ABCDE"); + assertThat(result).isNotNull(); } @Test public void should_plan() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + httpServer.doReturnBody("{\"issue\": {\"key\": \"ABCDE\"}}"); IssueClient client = new DefaultIssueClient(requestFactory); - client.plan("ABCDE", "DEFGH"); + Issue result = client.plan("ABCDE", "DEFGH"); assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/plan?issue=ABCDE&plan=DEFGH"); + assertThat(result).isNotNull(); } @Test public void should_unplan() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + httpServer.doReturnBody("{\"issue\": {\"key\": \"ABCDE\"}}"); IssueClient client = new DefaultIssueClient(requestFactory); - client.plan("ABCDE", null); + Issue result = client.plan("ABCDE", null); assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/plan?issue=ABCDE"); + assertThat(result).isNotNull(); } @Test public void should_create_issue() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + httpServer.doReturnBody("{\"issue\": {\"key\": \"ABCDE\"}}"); IssueClient client = new DefaultIssueClient(requestFactory); - client.create(NewIssue.create().component("Action.java").rule("squid:AvoidCycle")); + Issue result = client.create(NewIssue.create().component("Action.java").rule("squid:AvoidCycle")); assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/create?component=Action.java&rule=squid:AvoidCycle"); + assertThat(result).isNotNull(); } @Test @@ -143,11 +155,13 @@ public class DefaultIssueClientTest { @Test public void should_apply_transition() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null); + httpServer.doReturnBody("{\"issue\": {\"key\": \"ABCDE\"}}"); IssueClient client = new DefaultIssueClient(requestFactory); - client.doTransition("ABCDE", "resolve"); + Issue result = client.doTransition("ABCDE", "resolve"); assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/do_transition?issue=ABCDE&transition=resolve"); + assertThat(result).isNotNull(); } @Test |