3 * Copyright (C) 2009-2017 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.server.computation.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.server.computation.task.projectanalysis.measure.Measure;
26 import org.sonar.server.computation.task.projectanalysis.metric.Metric;
27 import org.sonar.server.computation.task.projectanalysis.metric.MetricImpl;
28 import org.sonar.server.computation.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.<EvaluatedCondition>emptyList());
37 @Test(expected = NullPointerException.class)
38 public void constructor_throws_NPE_if_Iterable_arg_is_null() {
39 new QualityGateDetailsData(Measure.Level.OK, null);
43 public void verify_json_when_there_is_no_condition() {
44 String actualJson = new QualityGateDetailsData(Measure.Level.OK, Collections.<EvaluatedCondition>emptyList()).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", true);
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).toJson();
62 JsonAssert.assertJson(actualJson).isSimilarTo("{" +
66 " \"metric\":\"key1\"," +
69 " \"warning\":\"warnTh\"," +
70 " \"error\":\"errorTh\"," +
71 " \"actual\":\"actualValue\"," +
75 " \"metric\":\"key1\"," +
78 " \"warning\":\"warnTh\"," +
79 " \"error\":\"errorTh\"," +
80 " \"actual\":\"actualValue\"," +
81 " \"level\":\"WARN\"" +
84 " \"metric\":\"key1\"," +
87 " \"warning\":\"warnTh\"," +
88 " \"error\":\"errorTh\"," +
89 " \"actual\":\"actualValue\"," +
90 " \"level\":\"ERROR\"" +