use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class TrackerExecutionTest method track_does_not_track_nonClosed_issues_if_tracking_returns_incomplete_but_this_is_first_analysis.
@Test
public void track_does_not_track_nonClosed_issues_if_tracking_returns_incomplete_but_this_is_first_analysis() {
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(false);
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true);
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 CommonRuleEngineImplTest method do_not_process_files_with_unknown_language.
@Test
public void do_not_process_files_with_unknown_language() {
ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, null, 1)).build();
Collection<DefaultIssue> issues = underTest.process(file);
assertThat(issues).isEmpty();
verifyZeroInteractions(rule1, rule2);
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class CommonRuleEngineImplTest method process_files_with_known_language.
@Test
public void process_files_with_known_language() {
ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, "java", 1)).build();
DefaultIssue issue = new DefaultIssue();
when(rule1.processFile(file, "java")).thenReturn(issue);
when(rule2.processFile(file, "java")).thenReturn(null);
Collection<DefaultIssue> issues = underTest.process(file);
assertThat(issues).containsOnly(issue);
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_creates_AnalysisChange_with_analysis_date.
@Test
public void newIssuesChangesNotification_creates_AnalysisChange_with_analysis_date() {
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();
long analysisDate = new Random().nextLong();
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(ImmutableSet.of(issue), assigneesByUuid);
assertThat(notification).isSameAs(expected);
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(1);
assertThat(builder.getChange()).isInstanceOf(AnalysisChange.class).extracting(IssuesChangesNotificationBuilder.Change::getDate).isEqualTo(analysisDate);
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class LastCommitVisitorTest method aggregate_date_of_last_commit_to_directories_and_project.
@Test
public void aggregate_date_of_last_commit_to_directories_and_project() {
final long FILE_1_DATE = 1_100_000_000_000L;
// FILE_2 is the most recent file in DIR_1
final long FILE_2_DATE = 1_200_000_000_000L;
// FILE_3 is the most recent file in the project
final long FILE_3_DATE = 1_300_000_000_000L;
// simulate the output of visitFile()
LastCommitVisitor visitor = new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository) {
@Override
public void visitFile(Component file, Path<LastCommit> path) {
long fileDate;
switch(file.getReportAttributes().getRef()) {
case FILE_1_REF:
fileDate = FILE_1_DATE;
break;
case FILE_2_REF:
fileDate = FILE_2_DATE;
break;
case FILE_3_REF:
fileDate = FILE_3_DATE;
break;
default:
throw new IllegalArgumentException();
}
path.parent().addDate(fileDate);
}
};
// project with 1 module, 2 directories and 3 files
ReportComponent project = ReportComponent.builder(PROJECT, PROJECT_REF).addChildren(ReportComponent.builder(DIRECTORY, DIR_REF).addChildren(ReportComponent.builder(DIRECTORY, DIR_1_REF).addChildren(createFileComponent(FILE_1_REF), createFileComponent(FILE_2_REF)).build(), ReportComponent.builder(DIRECTORY, DIR_2_REF).addChildren(createFileComponent(FILE_3_REF)).build()).build()).build();
treeRootHolder.setRoot(project);
VisitorsCrawler underTest = new VisitorsCrawler(Lists.newArrayList(visitor));
underTest.visit(project);
assertDate(DIR_1_REF, FILE_2_DATE);
assertDate(DIR_2_REF, FILE_3_DATE);
assertDate(DIR_REF, FILE_3_DATE);
// project
assertDate(PROJECT_REF, FILE_3_DATE);
}
Aggregations