Search in sources :

Example 1 with Condition

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;
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) JsonObject(com.google.gson.JsonObject)

Example 2 with Condition

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();
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) Test(org.junit.Test)

Example 3 with Condition

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);
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric)

Example 4 with Condition

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\"" + "  }" + "]" + "}");
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) Test(org.junit.Test)

Example 5 with Condition

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));
}
Also used : EvaluatedCondition(org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) QualityGate(org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Aggregations

Condition (org.sonar.server.computation.task.projectanalysis.qualitygate.Condition)16 Test (org.junit.Test)11 EvaluatedCondition (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)10 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)8 QualityGate (org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate)7 QualityGateDetailsData (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 Metric (org.sonar.server.computation.task.projectanalysis.metric.Metric)2 JsonObject (com.google.gson.JsonObject)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Collection (java.util.Collection)1 Map (java.util.Map)1 QualityGate (org.sonar.api.ce.posttask.QualityGate)1 QualityGateStatus (org.sonar.server.computation.task.projectanalysis.measure.QualityGateStatus)1 MetricImpl (org.sonar.server.computation.task.projectanalysis.metric.MetricImpl)1 ConditionEvaluator (org.sonar.server.computation.task.projectanalysis.qualitygate.ConditionEvaluator)1 ConditionStatus (org.sonar.server.computation.task.projectanalysis.qualitygate.ConditionStatus)1 EvaluationResult (org.sonar.server.computation.task.projectanalysis.qualitygate.EvaluationResult)1