Search in sources :

Example 76 with Component

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);
}
Also used : InnerDuplicate(org.sonar.ce.task.projectanalysis.duplication.InnerDuplicate) InProjectDuplicate(org.sonar.ce.task.projectanalysis.duplication.InProjectDuplicate) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 77 with Component

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);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 78 with Component

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);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 79 with Component

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);
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 80 with 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);
}
Also used : ArrayList(java.util.ArrayList) Component(org.sonar.ce.task.projectanalysis.component.Component) LineRange(org.sonar.core.hash.LineRange) LineSgnificantCode(org.sonar.scanner.protocol.output.ScannerReport.LineSgnificantCode) Test(org.junit.Test)

Aggregations

Component (org.sonar.ce.task.projectanalysis.component.Component)118 Test (org.junit.Test)82 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)47 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 ComponentDto (org.sonar.db.component.ComponentDto)25 ViewsComponent (org.sonar.ce.task.projectanalysis.component.ViewsComponent)14 DefaultIssue (org.sonar.core.issue.DefaultIssue)14 DbSession (org.sonar.db.DbSession)11 Period (org.sonar.ce.task.projectanalysis.period.Period)8 SnapshotDto (org.sonar.db.component.SnapshotDto)8 FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)6 DbClient (org.sonar.db.DbClient)6 List (java.util.List)5 ComputationStep (org.sonar.ce.task.step.ComputationStep)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 DepthTraversalTypeAwareCrawler (org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 Map (java.util.Map)3