Search in sources :

Example 1 with ViewsComponent

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

the class LastCommitVisitorTest method aggregate_date_of_last_commit_to_views.

@Test
public void aggregate_date_of_last_commit_to_views() {
    final int VIEW_REF = 1;
    final int SUBVIEW_1_REF = 2;
    final int SUBVIEW_2_REF = 3;
    final int SUBVIEW_3_REF = 4;
    final int PROJECT_1_REF = 5;
    final int PROJECT_2_REF = 6;
    final int PROJECT_3_REF = 7;
    final long PROJECT_1_DATE = 1_500_000_000_000L;
    // the second project has the most recent commit date
    final long PROJECT_2_DATE = 1_700_000_000_000L;
    final long PROJECT_3_DATE = 1_600_000_000_000L;
    // view with 3 nested sub-views and 3 projects
    ViewsComponent view = ViewsComponent.builder(VIEW, VIEW_REF).addChildren(builder(SUBVIEW, SUBVIEW_1_REF).addChildren(builder(SUBVIEW, SUBVIEW_2_REF).addChildren(builder(PROJECT_VIEW, PROJECT_1_REF).build(), builder(PROJECT_VIEW, PROJECT_2_REF).build()).build(), builder(SUBVIEW, SUBVIEW_3_REF).addChildren(builder(PROJECT_VIEW, PROJECT_3_REF).build()).build()).build()).build();
    treeRootHolder.setRoot(view);
    measureRepository.addRawMeasure(PROJECT_1_REF, LAST_COMMIT_DATE_KEY, newMeasureBuilder().create(PROJECT_1_DATE));
    measureRepository.addRawMeasure(PROJECT_2_REF, LAST_COMMIT_DATE_KEY, newMeasureBuilder().create(PROJECT_2_DATE));
    measureRepository.addRawMeasure(PROJECT_3_REF, LAST_COMMIT_DATE_KEY, newMeasureBuilder().create(PROJECT_3_DATE));
    VisitorsCrawler underTest = new VisitorsCrawler(Lists.newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
    underTest.visit(view);
    // second level of sub-views
    assertDate(SUBVIEW_2_REF, PROJECT_2_DATE);
    assertDate(SUBVIEW_3_REF, PROJECT_3_DATE);
    // first level of sub-views
    assertDate(SUBVIEW_1_REF, PROJECT_2_DATE);
    // view
    assertDate(VIEW_REF, PROJECT_2_DATE);
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Test(org.junit.Test)

Example 2 with ViewsComponent

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

the class ViewsFormulaExecutorComponentVisitorTest method verify_no_measure_added_on_projectView.

@Test
public void verify_no_measure_added_on_projectView() {
    ViewsComponent project = ViewsComponent.builder(VIEW, ROOT_REF).addChildren(ViewsComponent.builder(SUBVIEW, SUBVIEW_1_REF).addChildren(ViewsComponent.builder(SUBVIEW, SUB_SUBVIEW_REF).addChildren(builder(PROJECT_VIEW, PROJECT_VIEW_1_REF).build()).build()).build()).build();
    treeRootHolder.setRoot(project);
    new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(project);
    assertNoAddedRawMeasure(PROJECT_VIEW_1_REF);
    verifySingleMetricValue(SUB_SUBVIEW_REF, 0);
    verifySingleMetricValue(SUBVIEW_1_REF, 0);
    verifySingleMetricValue(ROOT_REF, 0);
}
Also used : ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Test(org.junit.Test)

Example 3 with ViewsComponent

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

the class ViewsFormulaExecutorComponentVisitorTest method add_measure_even_if_leaf_is_not_a_PROJECT_VIEW.

@Test
public void add_measure_even_if_leaf_is_not_a_PROJECT_VIEW() {
    ViewsComponent project = ViewsComponent.builder(VIEW, ROOT_REF).addChildren(ViewsComponent.builder(SUBVIEW, SUBVIEW_1_REF).addChildren(ViewsComponent.builder(SUBVIEW, SUB_SUBVIEW_REF).build()).build()).build();
    treeRootHolder.setRoot(project);
    new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(project);
    verifySingleMetricValue(SUB_SUBVIEW_REF, 0);
    verifySingleMetricValue(SUBVIEW_1_REF, 0);
    verifySingleMetricValue(ROOT_REF, 0);
}
Also used : ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ViewsComponent (org.sonar.ce.task.projectanalysis.component.ViewsComponent)3 VisitorsCrawler (org.sonar.ce.task.projectanalysis.component.VisitorsCrawler)1