"}");
}
+ @Test
+ public void verify_json_for_condition_on_leak_metric() {
+ String value = "actualValue";
+ Condition condition = new Condition(new MetricImpl(1, "new_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\":\"new_key1\"," +
+ " \"op\":\"GT\"," +
+ " \"error\":\"errorTh\"," +
+ " \"actual\":\"actualValue\"," +
+ " \"period\":1," +
+ " \"level\":\"OK\"" +
+ " }," +
+ " {" +
+ " \"metric\":\"new_key1\"," +
+ " \"op\":\"GT\"," +
+ " \"error\":\"errorTh\"," +
+ " \"actual\":\"actualValue\"," +
+ " \"period\":1," +
+ " \"level\":\"ERROR\"" +
+ " }" +
+ "]" +
+ "}");
+ }
+
@Test
public void verify_json_for_small_leak() {
String actualJson = new QualityGateDetailsData(Measure.Level.OK, Collections.emptyList(), false).toJson();
JsonObject result = new JsonObject();
result.addProperty("metric", condition.getMetricKey());
result.addProperty("op", condition.getOperator().getDbValue());
+ if (condition.isOnLeakPeriod()) {
+ result.addProperty("period", 1);
+ }
result.addProperty("error", condition.getErrorThreshold());
evaluatedCondition.getValue().ifPresent(v -> result.addProperty("actual", v));
result.addProperty(FIELD_LEVEL, evaluatedCondition.getStatus().name());