use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange 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.UserChange 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.UserChange in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_set_html_message_with_header_dealing_with_plural_security_hotspots_when_change_from_User.
@Test
public void format_set_html_message_with_header_dealing_with_plural_security_hotspots_when_change_from_User() {
Set<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(4)).mapToObj(i -> newChangedIssue(i + "", randomValidStatus(), newProject("prj_" + i), newSecurityHotspotRule("rule_" + i))).collect(toSet());
UserChange userChange = newUserChange();
EmailMessage singleIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, changedIssues.stream().limit(1).collect(toSet())));
EmailMessage multiIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, changedIssues));
HtmlFragmentAssert.assertThat(singleIssueMessage.getMessage()).hasParagraph("Hi,").withoutLink().hasParagraph("A manual change has updated a hotspot assigned to you:").withoutLink();
HtmlFragmentAssert.assertThat(multiIssueMessage.getMessage()).hasParagraph("Hi,").withoutLink().hasParagraph("A manual change has updated hotspots assigned to you:").withoutLink();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_branch_when_user_change.
@Test
public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_branch_when_user_change() {
String branchName = randomAlphabetic(19);
Project project = newBranch("1", branchName);
String ruleName = randomAlphabetic(8);
String host = randomAlphabetic(15);
Rule rule = newRandomNotAHotspotRule(ruleName);
List<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> newChangedIssue("issue_" + i, randomValidStatus(), project, rule)).collect(toList());
UserChange userChange = newUserChange();
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, ImmutableSet.copyOf(changedIssues)));
String expectedHref = host + "/project/issues?id=" + project.getKey() + "&branch=" + branchName + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C"));
String expectedLinkText = "See all " + changedIssues.size() + " issues";
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project.getProjectName() + ", " + branchName).hasList("Rule " + ruleName + " - " + expectedLinkText).withLink(expectedLinkText, expectedHref).hasParagraph().hasParagraph().noMoreBlock();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_for_single_issue_on_branch_when_user_change.
@Test
public void formats_returns_html_message_for_single_issue_on_branch_when_user_change() {
String branchName = randomAlphabetic(6);
Project project = newBranch("1", branchName);
String ruleName = randomAlphabetic(8);
String host = randomAlphabetic(15);
String key = "key";
ChangedIssue changedIssue = newChangedIssue(key, randomValidStatus(), project, ruleName, randomRuleTypeHotspotExcluded());
UserChange userChange = newUserChange();
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, ImmutableSet.of(changedIssue)));
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project.getProjectName() + ", " + branchName).hasList("Rule " + ruleName + " - See the single issue").withLink("See the single issue", host + "/project/issues?id=" + project.getKey() + "&branch=" + branchName + "&issues=" + changedIssue.getKey() + "&open=" + changedIssue.getKey()).hasParagraph().hasParagraph().noMoreBlock();
}
Aggregations