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
*/
package org.sonar.wsclient.issue;
+import org.apache.commons.io.IOUtils;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.wsclient.MockHttpServerInterceptor;
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);
+ }
}