use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class ClosedIssuesInputFactoryTest method underTest_returns_inputFactory_loading_closed_issues_only_when_getIssues_is_called.
@Test
public void underTest_returns_inputFactory_loading_closed_issues_only_when_getIssues_is_called() {
String componentUuid = randomAlphanumeric(12);
ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).setUuid(componentUuid).build();
when(movedFilesRepository.getOriginalFile(component)).thenReturn(Optional.empty());
Input<DefaultIssue> input = underTest.create(component);
verifyZeroInteractions(dbClient, issuesLoader);
List<DefaultIssue> issues = ImmutableList.of(new DefaultIssue(), new DefaultIssue());
when(issuesLoader.loadClosedIssues(componentUuid)).thenReturn(issues);
assertThat(input.getIssues()).isSameAs(issues);
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class QualityGateMeasuresStepTest method no_measure_if_tree_has_no_project.
@Test
public void no_measure_if_tree_has_no_project() {
ReportComponent notAProjectComponent = ReportComponent.builder(Component.Type.DIRECTORY, 1).build();
treeRootHolder.setRoot(notAProjectComponent);
underTest.execute(new TestComputationStepContext());
measureRepository.getAddedRawMeasures(1).isEmpty();
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class TrackerExecutionTest method track_loadChanges_on_matched_closed_issues.
@Test
public void track_loadChanges_on_matched_closed_issues() {
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);
Set<DefaultIssue> mappedClosedIssues = IntStream.range(1, 2 + new Random().nextInt(2)).mapToObj(i -> new DefaultIssue().setKey("closed" + i).setStatus(Issue.STATUS_CLOSED)).collect(toSet());
ArrayList<DefaultIssue> mappedBaseIssues = new ArrayList<>(mappedClosedIssues);
Issue.STATUSES.stream().filter(t -> !Issue.STATUS_CLOSED.equals(t)).forEach(s -> mappedBaseIssues.add(new DefaultIssue().setKey(s).setStatus(s)));
Collections.shuffle(mappedBaseIssues);
when(closedTracking.getMatchedRaws()).thenReturn(mappedBaseIssues.stream().collect(uniqueIndex(i -> new DefaultIssue().setKey("raw_for_" + i.key()), i -> i)));
Tracking<DefaultIssue, DefaultIssue> tracking = underTest.track(component, rawInput);
assertThat(tracking).isSameAs(closedTracking);
verify(tracker).trackNonClosed(rawInput, openIssuesInput);
verify(tracker).trackClosed(nonClosedTracking, closedIssuesInput);
verify(componentIssuesLoader).loadLatestDiffChangesForReopeningOfClosedIssues(mappedClosedIssues);
verifyNoMoreInteractions(tracker);
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class ProjectTrackerBaseLazyInputTest method prepare.
@Before
public void prepare() {
rule = dbTester.rules().insert();
ruleRepositoryRule.add(rule.getKey());
rootProjectDto = dbTester.components().insertPublicProject();
ReportComponent rootProject = ReportComponent.builder(Component.Type.FILE, 1).setKey(rootProjectDto.getDbKey()).setUuid(rootProjectDto.uuid()).build();
reportModulesPath = mock(ReportModulesPath.class);
underTest = new ProjectTrackerBaseLazyInput(analysisMetadataHolder, mock(ComponentsWithUnprocessedIssues.class), dbClient, new IssueFieldsSetter(), issuesLoader, reportModulesPath, rootProject);
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent 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();
}
Aggregations