]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 fix IssueClient#addComment()
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 16 May 2013 13:47:44 +0000 (15:47 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 16 May 2013 14:09:12 +0000 (16:09 +0200)
sonar-ws-client/src/main/java/org/sonar/wsclient/issue/DefaultIssueClient.java
sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java
sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/DefaultIssueClientTest/add_comment_result.json [new file with mode: 0644]

index 68c9a926e4fc4e561be36fdac708adb9d7eabeca..3d9e37c44b929fe2048bbc0c8d33ccb8fce1f5ae 100644 (file)
@@ -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
index a098d39e2c93a77bb10bd3716faf2e0d407cfdc0..a9cc0bc46298fa8b188aae350f08d4ed48500278 100644 (file)
@@ -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 (file)
index 0000000..7329cc8
--- /dev/null
@@ -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