use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_with_projects_ordered_by_name_when_user_change.
@Test
public void formats_returns_html_message_with_projects_ordered_by_name_when_user_change() {
Project project1 = newProject("1");
Project project1Branch1 = newBranch("1", "a");
Project project1Branch2 = newBranch("1", "b");
Project project2 = newProject("B");
Project project2Branch1 = newBranch("B", "a");
Project project3 = newProject("C");
String host = randomAlphabetic(15);
List<ChangedIssue> changedIssues = Stream.of(project1, project1Branch1, project1Branch2, project2, project2Branch1, project3).map(project -> newChangedIssue("issue_" + project.getUuid(), randomValidStatus(), project, newRule(randomAlphabetic(2), randomRuleTypeHotspotExcluded()))).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(project1.getProjectName()).hasList().hasParagraph(project1Branch1.getProjectName() + ", " + project1Branch1.getBranchName().get()).hasList().hasParagraph(project1Branch2.getProjectName() + ", " + project1Branch2.getBranchName().get()).hasList().hasParagraph(project2.getProjectName()).hasList().hasParagraph(project2Branch1.getProjectName() + ", " + project2Branch1.getBranchName().get()).hasList().hasParagraph(project3.getProjectName()).hasList().hasParagraph().hasParagraph().noMoreBlock();
}
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_when_change_from_Analysis.
@Test
public void format_set_html_message_with_header_dealing_with_plural_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 singleIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues.stream().limit(1).collect(toSet())));
EmailMessage multiIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues));
HtmlFragmentAssert.assertThat(singleIssueMessage.getMessage()).hasParagraph("Hi,").hasParagraph("An analysis has updated an issue assigned to you:");
HtmlFragmentAssert.assertThat(multiIssueMessage.getMessage()).hasParagraph("Hi,").hasParagraph("An analysis has updated issues assigned to you:");
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class IssuesChangesNotificationBuilderTest method ChangedIssue_getters.
@Test
public void ChangedIssue_getters() {
Project project = new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build();
Rule rule = newRule("repository", "key", RuleType.CODE_SMELL, "name");
User user = new User("uuid", "login", "name");
ChangedIssue changedIssue = new ChangedIssue.Builder("key").setRule(rule).setProject(project).setNewStatus("status").setNewResolution("resolution").setAssignee(user).build();
assertThat(changedIssue.getKey()).isEqualTo("key");
assertThat(changedIssue.getNewStatus()).isEqualTo("status");
assertThat(changedIssue.getAssignee()).hasValue(user);
assertThat(changedIssue.getNewResolution()).hasValue("resolution");
assertThat(changedIssue.getProject()).isEqualTo(project);
assertThat(changedIssue.getRule()).isEqualTo(rule);
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesNotificationTest method hashcode_is_based_on_change_and_issues.
@Test
public void hashcode_is_based_on_change_and_issues() {
AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"), newRandomNotAHotspotRule("rul"));
ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue));
assertThat(underTest.hashCode()).isEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)).hashCode()).isNotEqualTo(mock(Notification.class).hashCode()).isNotEqualTo(new ChangesOnMyIssuesNotification(new AnalysisChange(analysisChange.getDate() + 10), ImmutableSet.of(changedIssue)).hashCode()).isNotEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of())).hashCode();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class FPOrWontFixNotificationHandlerTest method randomIssues.
private static Stream<ChangedIssue> randomIssues(Consumer<ChangedIssue.Builder> consumer) {
return IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> {
ChangedIssue.Builder builder = new ChangedIssue.Builder("key_" + i).setAssignee(new User(randomAlphabetic(3), randomAlphabetic(4), randomAlphabetic(5))).setNewStatus(randomAlphabetic(12)).setNewResolution(randomAlphabetic(13)).setRule(newRandomNotAHotspotRule(randomAlphabetic(8))).setProject(new Project.Builder(randomAlphabetic(9)).setKey(randomAlphabetic(10)).setProjectName(randomAlphabetic(11)).build());
consumer.accept(builder);
return builder.build();
});
}
Aggregations