Search in sources :

Example 1 with Tracker

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);
}
Also used : IntStream(java.util.stream.IntStream) Component(org.sonar.ce.task.projectanalysis.component.Component) NonClosedTracking(org.sonar.core.issue.tracking.NonClosedTracking) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DefaultIssue(org.sonar.core.issue.DefaultIssue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Tracking(org.sonar.core.issue.tracking.Tracking) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) AnalysisMetadataHolder(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder) Input(org.sonar.core.issue.tracking.Input) Mockito.verify(org.mockito.Mockito.verify) Issue(org.sonar.api.issue.Issue) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Tracker(org.sonar.core.issue.tracking.Tracker) Collections(java.util.Collections) Collectors.toSet(java.util.stream.Collectors.toSet) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) ArrayList(java.util.ArrayList) DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 2 with 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));
}
Also used : Tracker(org.sonar.core.issue.tracking.Tracker) DbClient(org.sonar.db.DbClient) CommonRuleEngineImpl(org.sonar.ce.task.projectanalysis.issue.commonrule.CommonRuleEngineImpl) IssueFieldsSetter(org.sonar.server.issue.IssueFieldsSetter) ReportModulesPath(org.sonar.ce.task.projectanalysis.component.ReportModulesPath) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Before(org.junit.Before)

Aggregations

Component (org.sonar.ce.task.projectanalysis.component.Component)2 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)2 DefaultIssue (org.sonar.core.issue.DefaultIssue)2 Tracker (org.sonar.core.issue.tracking.Tracker)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 Random (java.util.Random)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 Mockito.when (org.mockito.Mockito.when)1 Issue (org.sonar.api.issue.Issue)1