use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule 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();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule 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.Rule in project sonarqube by SonarSource.
the class IssuesChangesNotificationBuilderTest method Rule_not_equal.
@Test
@UseDataProvider("ruleData")
public void Rule_not_equal(Object object) {
Rule rule = newRule("repository1", "key1", RuleType.CODE_SMELL, "name1");
assertThat(rule.equals(object)).isFalse();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule in project sonarqube by SonarSource.
the class IssuesChangesNotificationBuilderTest method Rule_equals.
@Test
public void Rule_equals() {
Rule rule1 = newRule("repository", "key", RuleType.CODE_SMELL, "name");
Rule rule2 = newRule("repository", "key", RuleType.CODE_SMELL, "name");
assertThat(rule1).isEqualTo(rule2).isEqualTo(rule1);
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule 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_user_change.
@Test
public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_master_when_user_change() {
Project project = newProject("1");
String ruleName = randomAlphabetic(8);
String host = randomAlphabetic(15);
Rule rule = newRule(ruleName, randomRuleTypeHotspotExcluded());
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() + "&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()).hasList("Rule " + ruleName + " - " + expectedLinkText).withLink(expectedLinkText, expectedHref).hasParagraph().hasParagraph().noMoreBlock();
}
Aggregations