Search in sources :

Example 1 with EvaluatedCondition

use of org.sonar.server.qualitygate.EvaluatedCondition in project sonarqube by SonarSource.

the class LiveQualityGateComputerImplTest method refreshGateStatus_generates_gate_related_measures.

@Test
public void refreshGateStatus_generates_gate_related_measures() {
    ComponentDto project = ComponentTesting.newPublicProjectDto();
    MetricDto conditionMetric = newMetricDto();
    MetricDto statusMetric = newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY);
    MetricDto detailsMetric = newMetricDto().setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
    Condition condition = new Condition(conditionMetric.getKey(), Condition.Operator.GREATER_THAN, "10");
    QualityGate gate = new QualityGate("1", "foo", ImmutableSet.of(condition));
    MeasureMatrix matrix = new MeasureMatrix(singleton(project), asList(conditionMetric, statusMetric, detailsMetric), emptyList());
    EvaluatedQualityGate result = underTest.refreshGateStatus(project, gate, matrix, configuration);
    QualityGateEvaluator.Measures measures = qualityGateEvaluator.getCalledMeasures();
    assertThat(measures.get(conditionMetric.getKey())).isEmpty();
    assertThat(result.getStatus()).isEqualTo(Metric.Level.OK);
    assertThat(result.getEvaluatedConditions()).extracting(EvaluatedCondition::getStatus).containsExactly(EvaluatedCondition.EvaluationStatus.OK);
    assertThat(matrix.getMeasure(project, CoreMetrics.ALERT_STATUS_KEY).get().getDataAsString()).isEqualTo(Metric.Level.OK.name());
    assertThat(matrix.getMeasure(project, CoreMetrics.QUALITY_GATE_DETAILS_KEY).get().getDataAsString()).isNotEmpty().startsWith("{").endsWith("}");
}
Also used : EvaluatedCondition(org.sonar.server.qualitygate.EvaluatedCondition) Condition(org.sonar.server.qualitygate.Condition) MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) QualityGateEvaluator(org.sonar.server.qualitygate.QualityGateEvaluator) QualityGate(org.sonar.server.qualitygate.QualityGate) EvaluatedQualityGate(org.sonar.server.qualitygate.EvaluatedQualityGate) EvaluatedQualityGate(org.sonar.server.qualitygate.EvaluatedQualityGate) Test(org.junit.Test)

Example 2 with EvaluatedCondition

use of org.sonar.server.qualitygate.EvaluatedCondition in project sonarqube by SonarSource.

the class WebhookPayloadFactoryImpl method writeQualityGate.

private static void writeQualityGate(JsonWriter writer, EvaluatedQualityGate gate) {
    writer.name("qualityGate").beginObject().prop("name", gate.getQualityGate().getName()).prop(PROPERTY_STATUS, gate.getStatus().toString()).name("conditions").beginArray();
    for (EvaluatedCondition evaluatedCondition : gate.getEvaluatedConditions()) {
        Condition condition = evaluatedCondition.getCondition();
        writer.beginObject().prop("metric", condition.getMetricKey()).prop("operator", condition.getOperator().name());
        evaluatedCondition.getValue().ifPresent(t -> writer.prop("value", t));
        writer.prop(PROPERTY_STATUS, evaluatedCondition.getStatus().name()).prop("errorThreshold", condition.getErrorThreshold()).endObject();
    }
    writer.endArray().endObject();
}
Also used : EvaluatedCondition(org.sonar.server.qualitygate.EvaluatedCondition) Condition(org.sonar.server.qualitygate.Condition) EvaluatedCondition(org.sonar.server.qualitygate.EvaluatedCondition)

Aggregations

Condition (org.sonar.server.qualitygate.Condition)2 EvaluatedCondition (org.sonar.server.qualitygate.EvaluatedCondition)2 Test (org.junit.Test)1 ComponentDto (org.sonar.db.component.ComponentDto)1 MetricDto (org.sonar.db.metric.MetricDto)1 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)1 EvaluatedQualityGate (org.sonar.server.qualitygate.EvaluatedQualityGate)1 QualityGate (org.sonar.server.qualitygate.QualityGate)1 QualityGateEvaluator (org.sonar.server.qualitygate.QualityGateEvaluator)1