]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11570 Add period back to QG conditions recomputed on UI change
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Thu, 10 Jan 2019 14:00:10 +0000 (15:00 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 16 Jan 2019 08:42:57 +0000 (09:42 +0100)
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateConverter.java

index 5a91b986a0231cccda28802688abbb73a2136872..5b27ad8aeeeaa92ae35c4c90a00e4a61d1717d5d 100644 (file)
@@ -79,6 +79,38 @@ public class QualityGateDetailsDataTest {
       "}");
   }
 
+  @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();
index 402c9bfed54b802808669abb760fc416eef8ead8..8ed1b406c62a277321de473c91a57b883c11ee59 100644 (file)
@@ -49,6 +49,9 @@ public class QualityGateConverter {
     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());