use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class FileSourceDataWarningsTest method create_symbol_warning_when_one_file_HIGHLIGHT_read_error.
@Test
public void create_symbol_warning_when_one_file_HIGHLIGHT_read_error() {
ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setUuid("uuid").setName(path).build();
LineReader.ReadError readError = new LineReader.ReadError(SYMBOLS, line);
when(system2.now()).thenReturn(timeStamp);
underTest.addWarning(file, readError);
verifyZeroInteractions(taskMessages);
underTest.commitWarnings();
verify(taskMessages, times(1)).add(new CeTaskMessages.Message("Inconsistent symbol data detected on file '" + path + "'. " + "File source may have been modified while analysis was running.", timeStamp));
}
use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class FileSourceDataWarningsTest method creates_no_warning_when_read_error_for_anything_but_highlighting_and_symbols.
@Test
@UseDataProvider("anyDataButHighlightAndSymbols")
public void creates_no_warning_when_read_error_for_anything_but_highlighting_and_symbols(LineReader.Data data) {
ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setUuid("uuid").setName(path).build();
LineReader.ReadError readError = new LineReader.ReadError(data, line);
when(system2.now()).thenReturn(timeStamp);
underTest.addWarning(file, readError);
verifyZeroInteractions(taskMessages);
underTest.commitWarnings();
verifyZeroInteractions(taskMessages);
}
use of org.sonar.ce.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(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(), builder(DIRECTORY, 121).addChildren(createFileComponent(LANGUAGE_KEY_1, 1211)).build(), builder(DIRECTORY, 122).build()).build();
treeRootHolder.setRoot(root);
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(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(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));
verifyAddedRawMeasure(1, DEVELOPMENT_COST_KEY, Long.toString(ncloc1112 * DEV_COST_LANGUAGE_2 + ncloc1113 * DEV_COST_LANGUAGE_1 + nclocValue1121 * DEV_COST_LANGUAGE_2 + ncloc1211 * DEV_COST_LANGUAGE_1));
}
use of org.sonar.ce.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(measureRepository.getRawMeasures(root).entrySet().stream().map(e -> entryOf(e.getKey(), e.getValue()))).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.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.
the class AverageFormulaExecutionTest method add_measures.
@Test
public void add_measures() {
ReportComponent project = builder(PROJECT, 1).addChildren(builder(DIRECTORY, 111).addChildren(builder(Component.Type.FILE, 1111).build(), builder(Component.Type.FILE, 1112).build()).build(), builder(DIRECTORY, 121).addChildren(builder(Component.Type.FILE, 1211).build()).build()).build();
treeRootHolder.setRoot(project);
measureRepository.addRawMeasure(1111, COMPLEXITY_IN_FUNCTIONS_KEY, newMeasureBuilder().create(5));
measureRepository.addRawMeasure(1111, FUNCTIONS_KEY, newMeasureBuilder().create(2));
measureRepository.addRawMeasure(1112, COMPLEXITY_IN_FUNCTIONS_KEY, newMeasureBuilder().create(1));
measureRepository.addRawMeasure(1112, FUNCTIONS_KEY, newMeasureBuilder().create(1));
measureRepository.addRawMeasure(1211, COMPLEXITY_IN_FUNCTIONS_KEY, newMeasureBuilder().create(9));
measureRepository.addRawMeasure(1211, FUNCTIONS_KEY, newMeasureBuilder().create(2));
new PathAwareCrawler<>(underTest).visit(project);
assertThat(toEntries(measureRepository.getAddedRawMeasures(1))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(3d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(111))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(2d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(1111))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(2.5d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(1112))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(1d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(121))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(4.5d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(1211))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(4.5d, 1)));
}
Aggregations