use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder 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 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 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 in project sonarqube by SonarSource.
the class NotificationFactory method newIssuesChangesNotification.
public IssuesChangesNotification newIssuesChangesNotification(Set<DefaultIssue> issues, Map<String, UserDto> assigneesByUuid) {
AnalysisChange change = new AnalysisChange(analysisMetadataHolder.getAnalysisDate());
Set<ChangedIssue> changedIssues = issues.stream().map(issue -> new ChangedIssue.Builder(issue.key()).setAssignee(getAssignee(issue.assignee(), assigneesByUuid)).setNewResolution(issue.resolution()).setNewStatus(issue.status()).setRule(getRuleByRuleKey(issue.ruleKey())).setProject(getProject()).build()).collect(MoreCollectors.toSet(issues.size()));
return issuesChangesSerializer.serialize(new IssuesChangesNotificationBuilder(changedIssues, change));
}
use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification_without_resolution.
@Test
public void verify_notification_without_resolution() {
UserDto assignee = db.users().insertUser();
RuleDefinitionDto rule = db.rules().insertIssueRule();
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
DefaultIssue issue = db.issues().insertIssue(rule, project, file, t -> t.setSeverity(MAJOR).setAssigneeUuid(assignee.getUuid())).toDefaultIssue();
UserDto changeAuthor = db.users().insertUser();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssuesChangesNotification issueChangeNotification = notificationArgumentCaptor.getValue();
IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotification);
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changedIssue = builder.getIssues().iterator().next();
assertThat(changedIssue.getKey()).isEqualTo(issue.key());
assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).contains(userOf(assignee));
assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
assertThat(changedIssue.getProject()).isEqualTo(projectOf(project));
assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor)));
}
Aggregations