aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-16 15:47:44 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-16 16:09:12 +0200
commit514e62bd762e3b0eb8743b8c302230100234be5c (patch)
treee49dff63c63f6368e0ae5c5aa2326c1080829f6b /sonar-ws-client
parent1bcdcf66d3ad67f4cbba7cf9ba06f31573a9f97c (diff)
downloadsonarqube-514e62bd762e3b0eb8743b8c302230100234be5c.tar.gz
sonarqube-514e62bd762e3b0eb8743b8c302230100234be5c.zip
SONAR-3755 fix IssueClient#addComment()
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultIssueClient.java4
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java17
-rw-r--r--sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/DefaultIssueClientTest/add_comment_result.json8
3 files changed, 27 insertions, 2 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 68c9a926e4f..3d9e37c44b9 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
@@ -95,8 +95,8 @@ public class DefaultIssueClient implements IssueClient {
if (!request.ok()) {
throw new IllegalStateException("Fail to add issue comment. Bad HTTP response status: " + request.code());
}
- String json = request.body();
- return new IssueComment((Map) JSONValue.parse(json));
+ Map rootJson = (Map) JSONValue.parse(request.body());
+ return new IssueComment((Map)rootJson.get("comment"));
}
@Override
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 a098d39e2c9..a9cc0bc4629 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
@@ -19,6 +19,7 @@
*/
package org.sonar.wsclient.issue;
+import org.apache.commons.io.IOUtils;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.wsclient.MockHttpServerInterceptor;
@@ -148,4 +149,20 @@ public class DefaultIssueClientTest {
assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/do_transition?issue=ABCDE&transition=resolve");
}
+
+ @Test
+ public void should_add_comment() throws Exception {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url(), null, null);
+ httpServer.doReturnBody(IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/DefaultIssueClientTest/add_comment_result.json")));
+
+ IssueClient client = new DefaultIssueClient(requestFactory);
+ IssueComment comment = client.addComment("ISSUE-1", "this is my comment");
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/add_comment?issue=ISSUE-1&text=this%20is%20my%20comment");
+ assertThat(comment).isNotNull();
+ assertThat(comment.key()).isEqualTo("COMMENT-123");
+ assertThat(comment.htmlText()).isEqualTo("this is my comment");
+ assertThat(comment.login()).isEqualTo("admin");
+ assertThat(comment.createdAt().getDate()).isEqualTo(18);
+ }
}
diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/DefaultIssueClientTest/add_comment_result.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/DefaultIssueClientTest/add_comment_result.json
new file mode 100644
index 00000000000..7329cc86d24
--- /dev/null
+++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/DefaultIssueClientTest/add_comment_result.json
@@ -0,0 +1,8 @@
+{
+ "comment": {
+ "key": "COMMENT-123",
+ "htmlText": "this is my comment",
+ "login": "admin",
+ "createdAt": "2013-05-18T13:45:34+0200"
+ }
+} \ No newline at end of file