Search in sources :

Example 16 with FileAttributes

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

the class NewMaintainabilityMeasuresVisitorTest method setupOneFileAloneInAProject.

private void setupOneFileAloneInAProject(int newDebt, Flag isUnitTest, Flag withNclocLines, Flag withNewLines) {
    checkArgument(isUnitTest == Flag.UT_FILE || isUnitTest == Flag.SRC_FILE);
    checkArgument(withNclocLines == Flag.WITH_NCLOC || withNclocLines == Flag.NO_NCLOC || withNclocLines == Flag.MISSING_MEASURE_NCLOC);
    checkArgument(withNewLines == Flag.WITH_NEW_LINES || withNewLines == Flag.NO_NEW_LINES);
    Component file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(isUnitTest == Flag.UT_FILE, LANGUAGE_1_KEY, 1)).build();
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(file).build());
    Measure newDebtMeasure = createNewDebtMeasure(newDebt);
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
    if (withNclocLines == Flag.WITH_NCLOC) {
        // 4 lines file, only first one is not ncloc
        measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    } else if (withNclocLines == Flag.NO_NCLOC) {
        // 4 lines file, none of which is ncloc
        measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNoNclocDataMeasure(4));
    }
    if (withNewLines == Flag.WITH_NEW_LINES) {
        // 2 last lines are new
        setNewLines(file, 3, 4);
    }
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes)

Example 17 with FileAttributes

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

the class NewCoverageMeasuresStepTest method no_measures_for_FILE_component_without_code.

@Test
public void no_measures_for_FILE_component_without_code() {
    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, null, 1)).build());
    underTest.execute(new TestComputationStepContext());
    assertThat(measureRepository.isEmpty()).isTrue();
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 18 with FileAttributes

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

the class IntegrateCrossProjectDuplicationsTest method add_duplication_for_java_even_when_no_token.

@Test
public void add_duplication_for_java_even_when_no_token() {
    Component javaFile = builder(FILE, 1).setKey(ORIGIN_FILE_KEY).setFileAttributes(new FileAttributes(false, "java", 10)).build();
    Collection<Block> originBlocks = singletonList(// This block contains 0 token
    new Block.Builder().setResourceId(ORIGIN_FILE_KEY).setBlockHash(new ByteArray("a8998353e96320ec")).setIndexInFile(0).setLines(30, 45).setUnit(0, 0).build());
    Collection<Block> duplicatedBlocks = singletonList(new Block.Builder().setResourceId(OTHER_FILE_KEY).setBlockHash(new ByteArray("a8998353e96320ec")).setIndexInFile(0).setLines(40, 55).build());
    underTest.computeCpd(javaFile, originBlocks, duplicatedBlocks);
    assertThat(duplicationRepository.getDuplications(ORIGIN_FILE)).containsExactly(crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55)));
}
Also used : Block(org.sonar.duplications.block.Block) ByteArray(org.sonar.duplications.block.ByteArray) Component(org.sonar.ce.task.projectanalysis.component.Component) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 19 with FileAttributes

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

the class ReportPersistComponentsStepTest method persist_unit_test.

@Test
public void persist_unit_test() {
    ComponentDto projectDto = prepareProject();
    treeRootHolder.setRoot(asTreeRoot(projectDto).addChildren(builder(DIRECTORY, 2).setUuid("CDEF").setKey(PROJECT_KEY + ":src/test/java/dir").setName("src/test/java/dir").addChildren(builder(FILE, 3).setUuid("DEFG").setKey(PROJECT_KEY + ":src/test/java/dir/FooTest.java").setName("src/test/java/dir/FooTest.java").setShortName("FooTest.java").setFileAttributes(new FileAttributes(true, null, 1)).build()).build()).build());
    underTest.execute(new TestComputationStepContext());
    ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/test/java/dir/FooTest.java").get();
    assertThat(file.name()).isEqualTo("FooTest.java");
    assertThat(file.longName()).isEqualTo("src/test/java/dir/FooTest.java");
    assertThat(file.path()).isEqualTo("src/test/java/dir/FooTest.java");
    assertThat(file.qualifier()).isEqualTo("UTS");
    assertThat(file.scope()).isEqualTo("FIL");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 20 with FileAttributes

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

the class ReportPersistComponentsStepTest method update_module_to_directory_change_scope.

@Test
public void update_module_to_directory_change_scope() {
    ComponentDto project = prepareProject();
    ComponentDto module = ComponentTesting.newModuleDto(project).setUuid("CDEF").setDbKey("MODULE_KEY").setPath("module");
    dbClient.componentDao().insert(db.getSession(), module);
    db.getSession().commit();
    assertThat(dbClient.componentDao().selectByUuid(db.getSession(), "CDEF").get().scope()).isEqualTo("PRJ");
    treeRootHolder.setRoot(asTreeRoot(project).addChildren(builder(DIRECTORY, 2).setUuid("CDEF").setKey(PROJECT_KEY + ":module").setName("module").addChildren(builder(FILE, 3).setUuid("HIJK").setKey(PROJECT_KEY + ":module/FooTest.java").setName("module/FooTest.java").setShortName("FooTest.java").setFileAttributes(new FileAttributes(false, null, 1)).build()).build()).build());
    underTest.execute(new TestComputationStepContext());
    // commit the functional transaction
    dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
    db.commit();
    assertThat(dbClient.componentDao().selectByUuid(db.getSession(), "CDEF").get().scope()).isEqualTo("DIR");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Aggregations

FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)20 Test (org.junit.Test)17 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)12 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)8 Component (org.sonar.ce.task.projectanalysis.component.Component)6 ComponentDto (org.sonar.db.component.ComponentDto)5 Measure (org.sonar.ce.task.projectanalysis.measure.Measure)3 DefaultIssue (org.sonar.core.issue.DefaultIssue)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Block (org.sonar.duplications.block.Block)1 ByteArray (org.sonar.duplications.block.ByteArray)1