Search in sources :

Example 6 with FileAttributes

use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class ReportPersistComponentsStepTest method persist_components.

@Test
public void persist_components() {
    Component file = builder(FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").setPath("src/main/java/dir/Foo.java").setFileAttributes(new FileAttributes(false, "java", 1)).build();
    Component directory = builder(DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").setPath("src/main/java/dir").addChildren(file).build();
    Component module = builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY).setPath("module").setName("Module").setDescription("Module description").addChildren(directory).build();
    Component project = builder(PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setName("Project").setDescription("Project description").addChildren(module).build();
    treeRootHolder.setRoot(project);
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(4);
    ComponentDto projectDto = dbClient.componentDao().selectByKey(dbTester.getSession(), PROJECT_KEY).get();
    assertThat(projectDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
    assertThat(projectDto.name()).isEqualTo("Project");
    assertThat(projectDto.description()).isEqualTo("Project description");
    assertThat(projectDto.path()).isNull();
    assertThat(projectDto.uuid()).isEqualTo("ABCD");
    assertThat(projectDto.getUuidPath()).isEqualTo(UUID_PATH_OF_ROOT);
    assertThat(projectDto.moduleUuid()).isNull();
    assertThat(projectDto.moduleUuidPath()).isEqualTo("." + projectDto.uuid() + ".");
    assertThat(projectDto.projectUuid()).isEqualTo(projectDto.uuid());
    assertThat(projectDto.qualifier()).isEqualTo("TRK");
    assertThat(projectDto.scope()).isEqualTo("PRJ");
    assertThat(projectDto.getRootUuid()).isEqualTo("ABCD");
    assertThat(projectDto.getCreatedAt()).isEqualTo(now);
    ComponentDto moduleDto = dbClient.componentDao().selectByKey(dbTester.getSession(), MODULE_KEY).get();
    assertThat(moduleDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
    assertThat(moduleDto.name()).isEqualTo("Module");
    assertThat(moduleDto.description()).isEqualTo("Module description");
    assertThat(moduleDto.path()).isEqualTo("module");
    assertThat(moduleDto.uuid()).isEqualTo("BCDE");
    assertThat(moduleDto.getUuidPath()).isEqualTo(projectDto.getUuidPath() + projectDto.uuid() + UUID_PATH_SEPARATOR);
    assertThat(moduleDto.moduleUuid()).isEqualTo(projectDto.uuid());
    assertThat(moduleDto.moduleUuidPath()).isEqualTo(projectDto.moduleUuidPath() + moduleDto.uuid() + ".");
    assertThat(moduleDto.projectUuid()).isEqualTo(projectDto.uuid());
    assertThat(moduleDto.qualifier()).isEqualTo("BRC");
    assertThat(moduleDto.scope()).isEqualTo("PRJ");
    assertThat(moduleDto.getRootUuid()).isEqualTo(projectDto.uuid());
    assertThat(moduleDto.getCreatedAt()).isEqualTo(now);
    ComponentDto directoryDto = dbClient.componentDao().selectByKey(dbTester.getSession(), "MODULE_KEY:src/main/java/dir").get();
    assertThat(directoryDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
    assertThat(directoryDto.name()).isEqualTo("src/main/java/dir");
    assertThat(directoryDto.description()).isNull();
    assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
    assertThat(directoryDto.uuid()).isEqualTo("CDEF");
    assertThat(directoryDto.getUuidPath()).isEqualTo(moduleDto.getUuidPath() + moduleDto.uuid() + UUID_PATH_SEPARATOR);
    assertThat(directoryDto.moduleUuid()).isEqualTo(moduleDto.uuid());
    assertThat(directoryDto.moduleUuidPath()).isEqualTo(moduleDto.moduleUuidPath());
    assertThat(directoryDto.projectUuid()).isEqualTo(projectDto.uuid());
    assertThat(directoryDto.qualifier()).isEqualTo("DIR");
    assertThat(directoryDto.scope()).isEqualTo("DIR");
    assertThat(directoryDto.getRootUuid()).isEqualTo(moduleDto.uuid());
    assertThat(directoryDto.getCreatedAt()).isEqualTo(now);
    ComponentDto fileDto = dbClient.componentDao().selectByKey(dbTester.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get();
    assertThat(fileDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
    assertThat(fileDto.name()).isEqualTo("Foo.java");
    assertThat(fileDto.description()).isNull();
    assertThat(fileDto.path()).isEqualTo("src/main/java/dir/Foo.java");
    assertThat(fileDto.language()).isEqualTo("java");
    assertThat(fileDto.uuid()).isEqualTo("DEFG");
    assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
    assertThat(fileDto.moduleUuid()).isEqualTo(moduleDto.uuid());
    assertThat(fileDto.moduleUuidPath()).isEqualTo(moduleDto.moduleUuidPath());
    assertThat(fileDto.projectUuid()).isEqualTo(projectDto.uuid());
    assertThat(fileDto.qualifier()).isEqualTo("FIL");
    assertThat(fileDto.scope()).isEqualTo("FIL");
    assertThat(fileDto.getRootUuid()).isEqualTo(moduleDto.uuid());
    assertThat(fileDto.getCreatedAt()).isEqualTo(now);
    assertThat(dbIdsRepository.getComponentId(project)).isEqualTo(projectDto.getId());
    assertThat(dbIdsRepository.getComponentId(module)).isEqualTo(moduleDto.getId());
    assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
    assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.server.computation.task.projectanalysis.component.Component) FileAttributes(org.sonar.server.computation.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 7 with FileAttributes

use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method initBasicReport.

private void initBasicReport(int numberOfLines) {
    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(ReportComponent.builder(Component.Type.MODULE, 2).setUuid("MODULE").setKey("MODULE_KEY").addChildren(ReportComponent.builder(Component.Type.FILE, FILE_REF).setUuid(FILE_UUID).setKey("MODULE_KEY:src/Foo.java").setFileAttributes(new FileAttributes(false, null, numberOfLines)).build()).build()).build());
    reportReader.putComponent(ScannerReport.Component.newBuilder().setRef(1).setType(ComponentType.PROJECT).addChildRef(2).build());
    reportReader.putComponent(ScannerReport.Component.newBuilder().setRef(2).setType(ComponentType.MODULE).addChildRef(FILE_REF).build());
    reportReader.putComponent(ScannerReport.Component.newBuilder().setRef(FILE_REF).setType(ComponentType.FILE).setLines(numberOfLines).build());
    for (int i = 1; i <= numberOfLines; i++) {
        fileSourceRepository.addLine(FILE_REF, "line" + i);
    }
}
Also used : FileAttributes(org.sonar.server.computation.task.projectanalysis.component.FileAttributes)

Example 8 with FileAttributes

use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class CommonRuleEngineImplTest method process_files_with_known_language.

@Test
public void process_files_with_known_language() throws Exception {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, "java", 1)).build();
    DefaultIssue issue = new DefaultIssue();
    when(rule1.processFile(file, "java")).thenReturn(issue);
    when(rule2.processFile(file, "java")).thenReturn(null);
    Collection<DefaultIssue> issues = underTest.process(file);
    assertThat(issues).containsOnly(issue);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.server.computation.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 9 with FileAttributes

use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class NewMaintainabilityMeasuresVisitorTest method file_has_0_new_debt_ratio_if_all_scm_dates_are_before_snapshot_dates.

@Test
public void file_has_0_new_debt_ratio_if_all_scm_dates_are_before_snapshot_dates() {
    setPeriod();
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()).build());
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50));
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_SNAPSHOT_DATE - 100, 4));
    underTest.visit(treeRootHolder.getRoot());
    assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0);
    assertNewDebtRatioValues(ROOT_REF, 0);
}
Also used : FileAttributes(org.sonar.server.computation.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 10 with FileAttributes

use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class NewMaintainabilityMeasuresVisitorTest method compute_new_maintainability_rating_to_A_when_no_debt.

@Test
public void compute_new_maintainability_rating_to_A_when_no_debt() throws Exception {
    setPeriod();
    when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(MODULE, 11).addChildren(builder(DIRECTORY, 111).addChildren(builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()).build()).build()).build());
    underTest.visit(treeRootHolder.getRoot());
    assertNewMaintainability(LANGUAGE_1_FILE_REF, A);
    assertNewMaintainability(111, A);
    assertNewMaintainability(11, A);
    assertNewMaintainability(ROOT_REF, A);
}
Also used : FileAttributes(org.sonar.server.computation.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Aggregations

FileAttributes (org.sonar.server.computation.task.projectanalysis.component.FileAttributes)15 Test (org.junit.Test)12 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)3 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)3 DefaultIssue (org.sonar.core.issue.DefaultIssue)2 ComponentDto (org.sonar.db.component.ComponentDto)2 Component (org.sonar.server.computation.task.projectanalysis.component.Component)2 Before (org.junit.Before)1 System2 (org.sonar.api.utils.System2)1 Block (org.sonar.duplications.block.Block)1 ByteArray (org.sonar.duplications.block.ByteArray)1