Search in sources :

Example 41 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method not_fail_if_input_metrics_are_same_as_output_metrics.

@Test
public void not_fail_if_input_metrics_are_same_as_output_metrics() {
    MeasureComputer[] computers = new MeasureComputer[] { newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_1)) };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
    underTest.execute(new TestComputationStepContext());
    assertThat(holder.getMeasureComputers()).hasSize(1);
}
Also used : MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 42 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method sort_computers.

@Test
public void sort_computers() {
    // Should be the last to be executed
    MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
    // Should be the first to be executed
    MeasureComputer measureComputer2 = newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2));
    // Should be the second to be executed
    MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
    MeasureComputer[] computers = new MeasureComputer[] { measureComputer1, measureComputer2, measureComputer3 };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
    underTest.execute(new TestComputationStepContext());
    List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
    assertThat(result).hasSize(3);
    assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
    assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
    assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
}
Also used : MeasureComputerWrapper(org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 43 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method fail_with_ISE_when_output_metric_is_not_define_by_plugin.

@Test
public void fail_with_ISE_when_output_metric_is_not_define_by_plugin() {
    assertThatThrownBy(() -> {
        MeasureComputer[] computers = new MeasureComputer[] { newMeasureComputer(array(NEW_METRIC_4), array("unknown")) };
        ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
        underTest.execute(new TestComputationStepContext());
    }).isInstanceOf(IllegalStateException.class).hasMessage("Metric 'unknown' cannot be used as an output metric because no plugins declare this metric");
}
Also used : MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 44 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class LoadQualityGateStepTest method filter_conditions_on_pull_request.

@Test
public void filter_conditions_on_pull_request() {
    Metric newMetric = new MetricImpl("1", "new_key", "name", Metric.MetricType.INT);
    Metric metric = new MetricImpl("2", "key", "name", Metric.MetricType.INT);
    Condition variation = new Condition(newMetric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
    Condition condition = new Condition(metric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
    when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
    QualityGate defaultGate = new QualityGate("1", "qg", Arrays.asList(variation, condition));
    when(qualityGateService.findDefaultQualityGate()).thenReturn(defaultGate);
    underTest.execute(new TestComputationStepContext());
    assertThat(mutableQualityGateHolder.getQualityGate().get().getConditions()).containsExactly(variation);
}
Also used : Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 45 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class ReportComplexityMeasuresStepTest method verify_distribution_aggregation.

private void verify_distribution_aggregation(String metricKey) {
    measureRepository.addRawMeasure(FILE_1_REF, metricKey, newMeasureBuilder().create("0.5=3;3.5=5;6.5=9"));
    measureRepository.addRawMeasure(FILE_2_REF, metricKey, newMeasureBuilder().create("0.5=0;3.5=2;6.5=1"));
    underTest.execute(new TestComputationStepContext());
    assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isNotPresent();
    assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isNotPresent();
    String expectedNonFileValue = "0.5=3;3.5=7;6.5=10";
    assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext)

Aggregations

TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)458 Test (org.junit.Test)431 ComponentDto (org.sonar.db.component.ComponentDto)91 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)38 Component (org.sonar.ce.task.projectanalysis.component.Component)38 SnapshotDto (org.sonar.db.component.SnapshotDto)31 Date (java.util.Date)30 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)28 ComputationStep (org.sonar.ce.task.step.ComputationStep)24 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)17 FileSourceDto (org.sonar.db.source.FileSourceDto)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Project (org.sonar.server.project.Project)14 TextBlock (org.sonar.ce.task.projectanalysis.duplication.TextBlock)13 QualityProfile (org.sonar.server.qualityprofile.QualityProfile)13 Notification (org.sonar.api.notifications.Notification)12 DefaultIssue (org.sonar.core.issue.DefaultIssue)12 MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)11 IssueDto (org.sonar.db.issue.IssueDto)11 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)11