use of org.sonar.ce.task.projectanalysis.component.Component 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);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class SourceLinesDiffImplTest method all_file_is_modified_if_no_source_in_db.
@Test
public void all_file_is_modified_if_no_source_in_db() {
periodHolder.setPeriod(null);
Component component = fileComponent(FILE_REF);
setLineHashesInReport(component, CONTENT);
assertThat(underTest.computeMatchingLines(component)).containsExactly(0, 0, 0, 0, 0, 0, 0);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class BuildComponentTreeStepTest method verify_tree_is_correctly_built.
@Test
public void verify_tree_is_correctly_built() {
setAnalysisMetadataHolder();
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF, FILE_2_REF, FILE_3_REF));
reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
reportReader.putComponent(componentWithPath(FILE_2_REF, FILE, REPORT_FILE_PATH_2));
reportReader.putComponent(componentWithPath(FILE_3_REF, FILE, REPORT_FILE_PATH_3));
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
Component root = treeRootHolder.getRoot();
assertThat(root).isNotNull();
verifyComponent(root, Component.Type.PROJECT, ROOT_REF, 1);
Component dir = root.getChildren().iterator().next();
verifyComponent(dir, Component.Type.DIRECTORY, null, 2);
Component dir1 = dir.getChildren().get(0);
verifyComponent(dir1, Component.Type.DIRECTORY, null, 1);
verifyComponent(dir1.getChildren().get(0), Component.Type.FILE, FILE_1_REF, 0);
Component dir2 = dir.getChildren().get(1);
verifyComponent(dir2, Component.Type.DIRECTORY, null, 2);
verifyComponent(dir2.getChildren().get(0), Component.Type.FILE, FILE_2_REF, 0);
verifyComponent(dir2.getChildren().get(1), Component.Type.FILE, FILE_3_REF, 0);
context.getStatistics().assertValue("components", 7);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class BuildComponentTreeStepTest method verifyComponentByKey.
private void verifyComponentByKey(String publicKey, String key, String shortName, @Nullable String uuid) {
Map<String, Component> componentsByKey = indexAllComponentsInTreeByKey(treeRootHolder.getRoot());
Component component = componentsByKey.get(publicKey);
assertThat(component.getDbKey()).isEqualTo(key);
assertThat(component.getReportAttributes().getRef()).isNull();
assertThat(component.getKey()).isEqualTo(publicKey);
assertThat(component.getShortName()).isEqualTo(shortName);
if (uuid != null) {
assertThat(component.getUuid()).isEqualTo(uuid);
} else {
assertThat(component.getUuid()).isNotNull();
}
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class BuildComponentTreeStepTest method verifyComponentByRef.
private void verifyComponentByRef(int ref, String key, String publicKey, String shortName, @Nullable String uuid) {
Map<Integer, Component> componentsByRef = indexAllComponentsInTreeByRef(treeRootHolder.getRoot());
Component component = componentsByRef.get(ref);
assertThat(component.getDbKey()).isEqualTo(key);
assertThat(component.getKey()).isEqualTo(publicKey);
assertThat(component.getShortName()).isEqualTo(shortName);
if (uuid != null) {
assertThat(component.getUuid()).isEqualTo(uuid);
} else {
assertThat(component.getUuid()).isNotNull();
}
}
Aggregations