Search in sources :

Example 11 with Component

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

Example 12 with Component

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

Example 13 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.

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

Example 14 with Component

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

Example 15 with Component

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

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