use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_maps_all_issues.
@Test
public void newIssuesChangesNotification_maps_all_issues() {
Set<DefaultIssue> issues = IntStream.range(0, 3 + new Random().nextInt(5)).mapToObj(i -> new DefaultIssue().setRuleKey(RuleKey.of("repo_" + i, "rule_" + i)).setKey("issue_key_" + i).setStatus("status_" + i)).collect(Collectors.toSet());
ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
long analysisDate = new Random().nextLong();
issues.stream().map(DefaultIssue::ruleKey).forEach(ruleKey -> ruleRepository.add(ruleKey));
treeRootHolder.setRoot(project);
analysisMetadata.setAnalysisDate(analysisDate);
analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, randomAlphabetic(12)));
IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
IssuesChangesNotification notification = underTest.newIssuesChangesNotification(issues, emptyMap());
assertThat(notification).isSameAs(expected);
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(issues.size());
Map<String, ChangedIssue> changedIssuesByKey = builder.getIssues().stream().collect(uniqueIndex(ChangedIssue::getKey));
issues.forEach(issue -> {
ChangedIssue changedIssue = changedIssuesByKey.get(issue.key());
assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).isEmpty();
assertThat(changedIssue.getRule().getKey()).isEqualTo(issue.ruleKey());
assertThat(changedIssue.getRule().getName()).isEqualTo(ruleRepository.getByKey(issue.ruleKey()).getName());
});
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_creates_rule_from_RuleRepository.
@Test
public void newIssuesChangesNotification_creates_rule_from_RuleRepository() {
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.getRule().getKey()).isEqualTo(ruleKey);
assertThat(changeIssue.getRule().getName()).isEqualTo(ruleRepository.getByKey(ruleKey).getName());
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_fails_with_ISE_if_issue_has_assignee_not_in_assigneesByUuid.
@Test
public void newIssuesChangesNotification_fails_with_ISE_if_issue_has_assignee_not_in_assigneesByUuid() {
RuleKey ruleKey = RuleKey.of("foo", "bar");
String assigneeUuid = randomAlphabetic(40);
DefaultIssue issue = new DefaultIssue().setRuleKey(ruleKey).setKey("issueKey").setStatus(STATUS_OPEN).setAssigneeUuid(assigneeUuid);
Map<String, UserDto> assigneesByUuid = Collections.emptyMap();
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)));
assertThatThrownBy(() -> underTest.newIssuesChangesNotification(ImmutableSet.of(issue), assigneesByUuid)).isInstanceOf(IllegalStateException.class).hasMessage("Can not find DTO for assignee uuid " + assigneeUuid);
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class TrackerExecutionTest method track_tracks_only_nonClosed_issues_if_tracking_returns_complete_from_Tracker.
@Test
public void track_tracks_only_nonClosed_issues_if_tracking_returns_complete_from_Tracker() {
ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).build();
when(baseInputFactory.create(component)).thenReturn(openIssuesInput);
when(closedIssuesInputFactory.create(any())).thenThrow(new IllegalStateException("closedIssuesInputFactory should not be called"));
when(nonClosedTracking.isComplete()).thenReturn(true);
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
when(tracker.trackNonClosed(rawInput, openIssuesInput)).thenReturn(nonClosedTracking);
when(tracker.trackClosed(any(), any())).thenThrow(new IllegalStateException("trackClosed should not be called"));
Tracking<DefaultIssue, DefaultIssue> tracking = underTest.track(component, rawInput);
assertThat(tracking).isSameAs(nonClosedTracking);
verify(tracker).trackNonClosed(rawInput, openIssuesInput);
verifyNoMoreInteractions(tracker);
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class TrackerExecutionTest method track_tracks_nonClosed_issues_and_then_closedOnes_if_tracking_returns_incomplete.
@Test
public void track_tracks_nonClosed_issues_and_then_closedOnes_if_tracking_returns_incomplete() {
ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).build();
when(baseInputFactory.create(component)).thenReturn(openIssuesInput);
when(closedIssuesInputFactory.create(component)).thenReturn(closedIssuesInput);
when(nonClosedTracking.isComplete()).thenReturn(false);
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
when(tracker.trackNonClosed(rawInput, openIssuesInput)).thenReturn(nonClosedTracking);
when(tracker.trackClosed(nonClosedTracking, closedIssuesInput)).thenReturn(closedTracking);
Tracking<DefaultIssue, DefaultIssue> tracking = underTest.track(component, rawInput);
assertThat(tracking).isSameAs(closedTracking);
verify(tracker).trackNonClosed(rawInput, openIssuesInput);
verify(tracker).trackClosed(nonClosedTracking, closedIssuesInput);
verifyNoMoreInteractions(tracker);
}
Aggregations