use of org.sonar.server.computation.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class QualityGateDetailsData method toJson.
private static JsonObject toJson(EvaluatedCondition evaluatedCondition) {
Condition condition = evaluatedCondition.getCondition();
JsonObject result = new JsonObject();
result.addProperty("metric", condition.getMetric().getKey());
result.addProperty("op", condition.getOperator().getDbValue());
if (condition.hasPeriod()) {
result.addProperty("period", 1);
}
if (condition.getWarningThreshold() != null) {
result.addProperty("warning", condition.getWarningThreshold());
}
if (condition.getErrorThreshold() != null) {
result.addProperty("error", condition.getErrorThreshold());
}
result.addProperty("actual", evaluatedCondition.getActualValue());
result.addProperty(FIELD_LEVEL, evaluatedCondition.getLevel().name());
return result;
}
use of org.sonar.server.computation.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class ConditionToConditionTest method apply_sets_onLeakPeriod_flag_when_Condition_has_non_null_Period.
@Test
public void apply_sets_onLeakPeriod_flag_when_Condition_has_non_null_Period() {
Condition noPeriodCondition = new Condition(newMetric(METRIC_KEY), Condition.Operator.NOT_EQUALS.getDbValue(), ERROR_THRESHOLD, WARN_THRESHOLD, false);
ConditionToCondition underTest = new ConditionToCondition(of(SOME_CONDITION, SOME_CONDITION_STATUS, noPeriodCondition, SOME_CONDITION_STATUS));
assertThat(underTest.apply(SOME_CONDITION).isOnLeakPeriod()).isTrue();
assertThat(underTest.apply(noPeriodCondition).isOnLeakPeriod()).isFalse();
}
use of org.sonar.server.computation.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class PostProjectAnalysisTasksExecutorTest method createCondition.
private static Condition createCondition(String metricKey) {
Metric metric = mock(Metric.class);
when(metric.getKey()).thenReturn(metricKey);
return new Condition(metric, Condition.Operator.EQUALS.getDbValue(), "error threshold", "warn threshold", false);
}
use of org.sonar.server.computation.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class QualityGateDetailsDataTest method verify_json_for_each_type_of_condition.
@Test
public void verify_json_for_each_type_of_condition() {
String value = "actualValue";
Condition condition = new Condition(new MetricImpl(1, "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh", "warnTh", true);
ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(new EvaluatedCondition(condition, Measure.Level.OK, value), new EvaluatedCondition(condition, Measure.Level.WARN, value), new EvaluatedCondition(condition, Measure.Level.ERROR, value));
String actualJson = new QualityGateDetailsData(Measure.Level.OK, evaluatedConditions).toJson();
JsonAssert.assertJson(actualJson).isSimilarTo("{" + "\"level\":\"OK\"," + "\"conditions\":[" + " {" + " \"metric\":\"key1\"," + " \"op\":\"GT\"," + " \"period\":1," + " \"warning\":\"warnTh\"," + " \"error\":\"errorTh\"," + " \"actual\":\"actualValue\"," + " \"level\":\"OK\"" + " }," + " {" + " \"metric\":\"key1\"," + " \"op\":\"GT\"," + " \"period\":1," + " \"warning\":\"warnTh\"," + " \"error\":\"errorTh\"," + " \"actual\":\"actualValue\"," + " \"level\":\"WARN\"" + " }," + " {" + " \"metric\":\"key1\"," + " \"op\":\"GT\"," + " \"period\":1," + " \"warning\":\"warnTh\"," + " \"error\":\"errorTh\"," + " \"actual\":\"actualValue\"," + " \"level\":\"ERROR\"" + " }" + "]" + "}");
}
use of org.sonar.server.computation.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class QualityGateMeasuresStepTest method new_measure_has_WARN_level_of_all_conditions_for_a_specific_metric_if_its_the_worst.
@Test
public void new_measure_has_WARN_level_of_all_conditions_for_a_specific_metric_if_its_the_worst() {
int rawValue = 2;
Condition fixedCondition = createEqualsCondition(INT_METRIC_1, "1", null);
Condition periodCondition = createEqualsCondition(INT_METRIC_1, null, "2", true);
qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(fixedCondition, periodCondition)));
Measure measure = newMeasureBuilder().setVariation(rawValue).create(rawValue, null);
measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, measure);
underTest.execute();
Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
assertThat(rawMeasure1.get()).hasQualityGateLevel(WARN).hasQualityGateText(dumbResultTextAnswer(periodCondition, WARN, rawValue));
}
Aggregations