use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange in project sonarqube by SonarSource.
the class ChangesOnMyIssueNotificationHandlerTest method deliver_ignores_issues_which_assignee_is_the_changeAuthor.
@Test
@UseDataProvider("userOrAnalysisChange")
public void deliver_ignores_issues_which_assignee_is_the_changeAuthor(Change userOrAnalysisChange) {
when(emailNotificationChannel.isActivated()).thenReturn(true);
Project project1 = newProject();
Project project2 = newProject();
User assignee1 = newUser("assignee_1");
User assignee2 = newUser("assignee_2");
Set<ChangedIssue> assignee1Issues = IntStream.range(0, 10).mapToObj(i -> newChangedIssue("1_issue_key_" + i, assignee1, project1)).collect(toSet());
Set<ChangedIssue> assignee2Issues = IntStream.range(0, 10).mapToObj(i -> newChangedIssue("2_issue_key_" + i, assignee2, project2)).collect(toSet());
UserChange assignee2Change1 = new UserChange(new Random().nextLong(), assignee2);
Set<IssuesChangesNotification> notifications = Stream.of(// notification from assignee1 with issues from assignee1 only
new IssuesChangesNotificationBuilder(assignee1Issues.stream().limit(4).collect(toSet()), new UserChange(new Random().nextLong(), assignee1)), // notification from assignee2 with issues from assignee1 and assignee2
new IssuesChangesNotificationBuilder(Stream.concat(assignee1Issues.stream().skip(4).limit(2), assignee2Issues.stream().limit(4)).collect(toSet()), assignee2Change1), // notification from assignee2 with issues from assignee2 only
new IssuesChangesNotificationBuilder(assignee2Issues.stream().skip(4).limit(3).collect(toSet()), new UserChange(new Random().nextLong(), assignee2)), // notification from other change with issues from assignee1 and assignee2)
new IssuesChangesNotificationBuilder(Stream.concat(assignee1Issues.stream().skip(6), assignee2Issues.stream().skip(7)).collect(toSet()), userOrAnalysisChange)).map(t -> serializer.serialize(t)).collect(toSet());
when(notificationManager.findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project1.getKey(), ImmutableSet.of(assignee1.getLogin()), ALL_MUST_HAVE_ROLE_USER)).thenReturn(ImmutableSet.of(emailRecipientOf(assignee1.getLogin())));
when(notificationManager.findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project2.getKey(), ImmutableSet.of(assignee2.getLogin()), ALL_MUST_HAVE_ROLE_USER)).thenReturn(ImmutableSet.of(emailRecipientOf(assignee2.getLogin())));
int deliveredCount = new Random().nextInt(100);
when(emailNotificationChannel.deliverAll(anySet())).thenReturn(deliveredCount);
int deliver = underTest.deliver(notifications);
assertThat(deliver).isEqualTo(deliveredCount);
verify(notificationManager).findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project1.getKey(), ImmutableSet.of(assignee1.getLogin()), ALL_MUST_HAVE_ROLE_USER);
verify(notificationManager).findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project2.getKey(), ImmutableSet.of(assignee2.getLogin()), ALL_MUST_HAVE_ROLE_USER);
verifyNoMoreInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verify(emailNotificationChannel).deliverAll(emailDeliveryRequestSetCaptor.capture());
verifyNoMoreInteractions(emailNotificationChannel);
Set<EmailDeliveryRequest> emailDeliveryRequests = emailDeliveryRequestSetCaptor.getValue();
assertThat(emailDeliveryRequests).hasSize(3);
ListMultimap<String, EmailDeliveryRequest> emailDeliveryRequestByEmail = emailDeliveryRequests.stream().collect(index(EmailDeliveryRequest::getRecipientEmail));
List<EmailDeliveryRequest> assignee1Requests = emailDeliveryRequestByEmail.get(emailOf(assignee1.getLogin()));
assertThat(assignee1Requests).hasSize(2).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChange).containsOnly(userOrAnalysisChange, assignee2Change1);
assertThat(assignee1Requests).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChangedIssues).containsOnly(assignee1Issues.stream().skip(4).limit(2).collect(unorderedIndex(t -> project1, t -> t)), assignee1Issues.stream().skip(6).collect(unorderedIndex(t -> project1, t -> t)));
List<EmailDeliveryRequest> assignee2Requests = emailDeliveryRequestByEmail.get(emailOf(assignee2.getLogin()));
assertThat(assignee2Requests).hasSize(1).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChange).containsOnly(userOrAnalysisChange);
assertThat(assignee2Requests).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChangedIssues).containsOnly(assignee2Issues.stream().skip(7).collect(unorderedIndex(t -> project2, t -> t)));
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange in project sonarqube by SonarSource.
the class FpOrWontFixEmailTemplateTest method fpOrWontFixValuesByUserOrAnalysisChange.
@DataProvider
public static Object[][] fpOrWontFixValuesByUserOrAnalysisChange() {
AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
UserChange userChange = new UserChange(new Random().nextLong(), new User(randomAlphabetic(5), randomAlphabetic(6), new Random().nextBoolean() ? null : randomAlphabetic(7)));
return new Object[][] { { analysisChange, FP }, { analysisChange, WONT_FIX }, { userChange, FP }, { userChange, WONT_FIX } };
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange in project sonarqube by SonarSource.
the class FpOrWontFixEmailTemplateTest method userOrAnalysisChange.
@DataProvider
public static Object[][] userOrAnalysisChange() {
AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
UserChange userChange = new UserChange(new Random().nextLong(), new User(randomAlphabetic(5), randomAlphabetic(6), new Random().nextBoolean() ? null : randomAlphabetic(7)));
return new Object[][] { { analysisChange }, { userChange } };
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification_without_resolution.
@Test
public void verify_notification_without_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.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()).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)));
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification_when_assignee_has_changed.
@Test
public void verify_notification_when_assignee_has_changed() {
UserDto oldAssignee = 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.setAssigneeUuid(oldAssignee.getUuid())).toDefaultIssue();
UserDto changeAuthor = db.users().insertUser();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
UserDto newAssignee = db.users().insertUser();
issueFieldsSetter.assign(issue, newAssignee, 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()).contains(userOf(newAssignee));
assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
assertThat(changedIssue.getProject()).isEqualTo(projectOf(project));
assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor)));
}
Aggregations