use of org.sonar.server.computation.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class LastCommitVisitorTest method date_is_not_computed_on_file_if_blame_is_not_in_scm_repo.
@Test
public void date_is_not_computed_on_file_if_blame_is_not_in_scm_repo() throws Exception {
VisitorsCrawler underTest = new VisitorsCrawler(Lists.<ComponentVisitor>newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
ReportComponent file = createFileComponent(FILE_1_REF);
treeRootHolder.setRoot(file);
underTest.visit(file);
Optional<Measure> measure = measureRepository.getAddedRawMeasure(FILE_1_REF, LAST_COMMIT_DATE_KEY);
assertThat(measure.isPresent()).isFalse();
}
use of org.sonar.server.computation.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(MODULE, MODULE_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.<ComponentVisitor>newArrayList(visitor));
underTest.visit(project);
assertDate(DIR_1_REF, FILE_2_DATE);
assertDate(DIR_2_REF, FILE_3_DATE);
// module = most recent commit date of directories
assertDate(MODULE_REF, FILE_3_DATE);
// project
assertDate(PROJECT_REF, FILE_3_DATE);
}
use of org.sonar.server.computation.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class MaintainabilityMeasuresVisitorTest method compute_development_cost.
@Test
public void compute_development_cost() {
ReportComponent root = builder(PROJECT, 1).addChildren(builder(MODULE, 11).addChildren(builder(DIRECTORY, 111).addChildren(createFileComponent(LANGUAGE_KEY_1, 1111), createFileComponent(LANGUAGE_KEY_2, 1112), // Unit test should not be ignored
builder(FILE, 1113).setFileAttributes(new FileAttributes(true, LANGUAGE_KEY_1, 1)).build()).build(), builder(DIRECTORY, 112).addChildren(createFileComponent(LANGUAGE_KEY_2, 1121)).build()).build(), builder(MODULE, 12).addChildren(builder(DIRECTORY, 121).addChildren(createFileComponent(LANGUAGE_KEY_1, 1211)).build(), builder(DIRECTORY, 122).build()).build(), builder(MODULE, 13).build()).build();
treeRootHolder.setRoot(root);
int ncloc1111 = 10;
addRawMeasure(NCLOC_KEY, 1111, ncloc1111);
int ncloc1112 = 12;
addRawMeasure(NCLOC_KEY, 1112, ncloc1112);
int ncloc1113 = 15;
addRawMeasure(NCLOC_KEY, 1113, ncloc1113);
int nclocValue1121 = 30;
addRawMeasure(NCLOC_KEY, 1121, nclocValue1121);
int ncloc1211 = 20;
addRawMeasure(NCLOC_KEY, 1211, ncloc1211);
underTest.visit(root);
// verify measures on files
verifyAddedRawMeasure(1111, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(1112, DEVELOPMENT_COST_KEY, Long.toString(ncloc1112 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(1113, DEVELOPMENT_COST_KEY, Long.toString(ncloc1113 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(1121, DEVELOPMENT_COST_KEY, Long.toString(nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(1211, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
// directory has no children => no file => 0 everywhere and A rating
verifyAddedRawMeasure(122, DEVELOPMENT_COST_KEY, "0");
// directory has children => dev cost is aggregated
verifyAddedRawMeasure(111, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1 + ncloc1112 * DEV_COST_LANGUAGE_2 + ncloc1113 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(112, DEVELOPMENT_COST_KEY, Long.toString(nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(121, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
// just for fun, we didn't define any debt on module => they must all have rating A
verifyAddedRawMeasure(11, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1 + ncloc1112 * DEV_COST_LANGUAGE_2 + ncloc1113 * DEV_COST_LANGUAGE_1 + nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(12, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(13, DEVELOPMENT_COST_KEY, "0");
verifyAddedRawMeasure(1, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1 + ncloc1112 * DEV_COST_LANGUAGE_2 + ncloc1113 * DEV_COST_LANGUAGE_1 + nclocValue1121 * DEV_COST_LANGUAGE_2 + ncloc1211 * DEV_COST_LANGUAGE_1));
}
use of org.sonar.server.computation.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class MaintainabilityMeasuresVisitorTest method measures_created_for_project_are_all_zero_when_they_have_no_FILE_child.
@Test
public void measures_created_for_project_are_all_zero_when_they_have_no_FILE_child() {
ReportComponent root = builder(PROJECT, 1).build();
treeRootHolder.setRoot(root);
underTest.visit(root);
assertThat(toEntries(measureRepository.getRawMeasures(root))).containsOnly(entryOf(DEVELOPMENT_COST_KEY, newMeasureBuilder().create("0")), entryOf(SQALE_DEBT_RATIO_KEY, newMeasureBuilder().create(0d, 1)), entryOf(SQALE_RATING_KEY, createMaintainabilityRatingMeasure(A)), entryOf(EFFORT_TO_REACH_MAINTAINABILITY_RATING_A_KEY, newMeasureBuilder().create(0L)));
}
use of org.sonar.server.computation.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class ReliabilityAndSecurityRatingMeasuresVisitorTest method measures_created_for_project_are_all_A_when_they_have_no_FILE_child.
@Test
public void measures_created_for_project_are_all_A_when_they_have_no_FILE_child() {
ReportComponent root = builder(PROJECT, 1).build();
treeRootHolder.setRoot(root);
underTest.visit(root);
assertThat(toEntries(measureRepository.getRawMeasures(root))).containsOnly(entryOf(RELIABILITY_RATING_KEY, createRatingMeasure(A)), entryOf(SECURITY_RATING_KEY, createRatingMeasure(A)));
}
Aggregations