use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class NewIssueClassifierTest method isNew_returns_true_for_issue_which_was_new_and_is_still_located_on_changed_lines.
@Test
public void isNew_returns_true_for_issue_which_was_new_and_is_still_located_on_changed_lines() {
periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null));
Component file = mock(Component.class);
DefaultIssue issue = mock(DefaultIssue.class);
when(file.getType()).thenReturn(Component.Type.FILE);
when(file.getUuid()).thenReturn("fileUuid");
when(newLinesRepository.getNewLines(file)).thenReturn(Optional.of(Set.of(2, 3)));
when(issue.getLocations()).thenReturn(DbIssues.Locations.newBuilder().setTextRange(DbCommons.TextRange.newBuilder().setStartLine(2).setStartOffset(1).setEndLine(2).setEndOffset(2).build()).build());
when(issue.isNewCodeReferenceIssue()).thenReturn(true);
assertThat(newIssueClassifier.isNew(file, issue)).isTrue();
assertThat(newIssueClassifier.isOnBranchUsingReferenceBranch()).isTrue();
assertThat(newIssueClassifier.hasAtLeastOneLocationOnChangedLines(file, issue)).isTrue();
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class NewIssueClassifierTest method isNew_returns_false_for_issue_not_located_on_changed_lines.
@Test
public void isNew_returns_false_for_issue_not_located_on_changed_lines() {
periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null));
Component file = mock(Component.class);
DefaultIssue issue = mock(DefaultIssue.class);
when(file.getType()).thenReturn(Component.Type.FILE);
when(file.getUuid()).thenReturn("fileUuid");
when(newLinesRepository.getNewLines(file)).thenReturn(Optional.of(Set.of(2, 3)));
when(issue.getLocations()).thenReturn(DbIssues.Locations.newBuilder().setTextRange(DbCommons.TextRange.newBuilder().setStartLine(10).setStartOffset(1).setEndLine(10).setEndOffset(2).build()).build());
assertThat(newIssueClassifier.isNew(file, issue)).isFalse();
assertThat(newIssueClassifier.isOnBranchUsingReferenceBranch()).isTrue();
assertThat(newIssueClassifier.hasAtLeastOneLocationOnChangedLines(file, issue)).isFalse();
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class NewIssueClassifierTest method isNew_returns_true_for_issue_located_on_changed_lines.
@Test
public void isNew_returns_true_for_issue_located_on_changed_lines() {
periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null));
Component file = mock(Component.class);
DefaultIssue issue = mock(DefaultIssue.class);
when(file.getType()).thenReturn(Component.Type.FILE);
when(file.getUuid()).thenReturn("fileUuid");
when(newLinesRepository.getNewLines(file)).thenReturn(Optional.of(Set.of(2, 3)));
when(issue.getLocations()).thenReturn(DbIssues.Locations.newBuilder().setTextRange(DbCommons.TextRange.newBuilder().setStartLine(2).setStartOffset(1).setEndLine(2).setEndOffset(2).build()).build());
assertThat(newIssueClassifier.isNew(file, issue)).isTrue();
assertThat(newIssueClassifier.isOnBranchUsingReferenceBranch()).isTrue();
assertThat(newIssueClassifier.hasAtLeastOneLocationOnChangedLines(file, issue)).isTrue();
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class TrackerSourceBranchInputFactoryTest method gets_issues_and_hashes_in_matching_component.
@Test
public void gets_issues_and_hashes_in_matching_component() {
DefaultIssue issue1 = new DefaultIssue();
when(sourceBranchComponentUuids.getSourceBranchComponentUuid(COMPONENT_KEY)).thenReturn(COMPONENT_UUID);
when(componentIssuesLoader.loadOpenIssuesWithChanges(COMPONENT_UUID)).thenReturn(Collections.singletonList(issue1));
ComponentDto fileDto = ComponentTesting.newFileDto(ComponentTesting.newPublicProjectDto()).setUuid(COMPONENT_UUID);
db.fileSources().insertFileSource(fileDto, 3);
Component component = mock(Component.class);
when(component.getDbKey()).thenReturn(COMPONENT_KEY);
when(component.getType()).thenReturn(Component.Type.FILE);
Input<DefaultIssue> input = underTest.createForSourceBranch(component);
assertThat(input.getIssues()).containsOnly(issue1);
assertThat(input.getLineHashSequence().length()).isEqualTo(3);
}
use of org.sonar.ce.task.projectanalysis.component.Component 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);
}
Aggregations