use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class BulkChangeActionTest method send_notification_only_on_changed_issues.
@Test
public void send_notification_only_on_changed_issues() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
RuleDefinitionDto rule = db.rules().insertIssueRule();
IssueDto issue1 = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG).setStatus(STATUS_OPEN).setResolution(null));
IssueDto issue2 = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG).setStatus(STATUS_OPEN).setResolution(null));
IssueDto issue3 = db.issues().insertIssue(rule, project, file, i -> i.setType(VULNERABILITY).setStatus(STATUS_OPEN).setResolution(null));
BulkChangeWsResponse response = call(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);
IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotificationCaptor.getValue());
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changedIssue = builder.getIssues().iterator().next();
assertThat(changedIssue.getKey()).isEqualTo(issue3.getKey());
assertThat(changedIssue.getNewStatus()).isEqualTo(STATUS_OPEN);
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).isEmpty();
assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
assertThat(changedIssue.getProject()).isEqualTo(projectOf(project));
assertThat(builder.getChange()).isEqualTo(new UserChange(NOW, userOf(user)));
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class BulkChangeActionTest method send_notification_on_branch.
@Test
public void send_notification_on_branch() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature").setBranchType(BranchType.BRANCH));
ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch));
addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
RuleDefinitionDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, branch, fileOnBranch, i -> i.setType(BUG).setStatus(STATUS_OPEN).setResolution(null));
BulkChangeWsResponse response = call(builder().setIssues(singletonList(issue.getKey())).setDoTransition("confirm").setSendNotifications(true).build());
checkResponse(response, 1, 1, 0, 0);
verify(notificationManager).scheduleForSending(issueChangeNotificationCaptor.capture());
IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotificationCaptor.getValue());
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changedIssue = builder.getIssues().iterator().next();
assertThat(changedIssue.getKey()).isEqualTo(issue.getKey());
assertThat(changedIssue.getNewStatus()).isEqualTo(STATUS_CONFIRMED);
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).isEmpty();
assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
assertThat(changedIssue.getProject()).isEqualTo(projectBranchOf(db, branch));
assertThat(builder.getChange()).isEqualTo(new UserChange(NOW, userOf(user)));
verifyPostProcessorCalled(fileOnBranch);
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class BulkChangeActionTest method send_notification.
@Test
public void send_notification() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
RuleDefinitionDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG).setStatus(STATUS_OPEN).setResolution(null));
BulkChangeWsResponse response = call(builder().setIssues(singletonList(issue.getKey())).setDoTransition("confirm").setSendNotifications(true).build());
checkResponse(response, 1, 1, 0, 0);
verify(notificationManager).scheduleForSending(issueChangeNotificationCaptor.capture());
IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotificationCaptor.getValue());
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changedIssue = builder.getIssues().iterator().next();
assertThat(changedIssue.getKey()).isEqualTo(issue.getKey());
assertThat(changedIssue.getProject().getUuid()).isEqualTo(project.uuid());
assertThat(changedIssue.getProject().getKey()).isEqualTo(project.getKey());
assertThat(changedIssue.getProject().getProjectName()).isEqualTo(project.name());
assertThat(changedIssue.getProject().getBranchName()).isEmpty();
assertThat(changedIssue.getRule().getKey()).isEqualTo(rule.getKey());
assertThat(changedIssue.getRule().getName()).isEqualTo(rule.getName());
assertThat(builder.getChange().getDate()).isEqualTo(NOW);
assertThat(builder.getChange()).isInstanceOf(UserChange.class);
UserChange userChange = (UserChange) builder.getChange();
assertThat(userChange.getUser().getUuid()).isEqualTo(user.getUuid());
assertThat(userChange.getUser().getLogin()).isEqualTo(user.getLogin());
assertThat(userChange.getUser().getName()).contains(user.getName());
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification_on_branch.
@Test
public void verify_notification_on_branch() {
RuleDefinitionDto rule = db.rules().insertIssueRule();
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BRANCH));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
DefaultIssue issue = db.issues().insertIssue(rule, branch, file, t -> t.setSeverity(MAJOR)).toDefaultIssue();
UserDto changeAuthor = db.users().insertUser();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssuesChangesNotification issueChangeNotification = notificationArgumentCaptor.getValue();
IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotification);
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changedIssue = builder.getIssues().iterator().next();
assertThat(changedIssue.getKey()).isEqualTo(issue.key());
assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).isEmpty();
assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
assertThat(changedIssue.getProject()).isEqualTo(projectBranchOf(db, branch));
assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor)));
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification_with_resolution.
@Test
public void verify_notification_with_resolution() {
UserDto assignee = db.users().insertUser();
RuleDefinitionDto rule = db.rules().insertIssueRule();
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
DefaultIssue issue = db.issues().insertIssue(rule, project, file, t -> t.setSeverity(MAJOR).setAssigneeUuid(assignee.getUuid())).toDefaultIssue();
UserDto changeAuthor = db.users().insertUser();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
issueFieldsSetter.setResolution(issue, RESOLUTION_FIXED, context);
underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssuesChangesNotification issueChangeNotification = notificationArgumentCaptor.getValue();
IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotification);
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changedIssue = builder.getIssues().iterator().next();
assertThat(changedIssue.getKey()).isEqualTo(issue.key());
assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
assertThat(changedIssue.getNewResolution()).contains(RESOLUTION_FIXED);
assertThat(changedIssue.getAssignee()).contains(userOf(assignee));
assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
assertThat(changedIssue.getProject()).isEqualTo(projectOf(project));
assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor)));
}
Aggregations