use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue 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.ChangedIssue in project sonarqube by SonarSource.
the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_for_multiple_hotspots_of_same_rule_on_same_project_on_master.
@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_for_multiple_hotspots_of_same_rule_on_same_project_on_master(Change change, FpOrWontFix fpOrWontFix) {
Project project = newProject("1");
String ruleName = randomAlphabetic(8);
String host = randomAlphabetic(15);
Rule rule = newSecurityHotspotRule(ruleName);
List<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> newChangedIssue("issue_" + i, project, rule)).collect(toList());
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix));
String expectedHref = host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C"));
String expectedLinkText = "See all " + changedIssues.size() + " hotspots";
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project.getProjectName()).hasList("Rule " + ruleName + " - " + expectedLinkText).withLink(expectedLinkText, expectedHref).hasParagraph().hasParagraph().noMoreBlock();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_with_projects_ordered_by_name.
@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_with_projects_ordered_by_name(Change change, FpOrWontFix fpOrWontFix) {
Project project1 = newProject("1");
Project project1Branch1 = newBranch("1", "a");
Project project1Branch2 = newBranch("1", "b");
Project project2 = newProject("B");
Project project2Branch1 = newBranch("B", "a");
Project project3 = newProject("C");
String host = randomAlphabetic(15);
List<ChangedIssue> changedIssues = Stream.of(project1, project1Branch1, project1Branch2, project2, project2Branch1, project3).map(project -> newChangedIssue("issue_" + project.getUuid(), project, newRandomNotAHotspotRule(randomAlphabetic(2)))).collect(toList());
Collections.shuffle(changedIssues);
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix));
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project1.getProjectName()).hasList().hasParagraph(project1Branch1.getProjectName() + ", " + project1Branch1.getBranchName().get()).hasList().hasParagraph(project1Branch2.getProjectName() + ", " + project1Branch2.getBranchName().get()).hasList().hasParagraph(project2.getProjectName()).hasList().hasParagraph(project2Branch1.getProjectName() + ", " + project2Branch1.getBranchName().get()).hasList().hasParagraph(project3.getProjectName()).hasList().hasParagraph().hasParagraph().noMoreBlock();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_for_single_issue_on_master.
@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_for_single_issue_on_master(Change change, FpOrWontFix fpOrWontFix) {
Project project = newProject("1");
String ruleName = randomAlphabetic(8);
String host = randomAlphabetic(15);
ChangedIssue changedIssue = newChangedIssue("key", project, ruleName, randomRuleTypeHotspotExcluded());
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssue), fpOrWontFix));
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project.getProjectName()).hasList("Rule " + ruleName + " - See the single issue").withLink("See the single issue", host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssue.getKey() + "&open=" + changedIssue.getKey()).hasParagraph().hasParagraph().noMoreBlock();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues.
@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues(Change change, FpOrWontFix fpOrWontFix) {
Project project1 = newProject("1");
Project project2 = newProject("V");
Project project2Branch = newBranch("V", "AB");
Rule rule1 = newRandomNotAHotspotRule("1");
Rule rule2 = newRandomNotAHotspotRule("a");
String host = randomAlphabetic(15);
List<ChangedIssue> changedIssues = Stream.of(IntStream.range(0, 39).mapToObj(i -> newChangedIssue("39_" + i, project1, rule1)), IntStream.range(0, 40).mapToObj(i -> newChangedIssue("40_" + i, project1, rule2)), IntStream.range(0, 81).mapToObj(i -> newChangedIssue("1-40_41-80_1_" + i, project2, rule2)), IntStream.range(0, 6).mapToObj(i -> newChangedIssue("6_" + i, project2Branch, rule1))).flatMap(t -> t).collect(toList());
Collections.shuffle(changedIssues);
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix));
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project1.getProjectName()).hasList().withItemTexts("Rule " + rule1.getName() + " - See all 39 issues", "Rule " + rule2.getName() + " - See all 40 issues").withLink("See all 39 issues", host + "/project/issues?id=" + project1.getKey() + "&issues=" + IntStream.range(0, 39).mapToObj(i -> "39_" + i).sorted().collect(joining("%2C"))).withLink("See all 40 issues", host + "/project/issues?id=" + project1.getKey() + "&issues=" + IntStream.range(0, 40).mapToObj(i -> "40_" + i).sorted().collect(joining("%2C"))).hasParagraph(project2.getProjectName()).hasList("Rule " + rule2.getName() + " - See issues 1-40 41-80 81").withLink("1-40", host + "/project/issues?id=" + project2.getKey() + "&issues=" + IntStream.range(0, 81).mapToObj(i -> "1-40_41-80_1_" + i).sorted().limit(40).collect(joining("%2C"))).withLink("41-80", host + "/project/issues?id=" + project2.getKey() + "&issues=" + IntStream.range(0, 81).mapToObj(i -> "1-40_41-80_1_" + i).sorted().skip(40).limit(40).collect(joining("%2C"))).withLink("81", host + "/project/issues?id=" + project2.getKey() + "&issues=" + "1-40_41-80_1_9" + "&open=" + "1-40_41-80_1_9").hasParagraph(project2Branch.getProjectName() + ", " + project2Branch.getBranchName().get()).hasList("Rule " + rule1.getName() + " - See all 6 issues").withLink("See all 6 issues", host + "/project/issues?id=" + project2Branch.getKey() + "&branch=" + project2Branch.getBranchName().get() + "&issues=" + IntStream.range(0, 6).mapToObj(i -> "6_" + i).sorted().collect(joining("%2C"))).hasParagraph().hasParagraph().noMoreBlock();
}
Aggregations