Search in sources :

Example 36 with IssueDto

use of org.sonar.db.issue.IssueDto 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 37 with IssueDto

use of org.sonar.db.issue.IssueDto 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)

Example 38 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class BulkChangeActionTest method set_severity.

@Test
public void set_severity() throws Exception {
    setUserProjectPermissions(USER, ISSUE_ADMIN);
    IssueDto issueDto = db.issues().insertIssue(newUnresolvedIssue().setSeverity(MAJOR));
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(singletonList(issueDto.getKey())).setSetSeverity(MINOR).build());
    checkResponse(response, 1, 1, 0, 0);
    IssueDto reloaded = getIssueByKeys(issueDto.getKey()).get(0);
    assertThat(reloaded.getSeverity()).isEqualTo(MINOR);
    assertThat(reloaded.getUpdatedAt()).isEqualTo(NOW);
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 39 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class BulkChangeActionTest method does_not_update_severity_when_no_issue_admin_permission.

@Test
public void does_not_update_severity_when_no_issue_admin_permission() throws Exception {
    setUserProjectPermissions(USER, ISSUE_ADMIN);
    ComponentDto anotherProject = db.components().insertProject();
    ComponentDto anotherFile = db.components().insertComponent(newFileDto(anotherProject));
    addUserProjectPermissions(anotherProject, USER);
    IssueDto authorizedIssue1 = db.issues().insertIssue(newUnresolvedIssue().setSeverity(MAJOR));
    // User has not issue admin permission on these 2 issues
    IssueDto notAuthorizedIssue1 = db.issues().insertIssue(newUnresolvedIssue(rule, anotherFile, anotherProject).setSeverity(MAJOR));
    IssueDto notAuthorizedIssue2 = db.issues().insertIssue(newUnresolvedIssue(rule, anotherFile, anotherProject).setSeverity(MAJOR));
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(asList(authorizedIssue1.getKey(), notAuthorizedIssue1.getKey(), notAuthorizedIssue2.getKey())).setSetSeverity(MINOR).build());
    checkResponse(response, 3, 1, 2, 0);
    assertThat(getIssueByKeys(authorizedIssue1.getKey(), notAuthorizedIssue1.getKey(), notAuthorizedIssue2.getKey())).extracting(IssueDto::getKey, IssueDto::getSeverity, IssueDto::getUpdatedAt).containsOnly(tuple(authorizedIssue1.getKey(), MINOR, NOW), tuple(notAuthorizedIssue1.getKey(), MAJOR, notAuthorizedIssue1.getUpdatedAt()), tuple(notAuthorizedIssue2.getKey(), MAJOR, 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 40 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class BulkChangeActionTest method bulk_change_with_comment.

@Test
public void bulk_change_with_comment() throws Exception {
    setUserProjectPermissions(USER);
    IssueDto issueDto = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
    BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(singletonList(issueDto.getKey())).setDoTransition("confirm").setComment("type was badly defined").build());
    checkResponse(response, 1, 1, 0, 0);
    IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(db.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0);
    assertThat(issueComment.getUserLogin()).isEqualTo("john");
    assertThat(issueComment.getChangeData()).isEqualTo("type was badly defined");
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) IssueDto(org.sonar.db.issue.IssueDto) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Aggregations

IssueDto (org.sonar.db.issue.IssueDto)134 Test (org.junit.Test)117 ComponentDto (org.sonar.db.component.ComponentDto)48 RuleDto (org.sonar.db.rule.RuleDto)28 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)19 UserDto (org.sonar.db.user.UserDto)18 WsTester (org.sonar.server.ws.WsTester)18 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)15 FieldDiffs (org.sonar.core.issue.FieldDiffs)14 BulkChangeWsResponse (org.sonarqube.ws.Issues.BulkChangeWsResponse)14 ChangelogWsResponse (org.sonarqube.ws.Issues.ChangelogWsResponse)12 TestResponse (org.sonar.server.ws.TestResponse)9 Request (org.sonar.api.server.ws.Request)8 Response (org.sonar.api.server.ws.Response)8 DefaultIssue (org.sonar.core.issue.DefaultIssue)8 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)8 TestRequest (org.sonar.server.ws.TestRequest)8 Date (java.util.Date)6 DbSession (org.sonar.db.DbSession)5 IssueDao (org.sonar.db.issue.IssueDao)4