use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_maps_all_issues.
@Test
public void newIssuesChangesNotification_maps_all_issues() {
Set<DefaultIssue> issues = IntStream.range(0, 3 + new Random().nextInt(5)).mapToObj(i -> new DefaultIssue().setRuleKey(RuleKey.of("repo_" + i, "rule_" + i)).setKey("issue_key_" + i).setStatus("status_" + i)).collect(Collectors.toSet());
ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
long analysisDate = new Random().nextLong();
issues.stream().map(DefaultIssue::ruleKey).forEach(ruleKey -> ruleRepository.add(ruleKey));
treeRootHolder.setRoot(project);
analysisMetadata.setAnalysisDate(analysisDate);
analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, randomAlphabetic(12)));
IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
IssuesChangesNotification notification = underTest.newIssuesChangesNotification(issues, emptyMap());
assertThat(notification).isSameAs(expected);
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(issues.size());
Map<String, ChangedIssue> changedIssuesByKey = builder.getIssues().stream().collect(uniqueIndex(ChangedIssue::getKey));
issues.forEach(issue -> {
ChangedIssue changedIssue = changedIssuesByKey.get(issue.key());
assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).isEmpty();
assertThat(changedIssue.getRule().getKey()).isEqualTo(issue.ruleKey());
assertThat(changedIssue.getRule().getName()).isEqualTo(ruleRepository.getByKey(issue.ruleKey()).getName());
});
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_creates_rule_from_RuleRepository.
@Test
public void newIssuesChangesNotification_creates_rule_from_RuleRepository() {
RuleKey ruleKey = RuleKey.of("foo", "bar");
DefaultIssue issue = new DefaultIssue().setRuleKey(ruleKey).setKey("issueKey").setStatus(STATUS_OPEN);
Map<String, UserDto> assigneesByUuid = nonEmptyAssigneesByUuid();
ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
String branchName = randomAlphabetic(12);
ruleRepository.add(ruleKey);
treeRootHolder.setRoot(project);
analysisMetadata.setAnalysisDate(new Random().nextLong());
analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, branchName));
IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
IssuesChangesNotification notification = underTest.newIssuesChangesNotification(ImmutableSet.of(issue), assigneesByUuid);
assertThat(notification).isSameAs(expected);
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changeIssue = builder.getIssues().iterator().next();
assertThat(changeIssue.getRule().getKey()).isEqualTo(ruleKey);
assertThat(changeIssue.getRule().getName()).isEqualTo(ruleRepository.getByKey(ruleKey).getName());
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_set_html_message_with_header_dealing_with_plural_security_hotspots_and_issues_when_change_from_User.
@Test
public void format_set_html_message_with_header_dealing_with_plural_security_hotspots_and_issues_when_change_from_User() {
Set<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(4)).mapToObj(i -> newChangedIssue(i + "", randomValidStatus(), newProject("prj_" + i), newRandomNotAHotspotRule("rule_" + i))).collect(toSet());
Set<ChangedIssue> changedHotspots = IntStream.range(0, 2 + new Random().nextInt(4)).mapToObj(i -> newChangedIssue(i + "", randomValidStatus(), newProject("prj_" + i), newSecurityHotspotRule("rule_" + i))).collect(toSet());
Set<ChangedIssue> issuesAndHotspots = Sets.union(changedIssues, changedHotspots);
UserChange userChange = newUserChange();
EmailMessage multiIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, issuesAndHotspots));
HtmlFragmentAssert.assertThat(multiIssueMessage.getMessage()).hasParagraph("Hi,").withoutLink().hasParagraph("A manual change has updated issues/hotspots assigned to you:").withoutLink();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_sets_static_message_id_when_change_from_User.
@Test
public void format_sets_static_message_id_when_change_from_User() {
Set<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(4)).mapToObj(i -> newChangedIssue(i + "", randomValidStatus(), newProject("prj_" + i), newRandomNotAHotspotRule("rule_" + i))).collect(toSet());
UserChange userChange = newUserChange();
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, changedIssues));
assertThat(emailMessage.getMessageId()).isEqualTo("changes-on-my-issues");
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues_when_analysis_change.
@Test
public void formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues_when_analysis_change() {
Project project1 = newProject("1");
Rule rule1 = newRandomNotAHotspotRule("1");
Rule rule2 = newRandomNotAHotspotRule("a");
String host = randomAlphabetic(15);
String issueStatusClosed = STATUS_CLOSED;
String otherIssueStatus = STATUS_RESOLVED;
List<ChangedIssue> changedIssues = Stream.of(IntStream.range(0, 39).mapToObj(i -> newChangedIssue("39_" + i, issueStatusClosed, project1, rule1)), IntStream.range(0, 40).mapToObj(i -> newChangedIssue("40_" + i, issueStatusClosed, project1, rule2)), IntStream.range(0, 81).mapToObj(i -> newChangedIssue("1-40_41-80_1_" + i, otherIssueStatus, project1, rule2)), IntStream.range(0, 6).mapToObj(i -> newChangedIssue("6_" + i, otherIssueStatus, project1, rule1))).flatMap(t -> t).collect(toList());
Collections.shuffle(changedIssues);
AnalysisChange analysisChange = newAnalysisChange();
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.copyOf(changedIssues)));
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(// skip title based on status
"Closed issues:").hasList("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("Open issues:").hasList("Rule " + rule2.getName() + " - See issues 1-40 41-80 81", "Rule " + rule1.getName() + " - See all 6 issues").withLink("1-40", host + "/project/issues?id=" + project1.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=" + project1.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=" + project1.getKey() + "&issues=" + "1-40_41-80_1_9" + "&open=" + "1-40_41-80_1_9").withLink("See all 6 issues", host + "/project/issues?id=" + project1.getKey() + "&issues=" + IntStream.range(0, 6).mapToObj(i -> "6_" + i).sorted().collect(joining("%2C"))).hasParagraph().hasParagraph().noMoreBlock();
}
Aggregations