Search in sources :

Example 1 with BulkChangeWsResponse

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

the class IssueBulkChangeTest method should_apply_bulk_change_on_many_actions.

@Test
public void should_apply_bulk_change_on_many_actions() {
    xooSampleLittleIssuesAnalysis.run();
    String[] issueKeys = searchIssueKeys(BULK_EDITED_ISSUE_COUNT);
    BulkChangeWsResponse bulkChangeResponse = issuesService.bulkChange(BulkChangeRequest.builder().setIssues(asList(issueKeys)).setDoTransition("confirm").setAssign("admin").setSetSeverity("BLOCKER").setComment(COMMENT_AS_MARKDOWN).build());
    assertThat(bulkChangeResponse.getSuccess()).isEqualTo(BULK_EDITED_ISSUE_COUNT);
    for (Issue issue : issueRule.getByKeys(issueKeys)) {
        assertThat(issue.getStatus()).isEqualTo("CONFIRMED");
        assertThat(issue.getAssignee()).isEqualTo("admin");
        assertThat(issue.getSeverity()).isEqualTo(BLOCKER);
        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 2 with BulkChangeWsResponse

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

the class IssueBulkChangeTest method should_assign.

@Test
public void should_assign() {
    xooSampleLittleIssuesAnalysis.run();
    String[] issueKeys = searchIssueKeys(BULK_EDITED_ISSUE_COUNT);
    BulkChangeWsResponse bulkChangeResponse = buldChangeAssigneeOfIssues(issueKeys, "admin");
    assertThat(bulkChangeResponse.getSuccess()).isEqualTo(BULK_EDITED_ISSUE_COUNT);
    for (Issue issue : issueRule.getByKeys(issueKeys)) {
        assertThat(issue.getAssignee()).isEqualTo("admin");
    }
}
Also used : Issue(org.sonarqube.ws.Issues.Issue) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 3 with BulkChangeWsResponse

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

the class BulkChangeActionTest method send_notification_only_on_changed_issues.

@Test
public void send_notification_only_on_changed_issues() throws Exception {
    setUserProjectPermissions(USER, ISSUE_ADMIN);
    IssueDto issue1 = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
    IssueDto issue2 = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
    IssueDto issue3 = db.issues().insertIssue(newUnresolvedIssue().setType(VULNERABILITY));
    ArgumentCaptor<IssueChangeNotification> issueChangeNotificationCaptor = ArgumentCaptor.forClass(IssueChangeNotification.class);
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(asList(issue1.getKey(), issue2.getKey(), issue3.getKey())).setSetType(RuleType.BUG.name()).setSendNotifications(true).build());
    checkResponse(response, 3, 1, 2, 0);
    verify(notificationManager).scheduleForSending(issueChangeNotificationCaptor.capture());
    assertThat(issueChangeNotificationCaptor.getAllValues()).hasSize(1);
    assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("key")).isEqualTo(issue3.getKey());
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 4 with BulkChangeWsResponse

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

the class BulkChangeActionTest method ignore_issues_when_there_is_nothing_to_do.

@Test
public void ignore_issues_when_there_is_nothing_to_do() throws Exception {
    setUserProjectPermissions(USER, ISSUE_ADMIN);
    IssueDto issue1 = db.issues().insertIssue(newUnresolvedIssue().setType(BUG).setSeverity(MINOR));
    // These 2 issues will be ignored as there's nothing to do
    IssueDto issue2 = db.issues().insertIssue(newUnresolvedIssue().setType(VULNERABILITY));
    IssueDto issue3 = db.issues().insertIssue(newUnresolvedIssue().setType(VULNERABILITY));
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(asList(issue1.getKey(), issue2.getKey(), issue3.getKey())).setSetType(VULNERABILITY.name()).build());
    checkResponse(response, 3, 1, 2, 0);
    assertThat(getIssueByKeys(issue1.getKey(), issue2.getKey(), issue3.getKey())).extracting(IssueDto::getKey, IssueDto::getType, IssueDto::getUpdatedAt).containsOnly(tuple(issue1.getKey(), VULNERABILITY.getDbConstant(), NOW), tuple(issue2.getKey(), VULNERABILITY.getDbConstant(), issue2.getUpdatedAt()), tuple(issue3.getKey(), VULNERABILITY.getDbConstant(), issue3.getUpdatedAt()));
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 5 with BulkChangeWsResponse

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

the class BulkChangeActionTest method send_notification.

@Test
public void send_notification() throws Exception {
    setUserProjectPermissions(USER);
    IssueDto issueDto = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
    ArgumentCaptor<IssueChangeNotification> issueChangeNotificationCaptor = ArgumentCaptor.forClass(IssueChangeNotification.class);
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(singletonList(issueDto.getKey())).setDoTransition("confirm").setSendNotifications(true).build());
    checkResponse(response, 1, 1, 0, 0);
    verify(notificationManager).scheduleForSending(issueChangeNotificationCaptor.capture());
    assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("key")).isEqualTo(issueDto.getKey());
    assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("componentName")).isEqualTo(file.longName());
    assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("projectName")).isEqualTo(project.longName());
    assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("projectKey")).isEqualTo(project.key());
    assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("ruleName")).isEqualTo(rule.getName());
    assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("changeAuthor")).isEqualTo(user.getLogin());
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 BulkChangeWsResponse (org.sonarqube.ws.Issues.BulkChangeWsResponse)21 IssueDto (org.sonar.db.issue.IssueDto)14 Issue (org.sonarqube.ws.Issues.Issue)4 ComponentDto (org.sonar.db.component.ComponentDto)3 IssueChangeNotification (org.sonar.server.issue.notification.IssueChangeNotification)2 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)1 UserDto (org.sonar.db.user.UserDto)1 Issues (org.sonarqube.ws.Issues)1