コード例 #1
0
  @Test
  public void add_comment() throws Exception {
    IssueComment comment = adminIssueClient().addComment(issue.key(), "this is my *comment*");
    assertThat(comment.key()).isNotNull();
    assertThat(comment.htmlText()).isEqualTo("this is my <strong>comment</strong>");
    assertThat(comment.login()).isEqualTo("admin");
    assertThat(comment.createdAt()).isNotNull();

    // reload issue
    Issue reloaded = searchIssue(issue.key(), true);

    assertThat(reloaded.comments()).hasSize(1);
    assertThat(reloaded.comments().get(0).key()).isEqualTo(comment.key());
    assertThat(reloaded.comments().get(0).htmlText())
        .isEqualTo("this is my <strong>comment</strong>");
    assertThat(reloaded.updateDate().before(issue.creationDate())).isFalse();
  }
コード例 #2
0
  @Test
  public void should_add_comment() throws Exception {
    HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
    httpServer.stubResponseBody(
        IOUtils.toString(
            getClass()
                .getResourceAsStream(
                    "/org/sonar/wsclient/issue/internal/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");
    assertThat(httpServer.requestParams())
        .includes(entry("issue", "ISSUE-1"), entry("text", "this is my comment"));
    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);
  }