use of org.sonar.core.issue.tracking.Tracker 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.core.issue.tracking.Tracker in project sonarqube by SonarSource.
the class IntegrateIssuesVisitorTest method setUp.
@Before
public void setUp() throws Exception {
IssueVisitors issueVisitors = new IssueVisitors(new IssueVisitor[] { issueVisitor });
defaultIssueCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
when(movedFilesRepository.getOriginalFile(any(Component.class))).thenReturn(Optional.empty());
DbClient dbClient = dbTester.getDbClient();
TrackerRawInputFactory rawInputFactory = new TrackerRawInputFactory(treeRootHolder, reportReader, sourceLinesHash, new CommonRuleEngineImpl(), issueFilter, ruleRepositoryRule, activeRulesHolder);
TrackerBaseInputFactory baseInputFactory = new TrackerBaseInputFactory(issuesLoader, dbClient, movedFilesRepository, mock(ReportModulesPath.class), analysisMetadataHolder, new IssueFieldsSetter(), mock(ComponentsWithUnprocessedIssues.class));
TrackerTargetBranchInputFactory targetInputFactory = new TrackerTargetBranchInputFactory(issuesLoader, targetBranchComponentUuids, dbClient);
TrackerReferenceBranchInputFactory mergeInputFactory = new TrackerReferenceBranchInputFactory(issuesLoader, mergeBranchComponentsUuids, dbClient);
ClosedIssuesInputFactory closedIssuesInputFactory = new ClosedIssuesInputFactory(issuesLoader, dbClient, movedFilesRepository);
tracker = new TrackerExecution(baseInputFactory, closedIssuesInputFactory, new Tracker<>(), issuesLoader, analysisMetadataHolder);
mergeBranchTracker = new ReferenceBranchTrackerExecution(mergeInputFactory, new Tracker<>());
prBranchTracker = new PullRequestTrackerExecution(baseInputFactory, targetInputFactory, new Tracker<>(), newLinesRepository);
trackingDelegator = new IssueTrackingDelegator(prBranchTracker, mergeBranchTracker, tracker, analysisMetadataHolder);
treeRootHolder.setRoot(PROJECT);
protoIssueCache = new ProtoIssueCache(temp.newFile(), System2.INSTANCE);
when(issueFilter.accept(any(DefaultIssue.class), eq(FILE))).thenReturn(true);
when(issueChangeContext.date()).thenReturn(new Date());
underTest = new IntegrateIssuesVisitor(protoIssueCache, rawInputFactory, issueLifecycle, issueVisitors, trackingDelegator, issueStatusCopier, referenceBranchComponentUuids, mock(PullRequestSourceBranchMerger.class));
}
Aggregations