Search in sources :

Example 16 with Condition

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

the class QualityGateMeasuresStepTest method rawMeasure_is_updated_if_present_and_new_measures_are_created_if_project_has_measure_for_metric_of_condition.

@Test
public void rawMeasure_is_updated_if_present_and_new_measures_are_created_if_project_has_measure_for_metric_of_condition() {
    int rawValue = 3;
    Condition equals2Condition = createLessThanCondition(INT_METRIC_1, "2");
    Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equals2Condition)));
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
    underTest.execute(new TestComputationStepContext());
    Optional<Measure> addedRawMeasure = measureRepository.getAddedRawMeasure(PROJECT_COMPONENT, INT_METRIC_1_KEY);
    assertThat(addedRawMeasure).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
    assertThat(getAlertStatusMeasure()).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
    assertThat(getQGDetailsMeasure().get()).hasValue(new QualityGateDetailsData(OK, of(new EvaluatedCondition(equals2Condition, OK, rawValue)), false).toJson());
    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.OK).hasConditionCount(1).hasCondition(equals2Condition, 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 17 with Condition

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

the class QualityGateDetailsData method toJson.

private static JsonObject toJson(EvaluatedCondition evaluatedCondition) {
    Condition condition = evaluatedCondition.getCondition();
    JsonObject result = new JsonObject();
    result.addProperty("metric", condition.getMetric().getKey());
    result.addProperty("op", condition.getOperator().getDbValue());
    if (condition.useVariation()) {
        // without this for new_ metrics, the UI will show "-" instead of
        // the actual value in the QG failure reason
        result.addProperty("period", 1);
    }
    result.addProperty("error", condition.getErrorThreshold());
    result.addProperty("actual", evaluatedCondition.getActualValue());
    result.addProperty(FIELD_LEVEL, evaluatedCondition.getLevel().name());
    return result;
}
Also used : Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) JsonObject(com.google.gson.JsonObject)

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