use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_set_html_message_with_footer.
private void format_set_html_message_with_footer(Change change, String issueStatus, Function<HtmlParagraphAssert, HtmlListAssert> skipContent, RuleType ruleType) {
String wordingNotification = randomAlphabetic(20);
String host = randomAlphabetic(15);
when(i18n.message(Locale.ENGLISH, "notification.dispatcher.ChangesOnMyIssue", "notification.dispatcher.ChangesOnMyIssue")).thenReturn(wordingNotification);
when(emailSettings.getServerBaseURL()).thenReturn(host);
Project project = newProject("foo");
Rule rule = newRule("bar", ruleType);
Set<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(4)).mapToObj(i -> newChangedIssue(i + "", issueStatus, project, rule)).collect(toSet());
EmailMessage singleIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(change, changedIssues.stream().limit(1).collect(toSet())));
EmailMessage multiIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(change, changedIssues));
Stream.of(singleIssueMessage, multiIssueMessage).forEach(issueMessage -> {
HtmlParagraphAssert htmlAssert = HtmlFragmentAssert.assertThat(issueMessage.getMessage()).hasParagraph().hasParagraph();
// skip content
HtmlListAssert htmlListAssert = skipContent.apply(htmlAssert);
String footerText = "You received this email because you are subscribed to \"" + wordingNotification + "\" notifications from SonarQube." + " Click here to edit your email preferences.";
htmlListAssert.hasEmptyParagraph().hasParagraph(footerText).withSmallOn(footerText).withLink("here", host + "/account/notifications").noMoreBlock();
});
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_sets_subject_with_project_name_and_branch_name_of_first_issue_in_set_when_change_from_Analysis.
@Test
public void format_sets_subject_with_project_name_and_branch_name_of_first_issue_in_set_when_change_from_Analysis() {
Set<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(4)).mapToObj(i -> newChangedIssue(i + "", randomValidStatus(), newBranch("prj_" + i, "br_" + i), newRandomNotAHotspotRule("rule_" + i))).collect(toSet());
AnalysisChange analysisChange = newAnalysisChange();
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues));
Project project = changedIssues.iterator().next().getProject();
assertThat(emailMessage.getSubject()).isEqualTo("Analysis has changed some of your issues in " + project.getProjectName() + ", " + project.getBranchName().get());
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_for_single_issue_on_branch_when_analysis_change.
@Test
public void formats_returns_html_message_for_single_issue_on_branch_when_analysis_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());
AnalysisChange analysisChange = newAnalysisChange();
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)));
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph().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();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_sets_message_id_with_project_key_of_first_issue_in_set_when_change_from_Analysis.
@Test
public void format_sets_message_id_with_project_key_of_first_issue_in_set_when_change_from_Analysis() {
Set<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(4)).mapToObj(i -> newChangedIssue(i + "", randomValidStatus(), newProject("prj_" + i), newRandomNotAHotspotRule("rule_" + i))).collect(toSet());
AnalysisChange analysisChange = newAnalysisChange();
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues));
assertThat(emailMessage.getMessageId()).isEqualTo("changes-on-my-issues/" + changedIssues.iterator().next().getProject().getKey());
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_sets_static_subject_when_change_from_User.
@Test
public void format_sets_static_subject_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.getSubject()).isEqualTo("A manual update has changed some of your issues/hotspots");
}
Aggregations