Search in sources :

Example 1 with ReportComponent

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

the class SumFormulaExecutionTest method not_add_measures_when_no_data_on_file.

@Test
public void not_add_measures_when_no_data_on_file() {
    ReportComponent project = builder(PROJECT, 1).addChildren(builder(MODULE, 11).addChildren(builder(DIRECTORY, 111).addChildren(builder(Component.Type.FILE, 1111).build()).build()).build()).build();
    treeRootHolder.setRoot(project);
    new PathAwareCrawler<>(underTest).visit(project);
    assertThat(measureRepository.getAddedRawMeasures(1)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(11)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(111)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
}
Also used : ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 2 with ReportComponent

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

the class AverageFormulaExecutionTest method add_measures.

@Test
public void add_measures() {
    ReportComponent project = builder(PROJECT, 1).addChildren(builder(MODULE, 11).addChildren(builder(DIRECTORY, 111).addChildren(builder(Component.Type.FILE, 1111).build(), builder(Component.Type.FILE, 1112).build()).build()).build(), builder(MODULE, 12).addChildren(builder(DIRECTORY, 121).addChildren(builder(Component.Type.FILE, 1211).build()).build()).build()).build();
    treeRootHolder.setRoot(project);
    measureRepository.addRawMeasure(1111, COMPLEXITY_IN_FUNCTIONS_KEY, newMeasureBuilder().create(5));
    measureRepository.addRawMeasure(1111, FUNCTIONS_KEY, newMeasureBuilder().create(2));
    measureRepository.addRawMeasure(1112, COMPLEXITY_IN_FUNCTIONS_KEY, newMeasureBuilder().create(1));
    measureRepository.addRawMeasure(1112, FUNCTIONS_KEY, newMeasureBuilder().create(1));
    measureRepository.addRawMeasure(1211, COMPLEXITY_IN_FUNCTIONS_KEY, newMeasureBuilder().create(9));
    measureRepository.addRawMeasure(1211, FUNCTIONS_KEY, newMeasureBuilder().create(2));
    new PathAwareCrawler<>(underTest).visit(project);
    assertThat(toEntries(measureRepository.getAddedRawMeasures(1))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(3d, 1)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(11))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(2d, 1)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(111))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(2d, 1)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(1111))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(2.5d, 1)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(1112))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(1d, 1)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(12))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(4.5d, 1)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(121))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(4.5d, 1)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(1211))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(4.5d, 1)));
}
Also used : ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 3 with ReportComponent

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

the class ReportFormulaExecutorComponentVisitorTest method add_measure_even_when_leaf_is_not_FILE.

@Test
public void add_measure_even_when_leaf_is_not_FILE() throws Exception {
    ReportComponent project = ReportComponent.builder(PROJECT, ROOT_REF).addChildren(ReportComponent.builder(MODULE, MODULE_1_REF).addChildren(ReportComponent.builder(DIRECTORY, 111).build()).build()).build();
    treeRootHolder.setRoot(project);
    new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(project);
    assertAddedRawMeasure(MODULE_1_REF, 0);
    assertAddedRawMeasure(DIRECTORY_1_REF, 0);
}
Also used : ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 4 with ReportComponent

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

the class CommonRuleEngineImplTest method do_not_process_files_with_unknown_language.

@Test
public void do_not_process_files_with_unknown_language() throws Exception {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, null, 1)).build();
    Collection<DefaultIssue> issues = underTest.process(file);
    assertThat(issues).isEmpty();
    verifyZeroInteractions(rule1, rule2);
}
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 5 with ReportComponent

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

the class LastCommitVisitorTest method compute_date_of_file_from_scm_repo.

@Test
public void compute_date_of_file_from_scm_repo() throws Exception {
    VisitorsCrawler underTest = new VisitorsCrawler(Lists.<ComponentVisitor>newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
    scmInfoRepository.setScmInfo(FILE_1_REF, Changeset.newChangesetBuilder().setAuthor("john").setDate(1_500_000_000_000L).setRevision("rev-1").build(), Changeset.newChangesetBuilder().setAuthor("tom").setDate(1_600_000_000_000L).setRevision("rev-2").build(), Changeset.newChangesetBuilder().setAuthor("john").setDate(1_500_000_000_000L).setRevision("rev-1").build());
    ReportComponent file = createFileComponent(FILE_1_REF);
    treeRootHolder.setRoot(file);
    underTest.visit(file);
    assertDate(FILE_1_REF, 1_600_000_000_000L);
}
Also used : VisitorsCrawler(org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)20 FileAttributes (org.sonar.server.computation.task.projectanalysis.component.FileAttributes)3 VisitorsCrawler (org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler)3 DefaultIssue (org.sonar.core.issue.DefaultIssue)2 MapSettings (org.sonar.api.config.MapSettings)1 Component (org.sonar.server.computation.task.projectanalysis.component.Component)1 ViewsComponent (org.sonar.server.computation.task.projectanalysis.component.ViewsComponent)1 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)1