3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.ce.task.projectanalysis.measure.qualitygatedetails;
22 import com.google.common.collect.ImmutableList;
23 import java.util.Collections;
24 import org.junit.Test;
25 import org.sonar.ce.task.projectanalysis.measure.Measure;
26 import org.sonar.ce.task.projectanalysis.metric.Metric;
27 import org.sonar.ce.task.projectanalysis.metric.MetricImpl;
28 import org.sonar.ce.task.projectanalysis.qualitygate.Condition;
29 import org.sonar.test.JsonAssert;
31 public class QualityGateDetailsDataTest {
32 @Test(expected = NullPointerException.class)
33 public void constructor_throws_NPE_if_Level_arg_is_null() {
34 new QualityGateDetailsData(null, Collections.emptyList(), false);
37 @Test(expected = NullPointerException.class)
38 public void constructor_throws_NPE_if_Iterable_arg_is_null() {
39 new QualityGateDetailsData(Measure.Level.OK, null, false);
43 public void verify_json_when_there_is_no_condition() {
44 String actualJson = new QualityGateDetailsData(Measure.Level.OK, Collections.emptyList(), false).toJson();
46 JsonAssert.assertJson(actualJson).isSimilarTo("{" +
53 public void verify_json_for_each_type_of_condition() {
54 String value = "actualValue";
55 Condition condition = new Condition(new MetricImpl(1, "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh", "warnTh");
56 ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(
57 new EvaluatedCondition(condition, Measure.Level.OK, value),
58 new EvaluatedCondition(condition, Measure.Level.WARN, value),
59 new EvaluatedCondition(condition, Measure.Level.ERROR, value));
60 String actualJson = new QualityGateDetailsData(Measure.Level.OK, evaluatedConditions, false).toJson();
62 JsonAssert.assertJson(actualJson).isSimilarTo("{" +
66 " \"metric\":\"key1\"," +
68 " \"warning\":\"warnTh\"," +
69 " \"error\":\"errorTh\"," +
70 " \"actual\":\"actualValue\"," +
74 " \"metric\":\"key1\"," +
76 " \"warning\":\"warnTh\"," +
77 " \"error\":\"errorTh\"," +
78 " \"actual\":\"actualValue\"," +
79 " \"level\":\"WARN\"" +
82 " \"metric\":\"key1\"," +
84 " \"warning\":\"warnTh\"," +
85 " \"error\":\"errorTh\"," +
86 " \"actual\":\"actualValue\"," +
87 " \"level\":\"ERROR\"" +
94 public void verify_json_for_small_leak() {
95 String actualJson = new QualityGateDetailsData(Measure.Level.OK, Collections.emptyList(), false).toJson();
96 JsonAssert.assertJson(actualJson).isSimilarTo("{\"ignoredConditions\": false}");
98 String actualJson2 = new QualityGateDetailsData(Measure.Level.OK, Collections.emptyList(), true).toJson();
99 JsonAssert.assertJson(actualJson2).isSimilarTo("{\"ignoredConditions\": true}");