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_issues_when_change_from_User.
@Test
public void format_set_html_message_with_header_dealing_with_plural_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());
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 an issue assigned to you:").withoutLink();
HtmlFragmentAssert.assertThat(multiIssueMessage.getMessage()).hasParagraph("Hi,").withoutLink().hasParagraph("A manual change has updated issues assigned to you:").withoutLink();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_sets_subject_with_project_name_of_first_issue_in_set_when_change_from_Analysis.
@Test
public void format_sets_subject_with_project_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(), newProject("prj_" + i), newRandomNotAHotspotRule("rule_" + i))).collect(toSet());
AnalysisChange analysisChange = IssuesChangesNotificationBuilderTesting.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());
}
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_master_when_analysis_change.
@Test
public void formats_returns_html_message_for_single_issue_on_master_when_analysis_change() {
Project project = newProject("1");
String ruleName = randomAlphabetic(8);
String host = randomAlphabetic(15);
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() + "&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 formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_master_when_analysis_change.
@Test
public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_master_when_analysis_change() {
Project project = newProject("1");
String ruleName = randomAlphabetic(8);
String host = randomAlphabetic(15);
Rule rule = newRule(ruleName, randomRuleTypeHotspotExcluded());
String issueStatus = randomValidStatus();
List<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> newChangedIssue("issue_" + i, issueStatus, project, rule)).collect(toList());
AnalysisChange analysisChange = newAnalysisChange();
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.copyOf(changedIssues)));
String expectedHref = host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C"));
String expectedLinkText = "See all " + changedIssues.size() + " issues";
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph().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 ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_with_rules_ordered_by_name_user_change.
@Test
public void formats_returns_html_message_with_rules_ordered_by_name_user_change() {
Project project = newProject("1");
Rule rule1 = newRandomNotAHotspotRule("1");
Rule rule2 = newRandomNotAHotspotRule("a");
Rule rule3 = newRandomNotAHotspotRule("b");
Rule rule4 = newRandomNotAHotspotRule("X");
Rule hotspot1 = newSecurityHotspotRule("S");
Rule hotspot2 = newSecurityHotspotRule("Z");
Rule hotspot3 = newSecurityHotspotRule("N");
Rule hotspot4 = newSecurityHotspotRule("M");
String host = randomAlphabetic(15);
List<ChangedIssue> changedIssues = Stream.of(rule1, rule2, rule3, rule4, hotspot1, hotspot2, hotspot3, hotspot4).map(rule -> newChangedIssue("issue_" + rule.getName(), randomValidStatus(), project, rule)).collect(toList());
Collections.shuffle(changedIssues);
UserChange userChange = newUserChange();
when(emailSettings.getServerBaseURL()).thenReturn(host);
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, ImmutableSet.copyOf(changedIssues)));
HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph().hasList("Rule " + rule1.getName() + " - See the single issue", "Rule " + rule2.getName() + " - See the single issue", "Rule " + rule3.getName() + " - See the single issue", "Rule " + rule4.getName() + " - See the single issue").hasEmptyParagraph().hasList("Rule " + hotspot1.getName() + " - See the single hotspot", "Rule " + hotspot2.getName() + " - See the single hotspot", "Rule " + hotspot3.getName() + " - See the single hotspot", "Rule " + hotspot4.getName() + " - See the single hotspot").hasParagraph().hasParagraph().noMoreBlock();
}
Aggregations