use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_creates_project_from_TreeRootHolder_and_branch_name_only_on_non_main_branches.
@Test
@UseDataProvider("noBranchNameBranches")
public void newIssuesChangesNotification_creates_project_from_TreeRootHolder_and_branch_name_only_on_non_main_branches(Branch branch) {
RuleKey ruleKey = RuleKey.of("foo", "bar");
DefaultIssue issue = new DefaultIssue().setRuleKey(ruleKey).setKey("issueKey").setStatus(STATUS_OPEN);
Map<String, UserDto> assigneesByUuid = nonEmptyAssigneesByUuid();
ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
ruleRepository.add(ruleKey);
treeRootHolder.setRoot(project);
analysisMetadata.setAnalysisDate(new Random().nextLong());
analysisMetadata.setBranch(branch);
IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
IssuesChangesNotification notification = underTest.newIssuesChangesNotification(ImmutableSet.of(issue), assigneesByUuid);
assertThat(notification).isSameAs(expected);
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changeIssue = builder.getIssues().iterator().next();
assertThat(changeIssue.getProject().getUuid()).isEqualTo(project.getUuid());
assertThat(changeIssue.getProject().getKey()).isEqualTo(project.getKey());
assertThat(changeIssue.getProject().getProjectName()).isEqualTo(project.getName());
assertThat(changeIssue.getProject().getBranchName()).isEmpty();
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_creates_assignee_from_UserDto.
@Test
public void newIssuesChangesNotification_creates_assignee_from_UserDto() {
RuleKey ruleKey = RuleKey.of("foo", "bar");
String assigneeUuid = randomAlphabetic(40);
DefaultIssue issue = new DefaultIssue().setRuleKey(ruleKey).setKey("issueKey").setStatus(STATUS_OPEN).setAssigneeUuid(assigneeUuid);
UserDto userDto = UserTesting.newUserDto();
Map<String, UserDto> assigneesByUuid = ImmutableMap.of(assigneeUuid, userDto);
ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
ruleRepository.add(ruleKey);
treeRootHolder.setRoot(project);
analysisMetadata.setAnalysisDate(new Random().nextLong());
analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, randomAlphabetic(12)));
IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
IssuesChangesNotification notification = underTest.newIssuesChangesNotification(ImmutableSet.of(issue), assigneesByUuid);
assertThat(notification).isSameAs(expected);
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changeIssue = builder.getIssues().iterator().next();
assertThat(changeIssue.getAssignee()).isPresent();
IssuesChangesNotificationBuilder.User assignee = changeIssue.getAssignee().get();
assertThat(assignee.getUuid()).isEqualTo(userDto.getUuid());
assertThat(assignee.getName()).contains(userDto.getName());
assertThat(assignee.getLogin()).isEqualTo(userDto.getLogin());
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_creates_project_from_TreeRootHolder_and_branch_name_from_branch.
@Test
public void newIssuesChangesNotification_creates_project_from_TreeRootHolder_and_branch_name_from_branch() {
RuleKey ruleKey = RuleKey.of("foo", "bar");
DefaultIssue issue = new DefaultIssue().setRuleKey(ruleKey).setKey("issueKey").setStatus(STATUS_OPEN);
Map<String, UserDto> assigneesByUuid = nonEmptyAssigneesByUuid();
ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
String branchName = randomAlphabetic(12);
ruleRepository.add(ruleKey);
treeRootHolder.setRoot(project);
analysisMetadata.setAnalysisDate(new Random().nextLong());
analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, branchName));
IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
IssuesChangesNotification notification = underTest.newIssuesChangesNotification(ImmutableSet.of(issue), assigneesByUuid);
assertThat(notification).isSameAs(expected);
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changeIssue = builder.getIssues().iterator().next();
assertThat(changeIssue.getProject().getUuid()).isEqualTo(project.getUuid());
assertThat(changeIssue.getProject().getKey()).isEqualTo(project.getKey());
assertThat(changeIssue.getProject().getProjectName()).isEqualTo(project.getName());
assertThat(changeIssue.getProject().getBranchName()).contains(branchName);
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.
the class ChangesOnMyIssuesEmailTemplateTest method format_set_html_message_with_issues_grouped_by_status_closed_or_any_other_when_change_from_analysis.
@Test
public void format_set_html_message_with_issues_grouped_by_status_closed_or_any_other_when_change_from_analysis() {
Project project = newProject("foo");
Rule rule = newRandomNotAHotspotRule("bar");
Set<ChangedIssue> changedIssues = Arrays.stream(ISSUE_STATUSES).map(status -> newChangedIssue(status + "", status, project, rule)).collect(toSet());
AnalysisChange analysisChange = newAnalysisChange();
EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues));
HtmlListAssert htmlListAssert = HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph("Closed issue:").withoutLink().hasList("Rule " + rule.getName() + " - See the single issue").withLinkOn("See the single issue").hasParagraph("Open issues:").withoutLink().hasList("Rule " + rule.getName() + " - See all " + (ISSUE_STATUSES.length - 1) + " issues").withLinkOn("See all " + (ISSUE_STATUSES.length - 1) + " issues");
verifyEnd(htmlListAssert);
}
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_when_analysis_change.
@Test
public void formats_returns_html_message_with_rules_ordered_by_name_when_analysis_change() {
Project project = newProject("1");
Rule rule1 = newRandomNotAHotspotRule("1");
Rule rule2 = newRandomNotAHotspotRule("a");
Rule rule3 = newRandomNotAHotspotRule("b");
Rule rule4 = newRandomNotAHotspotRule("X");
String host = randomAlphabetic(15);
String issueStatus = randomValidStatus();
List<ChangedIssue> changedIssues = Stream.of(rule1, rule2, rule3, rule4).map(rule -> newChangedIssue("issue_" + rule.getName(), issueStatus, project, rule)).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().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").hasParagraph().hasParagraph().noMoreBlock();
}
Aggregations