Search in sources :

Example 1 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class ConditionEvaluatorTest method testGreater.

@Test
public void testGreater() {
    Metric metric = createMetric(FLOAT);
    Measure measure = newMeasureBuilder().create(10.2d, 1, null);
    assertThat(underTest.evaluate(createCondition(metric, GREATER_THAN, "10.1"), measure)).hasLevel(ERROR).hasValue(10.2d);
    assertThat(underTest.evaluate(createCondition(metric, GREATER_THAN, "10.2"), measure)).hasLevel(OK).hasValue(10.2d);
    assertThat(underTest.evaluate(createCondition(metric, GREATER_THAN, "10.3"), measure)).hasLevel(OK).hasValue(10.2d);
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Example 2 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class ConditionEvaluatorTest method testSmaller.

@Test
public void testSmaller() {
    Metric metric = createMetric(FLOAT);
    Measure measure = newMeasureBuilder().create(10.2d, 1, null);
    assertThat(underTest.evaluate(createCondition(metric, LESS_THAN, "10.1"), measure)).hasLevel(OK).hasValue(10.2d);
    assertThat(underTest.evaluate(createCondition(metric, LESS_THAN, "10.2"), measure)).hasLevel(OK).hasValue(10.2d);
    assertThat(underTest.evaluate(createCondition(metric, LESS_THAN, "10.3"), measure)).hasLevel(ERROR).hasValue(10.2d);
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Example 3 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class ConditionEvaluatorTest method condition_on_new_metric_without_value_is_OK.

@Test
@UseDataProvider("numericNewMetricTypes")
public void condition_on_new_metric_without_value_is_OK(MetricType metricType) {
    Metric metric = createNewMetric(metricType);
    Measure measure = newMeasureBuilder().createNoValue();
    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3"), measure)).hasLevel(OK).hasValue(null);
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class ConditionEvaluatorTest method getLevel_throws_IEA_if_error_threshold_is_not_parsable_long.

@Test
public void getLevel_throws_IEA_if_error_threshold_is_not_parsable_long() {
    Metric metric = createMetric(WORK_DUR);
    Measure measure = newMeasureBuilder().create(60L, null);
    assertThatThrownBy(() -> underTest.evaluate(createCondition(metric, LESS_THAN, "polop"), measure)).isInstanceOf(IllegalArgumentException.class).hasMessage("Quality Gate: Unable to parse value 'polop' to compare against name");
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Example 5 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class ConditionEvaluatorTest method test_input_numbers.

@Test
public void test_input_numbers() {
    try {
        Metric metric = createMetric(FLOAT);
        Measure measure = newMeasureBuilder().create(10.2d, 1, null);
        underTest.evaluate(createCondition(metric, LESS_THAN, "20"), measure);
    } catch (NumberFormatException ex) {
        fail();
    }
    try {
        Metric metric = createMetric(INT);
        Measure measure = newMeasureBuilder().create(5, null);
        underTest.evaluate(createCondition(metric, LESS_THAN, "20.1"), measure);
    } catch (NumberFormatException ex) {
        fail();
    }
    try {
        Metric metric = createMetric(PERCENT);
        Measure measure = newMeasureBuilder().create(10.2d, 1, null);
        underTest.evaluate(createCondition(metric, LESS_THAN, "20.1"), measure);
    } catch (NumberFormatException ex) {
        fail();
    }
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Aggregations

Measure (org.sonar.ce.task.projectanalysis.measure.Measure)27 Test (org.junit.Test)19 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)15 EvaluatedCondition (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)6 Condition (org.sonar.ce.task.projectanalysis.qualitygate.Condition)6 QualityGate (org.sonar.ce.task.projectanalysis.qualitygate.QualityGate)5 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)5 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)4 QualityGateDetailsData (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)3 QualityGateStatus (org.sonar.ce.task.projectanalysis.measure.QualityGateStatus)3 Component (org.sonar.ce.task.projectanalysis.component.Component)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 Map (java.util.Map)1 VisitorsCrawler (org.sonar.ce.task.projectanalysis.component.VisitorsCrawler)1 MetricType (org.sonar.ce.task.projectanalysis.metric.Metric.MetricType)1