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_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.ChangedIssue 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.ChangedIssue 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();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class IssuesChangesNotificationBuilderTest method fail_if_changed_issues_empty.
@Test
public void fail_if_changed_issues_empty() {
AnalysisChange analysisChange = new AnalysisChange(1_000_000_000L);
Set<ChangedIssue> issues = Collections.emptySet();
assertThatThrownBy(() -> new IssuesChangesNotificationBuilder(issues, analysisChange)).isInstanceOf(IllegalArgumentException.class).hasMessage("issues can't be empty");
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class IssuesChangesNotificationBuilderTest method ChangedIssue_toString.
@Test
public void ChangedIssue_toString() {
ChangedIssue changedIssue = new ChangedIssue.Builder("key").setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")).setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()).setNewStatus("status").setNewResolution("resolution").setAssignee(new User("uuid", "login", "name")).build();
assertThat(changedIssue).hasToString("ChangedIssue{key='key', newStatus='status', newResolution='resolution', " + "assignee=User{uuid='uuid', login='login', name='name'}, " + "rule=Rule{key=repository:key, type=CODE_SMELL, name='name'}, " + "project=Project{uuid='uuid', key='key', projectName='name', branchName='branch-name'}}");
}
Aggregations