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("}");
}
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();
}
Aggregations