Search in sources :

Example 1 with Issue

use of org.sonarqube.ws.Issues.Issue in project sonarqube by SonarSource.

the class IssueActionTest method assign.

/**
   * SONAR-4287
   */
@Test
public void assign() {
    assertThat(randomIssue.hasAssignee()).isFalse();
    Issues.SearchWsResponse response = issueRule.search(new SearchWsRequest().setIssues(singletonList(randomIssue.getKey())));
    assertThat(response.getUsers().getUsersList()).isEmpty();
    issuesService.assign(new AssignRequest(randomIssue.getKey(), "admin"));
    assertThat(issueRule.search(new SearchWsRequest().setAssignees(singletonList("admin"))).getIssuesList()).hasSize(1);
    projectAnalysis.run();
    Issue reloaded = issueRule.getByKey(randomIssue.getKey());
    assertThat(reloaded.getAssignee()).isEqualTo("admin");
    assertThat(reloaded.getCreationDate()).isEqualTo(randomIssue.getCreationDate());
    response = issueRule.search(new SearchWsRequest().setIssues(singletonList(randomIssue.getKey())).setAdditionalFields(singletonList("users")));
    assertThat(response.getUsers().getUsersList().stream().filter(user -> "admin".equals(user.getLogin())).findFirst()).isPresent();
    assertThat(response.getUsers().getUsersList().stream().filter(user -> "Administrator".equals(user.getName())).findFirst()).isPresent();
    // unassign
    issuesService.assign(new AssignRequest(randomIssue.getKey(), null));
    reloaded = issueRule.getByKey(randomIssue.getKey());
    assertThat(reloaded.hasAssignee()).isFalse();
    assertThat(issueRule.search(new SearchWsRequest().setAssignees(singletonList("admin"))).getIssuesList()).isEmpty();
}
Also used : EditCommentRequest(org.sonarqube.ws.client.issue.EditCommentRequest) Issues(org.sonarqube.ws.Issues) ItUtils.toDatetime(util.ItUtils.toDatetime) Issue(org.sonarqube.ws.Issues.Issue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProjectAnalysis(util.ProjectAnalysis) IssuesService(org.sonarqube.ws.client.issue.IssuesService) Test(org.junit.Test) SetSeverityRequest(org.sonarqube.ws.client.issue.SetSeverityRequest) Collections.singletonList(java.util.Collections.singletonList) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) List(java.util.List) BLOCKER(org.sonarqube.ws.Common.Severity.BLOCKER) Rule(org.junit.Rule) ProjectAnalysisRule(util.ProjectAnalysisRule) SearchWsRequest(org.sonarqube.ws.client.issue.SearchWsRequest) AddCommentRequest(org.sonarqube.ws.client.issue.AddCommentRequest) IssueRule(util.issue.IssueRule) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) AssignRequest(org.sonarqube.ws.client.issue.AssignRequest) Before(org.junit.Before) Issue(org.sonarqube.ws.Issues.Issue) Issues(org.sonarqube.ws.Issues) SearchWsRequest(org.sonarqube.ws.client.issue.SearchWsRequest) AssignRequest(org.sonarqube.ws.client.issue.AssignRequest) Test(org.junit.Test)

Example 2 with Issue

use of org.sonarqube.ws.Issues.Issue 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 3 with Issue

use of org.sonarqube.ws.Issues.Issue 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 4 with Issue

use of org.sonarqube.ws.Issues.Issue 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 5 with Issue

use of org.sonarqube.ws.Issues.Issue 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)

Aggregations

Test (org.junit.Test)24 Issue (org.sonarqube.ws.Issues.Issue)24 DoTransitionRequest (org.sonarqube.ws.client.issue.DoTransitionRequest)9 Issues (org.sonarqube.ws.Issues)5 AddCommentRequest (org.sonarqube.ws.client.issue.AddCommentRequest)5 BulkChangeWsResponse (org.sonarqube.ws.Issues.BulkChangeWsResponse)4 SearchWsRequest (org.sonarqube.ws.client.issue.SearchWsRequest)4 EditCommentRequest (org.sonarqube.ws.client.issue.EditCommentRequest)2 SetSeverityRequest (org.sonarqube.ws.client.issue.SetSeverityRequest)2 Collections.singletonList (java.util.Collections.singletonList)1 Date (java.util.Date)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1 ClassRule (org.junit.ClassRule)1 Rule (org.junit.Rule)1 BLOCKER (org.sonarqube.ws.Common.Severity.BLOCKER)1 AssignRequest (org.sonarqube.ws.client.issue.AssignRequest)1 IssuesService (org.sonarqube.ws.client.issue.IssuesService)1