Search in sources :

Example 11 with Issue

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

the class IssueWorkflowTest method user_should_confirm_issue.

/**
   * SONAR-4329
   */
@Test
public void user_should_confirm_issue() {
    // mark as confirmed
    issuesService.doTransition(new DoTransitionRequest(issue.getKey(), "confirm"));
    Issue confirmed = issueRule.getByKey(issue.getKey());
    assertThat(confirmed.getStatus()).isEqualTo("CONFIRMED");
    assertThat(confirmed.hasResolution()).isFalse();
    assertThat(confirmed.getCreationDate()).isEqualTo(issue.getCreationDate());
    // user unconfirm the issue
    assertThat(transitions(confirmed.getKey())).contains("unconfirm");
    issuesService.doTransition(new DoTransitionRequest(confirmed.getKey(), "unconfirm"));
    Issue unconfirmed = issueRule.getByKey(issue.getKey());
    assertThat(unconfirmed.getStatus()).isEqualTo("REOPENED");
    assertThat(unconfirmed.hasResolution()).isFalse();
    assertThat(unconfirmed.getCreationDate()).isEqualTo(confirmed.getCreationDate());
}
Also used : Issue(org.sonarqube.ws.Issues.Issue) DoTransitionRequest(org.sonarqube.ws.client.issue.DoTransitionRequest) Test(org.junit.Test)

Example 12 with Issue

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

the class IssueWorkflowTest method scan_should_close_resolved_issue.

/**
   * SONAR-4288
   */
@Test
public void scan_should_close_resolved_issue() {
    // mark as resolved
    issuesService.doTransition(new DoTransitionRequest(issue.getKey(), "resolve"));
    Issue resolvedIssue = issueRule.getByKey(issue.getKey());
    assertThat(resolvedIssue.getStatus()).isEqualTo("RESOLVED");
    assertThat(resolvedIssue.getResolution()).isEqualTo("FIXED");
    assertThat(resolvedIssue.getCreationDate()).isEqualTo(issue.getCreationDate());
    assertThat(resolvedIssue.hasCloseDate()).isFalse();
    // re-execute scan without rules -> the issue is removed with resolution "REMOVED"
    analysisWithoutIssues.run();
    // reload issue
    Issue closedIssue = issueRule.getByKey(issue.getKey());
    assertThat(closedIssue.getStatus()).isEqualTo("CLOSED");
    assertThat(closedIssue.getResolution()).isEqualTo("REMOVED");
    assertThat(closedIssue.getCreationDate()).isEqualTo(issue.getCreationDate());
    assertThat(toDatetime(closedIssue.getUpdateDate())).isAfter(toDatetime(resolvedIssue.getUpdateDate()));
    assertThat(closedIssue.hasCloseDate()).isTrue();
    assertThat(toDatetime(closedIssue.getCloseDate())).isAfter(toDatetime(closedIssue.getCreationDate()));
}
Also used : Issue(org.sonarqube.ws.Issues.Issue) DoTransitionRequest(org.sonarqube.ws.client.issue.DoTransitionRequest) Test(org.junit.Test)

Example 13 with Issue

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

the class IssueActionTest method change_severity.

/**
   * SONAR-4352
   */
@Test
public void change_severity() {
    String componentKey = "sample";
    // there are no blocker issues
    assertThat(searchIssuesBySeverities(componentKey, "BLOCKER")).isEmpty();
    // increase the severity of an issue
    issuesService.setSeverity(new SetSeverityRequest(randomIssue.getKey(), "BLOCKER"));
    assertThat(searchIssuesBySeverities(componentKey, "BLOCKER")).hasSize(1);
    projectAnalysis.run();
    Issue reloaded = issueRule.getByKey(randomIssue.getKey());
    assertThat(reloaded.getSeverity()).isEqualTo(BLOCKER);
    assertThat(reloaded.getStatus()).isEqualTo("OPEN");
    assertThat(reloaded.hasResolution()).isFalse();
    assertThat(reloaded.getCreationDate()).isEqualTo(randomIssue.getCreationDate());
    assertThat(toDatetime(reloaded.getCreationDate())).isBefore(toDatetime(reloaded.getUpdateDate()));
}
Also used : Issue(org.sonarqube.ws.Issues.Issue) SetSeverityRequest(org.sonarqube.ws.client.issue.SetSeverityRequest) Test(org.junit.Test)

Example 14 with Issue

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

the class IssueBulkChangeTest method should_setSeverity_add_comment_in_single_WS_call.

@Test
public void should_setSeverity_add_comment_in_single_WS_call() {
    xooSampleLittleIssuesAnalysis.run();
    String newSeverity = "BLOCKER";
    String[] issueKeys = searchIssueKeys(BULK_EDITED_ISSUE_COUNT);
    BulkChangeWsResponse bulkChangeResponse = issuesService.bulkChange(BulkChangeRequest.builder().setIssues(asList(issueKeys)).setSetSeverity(newSeverity).setComment(COMMENT_AS_MARKDOWN).build());
    assertThat(bulkChangeResponse.getSuccess()).isEqualTo(BULK_EDITED_ISSUE_COUNT);
    for (Issue issue : issueRule.getByKeys(issueKeys)) {
        assertThat(issue.getComments().getCommentsList()).hasSize(1);
        assertThat(issue.getComments().getComments(0).getHtmlText()).isEqualTo(COMMENT_AS_HTML);
    }
}
Also used : Issue(org.sonarqube.ws.Issues.Issue) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 15 with Issue

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

the class IssueBulkChangeTest method should_add_comment_only_on_issues_that_will_be_changed.

@Test
public void should_add_comment_only_on_issues_that_will_be_changed() {
    xooSampleLittleIssuesAnalysis.run();
    int nbIssues = BULK_EDITED_ISSUE_COUNT;
    String[] issueKeys = searchIssueKeys(nbIssues);
    // Confirm an issue
    adminIssueClient().doTransition(searchIssues().iterator().next().key(), "confirm");
    // Apply a bulk change on unconfirm transition
    BulkChangeWsResponse bulkChangeResponse = issuesService.bulkChange(BulkChangeRequest.builder().setIssues(asList(issueKeys)).setDoTransition("unconfirm").setComment("this is my comment").build());
    assertThat(bulkChangeResponse.getSuccess()).isEqualTo(1);
    int nbIssuesWithComment = 0;
    for (Issues.Issue issue : issueRule.getByKeys(issueKeys)) {
        if (!issue.getComments().getCommentsList().isEmpty()) {
            nbIssuesWithComment++;
        }
    }
    // Only one issue should have the comment
    assertThat(nbIssuesWithComment).isEqualTo(1);
}
Also used : Issue(org.sonarqube.ws.Issues.Issue) Issues(org.sonarqube.ws.Issues) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) 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