Search in sources :

Example 16 with BulkChangeWsResponse

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

the class BulkChangeActionTest method add_comment_only_on_changed_issues.

@Test
public void add_comment_only_on_changed_issues() 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()).setComment("test").build());
    checkResponse(response, 3, 1, 2, 0);
    assertThat(dbClient.issueChangeDao().selectByTypeAndIssueKeys(db.getSession(), singletonList(issue1.getKey()), TYPE_COMMENT)).hasSize(1);
    assertThat(dbClient.issueChangeDao().selectByTypeAndIssueKeys(db.getSession(), singletonList(issue2.getKey()), TYPE_COMMENT)).isEmpty();
    assertThat(dbClient.issueChangeDao().selectByTypeAndIssueKeys(db.getSession(), singletonList(issue3.getKey()), TYPE_COMMENT)).isEmpty();
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 17 with BulkChangeWsResponse

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

the class BulkChangeActionTest method bulk_change_many_issues.

@Test
public void bulk_change_many_issues() throws Exception {
    setUserProjectPermissions(USER, ISSUE_ADMIN);
    UserDto userToAssign = db.users().insertUser("arthur");
    IssueDto issue1 = db.issues().insertIssue(newUnresolvedIssue().setAssignee(user.getLogin())).setType(BUG).setSeverity(MINOR);
    IssueDto issue2 = db.issues().insertIssue(newUnresolvedIssue().setAssignee(userToAssign.getLogin())).setType(BUG).setSeverity(MAJOR);
    IssueDto issue3 = db.issues().insertIssue(newUnresolvedIssue().setAssignee(null)).setType(VULNERABILITY).setSeverity(MAJOR);
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(asList(issue1.getKey(), issue2.getKey(), issue3.getKey())).setAssign(userToAssign.getLogin()).setSetSeverity(MINOR).setSetType(VULNERABILITY.name()).build());
    checkResponse(response, 3, 3, 0, 0);
    assertThat(getIssueByKeys(issue1.getKey(), issue2.getKey(), issue3.getKey())).extracting(IssueDto::getKey, IssueDto::getAssignee, IssueDto::getType, IssueDto::getSeverity, IssueDto::getUpdatedAt).containsOnly(tuple(issue1.getKey(), userToAssign.getLogin(), VULNERABILITY.getDbConstant(), MINOR, NOW), tuple(issue2.getKey(), userToAssign.getLogin(), VULNERABILITY.getDbConstant(), MINOR, NOW), tuple(issue3.getKey(), userToAssign.getLogin(), VULNERABILITY.getDbConstant(), MINOR, NOW));
}
Also used : UserDto(org.sonar.db.user.UserDto) IssueDto(org.sonar.db.issue.IssueDto) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 18 with BulkChangeWsResponse

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

the class BulkChangeActionTest method issues_on_which_user_has_not_browse_permission_are_ignored.

@Test
public void issues_on_which_user_has_not_browse_permission_are_ignored() throws Exception {
    setUserProjectPermissions(USER, ISSUE_ADMIN);
    ComponentDto anotherProject = db.components().insertProject();
    ComponentDto anotherFile = db.components().insertComponent(newFileDto(anotherProject));
    IssueDto authorizedIssue = db.issues().insertIssue(newUnresolvedIssue(rule, file, project).setType(BUG));
    // User has not browse permission on these 2 issues
    IssueDto notAuthorizedIssue1 = db.issues().insertIssue(newUnresolvedIssue(rule, anotherFile, anotherProject).setType(BUG));
    IssueDto notAuthorizedIssue2 = db.issues().insertIssue(newUnresolvedIssue(rule, anotherFile, anotherProject).setType(BUG));
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(asList(authorizedIssue.getKey(), notAuthorizedIssue1.getKey(), notAuthorizedIssue2.getKey())).setSetType(VULNERABILITY.name()).build());
    checkResponse(response, 1, 1, 0, 0);
    assertThat(getIssueByKeys(authorizedIssue.getKey(), notAuthorizedIssue1.getKey(), notAuthorizedIssue2.getKey())).extracting(IssueDto::getKey, IssueDto::getType, IssueDto::getUpdatedAt).containsOnly(tuple(authorizedIssue.getKey(), VULNERABILITY.getDbConstant(), NOW), tuple(notAuthorizedIssue1.getKey(), BUG.getDbConstant(), notAuthorizedIssue1.getUpdatedAt()), tuple(notAuthorizedIssue2.getKey(), BUG.getDbConstant(), notAuthorizedIssue2.getUpdatedAt()));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 19 with BulkChangeWsResponse

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

the class BulkChangeActionTest method set_type.

@Test
public void set_type() throws Exception {
    setUserProjectPermissions(USER, ISSUE_ADMIN);
    IssueDto issueDto = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(singletonList(issueDto.getKey())).setSetType(RuleType.CODE_SMELL.name()).build());
    checkResponse(response, 1, 1, 0, 0);
    IssueDto reloaded = getIssueByKeys(issueDto.getKey()).get(0);
    assertThat(reloaded.getType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant());
    assertThat(reloaded.getUpdatedAt()).isEqualTo(NOW);
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 20 with BulkChangeWsResponse

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

the class BulkChangeActionTest method ignore_issues_when_condition_does_not_match.

@Test
public void ignore_issues_when_condition_does_not_match() throws Exception {
    setUserProjectPermissions(USER, ISSUE_ADMIN);
    IssueDto issue1 = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
    // These 2 issues will be ignored as they are resolved, changing type is not possible
    IssueDto issue2 = db.issues().insertIssue(newResolvedIssue().setType(BUG));
    IssueDto issue3 = db.issues().insertIssue(newResolvedIssue().setType(BUG));
    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(issue3.getKey(), BUG.getDbConstant(), issue2.getUpdatedAt()), tuple(issue2.getKey(), BUG.getDbConstant(), issue3.getUpdatedAt()));
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) 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