use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class LoadDuplicationsFromReportStepTest method loads_multiple_duplications_with_multiple_duplicates.
@Test
public void loads_multiple_duplications_with_multiple_duplicates() {
reportReader.putDuplications(FILE_2_REF, createDuplication(singleLineTextRange(LINE), createInnerDuplicate(LINE + 1), createInnerDuplicate(LINE + 2), createInProjectDuplicate(FILE_1_REF, LINE), createInProjectDuplicate(FILE_1_REF, LINE + 10)), createDuplication(singleLineTextRange(OTHER_LINE), createInProjectDuplicate(FILE_1_REF, OTHER_LINE)), createDuplication(singleLineTextRange(OTHER_LINE + 80), createInnerDuplicate(LINE), createInnerDuplicate(LINE + 10)));
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
Component file1Component = treeRootHolder.getComponentByRef(FILE_1_REF);
assertThat(duplicationRepository.getDuplications(FILE_2_REF)).containsOnly(duplication(singleLineDetailedTextBlock(1, LINE), new InnerDuplicate(singleLineTextBlock(LINE + 1)), new InnerDuplicate(singleLineTextBlock(LINE + 2)), new InProjectDuplicate(file1Component, singleLineTextBlock(LINE)), new InProjectDuplicate(file1Component, singleLineTextBlock(LINE + 10))), duplication(singleLineDetailedTextBlock(2, OTHER_LINE), new InProjectDuplicate(file1Component, singleLineTextBlock(OTHER_LINE))), duplication(singleLineDetailedTextBlock(3, OTHER_LINE + 80), new InnerDuplicate(singleLineTextBlock(LINE)), new InnerDuplicate(singleLineTextBlock(LINE + 10))));
assertNbOfDuplications(context, 3);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class BuildComponentTreeStepTest method verify_tree_is_correctly_built_in_prs.
@Test
public void verify_tree_is_correctly_built_in_prs() {
setAnalysisMetadataHolder(true);
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF, FILE_2_REF, FILE_3_REF, UNCHANGED_FILE_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));
reportReader.putComponent(unchangedComponentWithPath(UNCHANGED_FILE_REF, FILE, REPORT_UNCHANGED_FILE_PATH));
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
// modified root
Component mRoot = treeRootHolder.getRoot();
verifyComponent(mRoot, Component.Type.PROJECT, ROOT_REF, 1);
Component mDir = mRoot.getChildren().get(0);
assertThat(mDir.getName()).isEqualTo("src/main/java");
verifyComponent(mDir, Component.Type.DIRECTORY, null, 2);
Component mDir1 = mDir.getChildren().get(0);
assertThat(mDir1.getName()).isEqualTo("src/main/java/dir1");
verifyComponent(mDir1, Component.Type.DIRECTORY, null, 1);
verifyComponent(mDir1.getChildren().get(0), Component.Type.FILE, FILE_1_REF, 0);
Component mDir2 = mDir.getChildren().get(1);
assertThat(mDir2.getName()).isEqualTo("src/main/java/dir2");
verifyComponent(mDir2, Component.Type.DIRECTORY, null, 2);
verifyComponent(mDir2.getChildren().get(0), Component.Type.FILE, FILE_2_REF, 0);
verifyComponent(mDir2.getChildren().get(1), Component.Type.FILE, FILE_3_REF, 0);
// root
Component root = treeRootHolder.getReportTreeRoot();
verifyComponent(root, Component.Type.PROJECT, ROOT_REF, 1);
Component dir = root.getChildren().get(0);
assertThat(dir.getName()).isEqualTo("src/main");
verifyComponent(dir, Component.Type.DIRECTORY, null, 2);
Component dir1 = dir.getChildren().get(0);
assertThat(dir1.getName()).isEqualTo("src/main/java");
verifyComponent(dir1, Component.Type.DIRECTORY, null, 2);
verifyComponent(dir1.getChildren().get(0), Component.Type.DIRECTORY, null, 1);
verifyComponent(dir1.getChildren().get(1), Component.Type.DIRECTORY, null, 2);
Component dir2 = dir1.getChildren().get(0);
assertThat(dir2.getName()).isEqualTo("src/main/java/dir1");
verifyComponent(dir2, Component.Type.DIRECTORY, null, 1);
verifyComponent(dir2.getChildren().get(0), Component.Type.FILE, FILE_1_REF, 0);
Component dir3 = dir1.getChildren().get(1);
assertThat(dir3.getName()).isEqualTo("src/main/java/dir2");
verifyComponent(dir3, Component.Type.DIRECTORY, null, 2);
verifyComponent(dir3.getChildren().get(0), Component.Type.FILE, FILE_2_REF, 0);
verifyComponent(dir3.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 verify_tree_is_correctly_built_in_prs_with_repeated_names.
/**
* SONAR-13262
*/
@Test
public void verify_tree_is_correctly_built_in_prs_with_repeated_names() {
setAnalysisMetadataHolder(true);
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_PROJECT_KEY + "/file.js"));
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
// modified root
Component mRoot = treeRootHolder.getRoot();
verifyComponent(mRoot, Component.Type.PROJECT, ROOT_REF, 1);
Component dir = mRoot.getChildren().get(0);
assertThat(dir.getName()).isEqualTo(REPORT_PROJECT_KEY);
assertThat(dir.getShortName()).isEqualTo(REPORT_PROJECT_KEY);
verifyComponent(dir, Component.Type.DIRECTORY, null, 1);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class SourceLinesHashImplTest method should_generate_correct_version_of_line_hashes.
@Test
public void should_generate_correct_version_of_line_hashes() {
Component component = createComponent(1);
underTest.getLineHashesMatchingDBVersion(component);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class SignificantCodeRepositoryTest method translate_offset_for_each_line.
@Test
public void translate_offset_for_each_line() {
Component component = createComponent(1);
List<ScannerReport.LineSgnificantCode> significantCode = new ArrayList<>();
significantCode.add(createLineSignificantCode(1, 1, 2));
reportReader.putSignificantCode(component.getReportAttributes().getRef(), significantCode);
assertThat(underTest.getRangesPerLine(component)).isNotEmpty();
LineRange[] lines = underTest.getRangesPerLine(component).get();
assertThat(lines).hasSize(1);
assertThat(lines[0].startOffset()).isOne();
assertThat(lines[0].endOffset()).isEqualTo(2);
}
Aggregations