Search in sources :

Example 6 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class QualityGateMeasuresStepTest method new_measure_has_ERROR_level_of_all_conditions_for_a_specific_metric_if_its_the_worst.

@Test
public void new_measure_has_ERROR_level_of_all_conditions_for_a_specific_metric_if_its_the_worst() {
    int rawValue = 3;
    Condition fixedCondition = createLessThanCondition(INT_METRIC_1, "4");
    Condition periodCondition = createLessThanCondition(INT_METRIC_1, "2");
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(fixedCondition, periodCondition)));
    Measure measure = newMeasureBuilder().create(rawValue, null);
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, measure);
    underTest.execute(new TestComputationStepContext());
    Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
    assertThat(rawMeasure1.get()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(fixedCondition, ERROR, rawValue));
}
Also used : EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 7 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class QualityGateMeasuresStepTest method new_measures_have_ERROR_level_if_at_least_one_updated_measure_has_ERROR_level.

@Test
public void new_measures_have_ERROR_level_if_at_least_one_updated_measure_has_ERROR_level() {
    int rawValue = 3;
    Condition equalsOneErrorCondition = createLessThanCondition(INT_METRIC_1, "4");
    Condition equalsOneOkCondition = createLessThanCondition(INT_METRIC_2, "2");
    Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equalsOneErrorCondition, equalsOneOkCondition)));
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure);
    underTest.execute(new TestComputationStepContext());
    Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
    Optional<Measure> rawMeasure2 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_2_KEY);
    assertThat(rawMeasure1.get()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(equalsOneErrorCondition, ERROR, rawValue));
    assertThat(rawMeasure2.get()).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
    assertThat(getAlertStatusMeasure()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(equalsOneErrorCondition, ERROR, rawValue) + ", " + dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
    assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(ERROR, of(new EvaluatedCondition(equalsOneErrorCondition, ERROR, rawValue), new EvaluatedCondition(equalsOneOkCondition, OK, rawValue)), false).toJson());
    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.ERROR).hasConditionCount(2).hasCondition(equalsOneErrorCondition, ConditionStatus.EvaluationStatus.ERROR, String.valueOf(rawValue)).hasCondition(equalsOneOkCondition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue));
}
Also used : EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) QualityGateDetailsData(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 8 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class SmallChangesetQualityGateSpecialCaseTest method apply.

@Test
public void apply() {
    Comparable<?> value = mock(Comparable.class);
    Condition condition = mock(Condition.class);
    QualityGateMeasuresStep.MetricEvaluationResult original = new QualityGateMeasuresStep.MetricEvaluationResult(new EvaluationResult(Measure.Level.ERROR, value), condition);
    QualityGateMeasuresStep.MetricEvaluationResult modified = underTest.apply(original);
    assertThat(modified.evaluationResult.getLevel()).isSameAs(OK);
    assertThat(modified.evaluationResult.getValue()).isSameAs(value);
    assertThat(modified.condition).isSameAs(condition);
}
Also used : Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) EvaluationResult(org.sonar.ce.task.projectanalysis.qualitygate.EvaluationResult) Test(org.junit.Test)

Example 9 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class SmallChangesetQualityGateSpecialCaseTest method generateEvaluationResult.

private QualityGateMeasuresStep.MetricEvaluationResult generateEvaluationResult(String metric, Measure.Level level) {
    Metric newCoverageMetric = metricRepository.getByKey(metric);
    Condition condition = new Condition(newCoverageMetric, "LT", "80");
    EvaluationResult evaluationResult = new EvaluationResult(level, mock(Comparable.class));
    return new QualityGateMeasuresStep.MetricEvaluationResult(evaluationResult, condition);
}
Also used : Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) EvaluationResult(org.sonar.ce.task.projectanalysis.qualitygate.EvaluationResult)

Example 10 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class QualityGateDetailsDataTest method verify_json_for_each_type_of_condition.

@Test
public void verify_json_for_each_type_of_condition() {
    String value = "actualValue";
    Condition condition = new Condition(new MetricImpl("1", "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
    ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(new EvaluatedCondition(condition, Measure.Level.OK, value), new EvaluatedCondition(condition, Measure.Level.ERROR, value));
    String actualJson = new QualityGateDetailsData(Measure.Level.OK, evaluatedConditions, false).toJson();
    JsonAssert.assertJson(actualJson).isSimilarTo("{" + "\"level\":\"OK\"," + "\"conditions\":[" + "  {" + "    \"metric\":\"key1\"," + "    \"op\":\"GT\"," + "    \"error\":\"errorTh\"," + "    \"actual\":\"actualValue\"," + "    \"level\":\"OK\"" + "  }," + "  {" + "    \"metric\":\"key1\"," + "    \"op\":\"GT\"," + "    \"error\":\"errorTh\"," + "    \"actual\":\"actualValue\"," + "    \"level\":\"ERROR\"" + "  }" + "]" + "}");
}
Also used : Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) Test(org.junit.Test)

Aggregations

Condition (org.sonar.ce.task.projectanalysis.qualitygate.Condition)17 Test (org.junit.Test)11 EvaluatedCondition (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)8 Measure (org.sonar.ce.task.projectanalysis.measure.Measure)6 QualityGate (org.sonar.ce.task.projectanalysis.qualitygate.QualityGate)6 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)6 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)4 QualityGateDetailsData (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)3 MetricImpl (org.sonar.ce.task.projectanalysis.metric.MetricImpl)3 EvaluationResult (org.sonar.ce.task.projectanalysis.qualitygate.EvaluationResult)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 JsonObject (com.google.gson.JsonObject)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Collection (java.util.Collection)1 Map (java.util.Map)1 QualityGate (org.sonar.api.ce.posttask.QualityGate)1 QualityGateStatus (org.sonar.ce.task.projectanalysis.measure.QualityGateStatus)1 ConditionEvaluator (org.sonar.ce.task.projectanalysis.qualitygate.ConditionEvaluator)1 ConditionStatus (org.sonar.ce.task.projectanalysis.qualitygate.ConditionStatus)1