Search in sources :

Example 1 with AddCommentRequest

use of org.sonarqube.ws.client.issue.AddCommentRequest in project sonarqube by SonarSource.

the class IssueActionTest method should_reject_blank_comment.

/**
   * SONAR-4450
   */
@Test
public void should_reject_blank_comment() throws Exception {
    try {
        issuesService.addComment(new AddCommentRequest(randomIssue.getKey(), "  "));
        fail();
    } catch (org.sonarqube.ws.client.HttpException ex) {
        assertThat(ex.code()).isEqualTo(400);
    }
    Issue reloaded = issueRule.getByKey(randomIssue.getKey());
    assertThat(reloaded.getComments().getCommentsList()).isEmpty();
}
Also used : AddCommentRequest(org.sonarqube.ws.client.issue.AddCommentRequest) Issue(org.sonarqube.ws.Issues.Issue) Test(org.junit.Test)

Example 2 with AddCommentRequest

use of org.sonarqube.ws.client.issue.AddCommentRequest in project sonarqube by SonarSource.

the class IssueActionTest method add_comment.

@Test
public void add_comment() throws Exception {
    Issues.Comment comment = issuesService.addComment(new AddCommentRequest(randomIssue.getKey(), "this is my *comment*")).getIssue().getComments().getComments(0);
    assertThat(comment.getKey()).isNotNull();
    assertThat(comment.getHtmlText()).isEqualTo("this is my <strong>comment</strong>");
    assertThat(comment.getLogin()).isEqualTo("admin");
    assertThat(comment.getCreatedAt()).isNotNull();
    // reload issue
    Issue reloaded = issueRule.getByKey(randomIssue.getKey());
    assertThat(reloaded.getComments().getCommentsList()).hasSize(1);
    assertThat(reloaded.getComments().getComments(0).getKey()).isEqualTo(comment.getKey());
    assertThat(reloaded.getComments().getComments(0).getHtmlText()).isEqualTo("this is my <strong>comment</strong>");
    assertThat(toDatetime(reloaded.getUpdateDate())).isAfter(toDatetime(randomIssue.getUpdateDate()));
}
Also used : AddCommentRequest(org.sonarqube.ws.client.issue.AddCommentRequest) Issue(org.sonarqube.ws.Issues.Issue) Issues(org.sonarqube.ws.Issues) Test(org.junit.Test)

Example 3 with AddCommentRequest

use of org.sonarqube.ws.client.issue.AddCommentRequest in project sonarqube by SonarSource.

the class IssueActionTest method edit_comment.

@Test
public void edit_comment() throws Exception {
    Issues.Comment comment = issuesService.addComment(new AddCommentRequest(randomIssue.getKey(), "this is my *comment*")).getIssue().getComments().getComments(0);
    Issues.Comment editedComment = issuesService.editComment(new EditCommentRequest(comment.getKey(), "new *comment*")).getIssue().getComments().getComments(0);
    assertThat(editedComment.getHtmlText()).isEqualTo("new <strong>comment</strong>");
    // reload issue
    Issue reloaded = issueRule.getByKey(randomIssue.getKey());
    assertThat(reloaded.getComments().getCommentsList()).hasSize(1);
    assertThat(reloaded.getComments().getComments(0).getHtmlText()).isEqualTo("new <strong>comment</strong>");
}
Also used : AddCommentRequest(org.sonarqube.ws.client.issue.AddCommentRequest) Issue(org.sonarqube.ws.Issues.Issue) Issues(org.sonarqube.ws.Issues) EditCommentRequest(org.sonarqube.ws.client.issue.EditCommentRequest) Test(org.junit.Test)

Example 4 with AddCommentRequest

use of org.sonarqube.ws.client.issue.AddCommentRequest in project sonarqube by SonarSource.

the class IssueActionTest method delete_comment.

@Test
public void delete_comment() throws Exception {
    Issues.Comment comment = issuesService.addComment(new AddCommentRequest(randomIssue.getKey(), "this is my *comment*")).getIssue().getComments().getComments(0);
    Issue issue = issuesService.deleteComment(comment.getKey()).getIssue();
    assertThat(issue.getComments().getCommentsList()).isEmpty();
    // reload issue
    Issue reloaded = issueRule.getByKey(randomIssue.getKey());
    assertThat(reloaded.getComments().getCommentsList()).isEmpty();
}
Also used : AddCommentRequest(org.sonarqube.ws.client.issue.AddCommentRequest) Issue(org.sonarqube.ws.Issues.Issue) Issues(org.sonarqube.ws.Issues) Test(org.junit.Test)

Example 5 with AddCommentRequest

use of org.sonarqube.ws.client.issue.AddCommentRequest in project sonarqube by SonarSource.

the class AddCommentAction method toWsRequest.

private static AddCommentRequest toWsRequest(Request request) {
    AddCommentRequest wsRequest = new AddCommentRequest(request.mandatoryParam(PARAM_ISSUE), request.mandatoryParam(PARAM_TEXT));
    checkArgument(!isNullOrEmpty(wsRequest.getText()), "Cannot add empty comment to an issue");
    return wsRequest;
}
Also used : AddCommentRequest(org.sonarqube.ws.client.issue.AddCommentRequest)

Aggregations

AddCommentRequest (org.sonarqube.ws.client.issue.AddCommentRequest)6 Test (org.junit.Test)4 Issue (org.sonarqube.ws.Issues.Issue)4 Issues (org.sonarqube.ws.Issues)3 Date (java.util.Date)1 DefaultIssue (org.sonar.core.issue.DefaultIssue)1 IssueChangeContext (org.sonar.core.issue.IssueChangeContext)1 DbSession (org.sonar.db.DbSession)1 IssueDto (org.sonar.db.issue.IssueDto)1 EditCommentRequest (org.sonarqube.ws.client.issue.EditCommentRequest)1