Search in sources :

Example 11 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class QualityGateDetailsDataTest method verify_json_for_condition_on_leak_metric.

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

Example 12 with Condition

use of org.sonar.ce.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.LESS_THAN.getDbValue(), "error threshold");
}
Also used : Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) Metric(org.sonar.ce.task.projectanalysis.metric.Metric)

Example 13 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class QualityGateMeasuresStep method createStatusPerCondition.

private static Map<Condition, ConditionStatus> createStatusPerCondition(Iterable<Condition> conditions, Iterable<EvaluatedCondition> evaluatedConditions) {
    Map<Condition, EvaluatedCondition> evaluatedConditionPerCondition = from(evaluatedConditions).uniqueIndex(EvaluatedConditionToCondition.INSTANCE);
    ImmutableMap.Builder<Condition, ConditionStatus> builder = ImmutableMap.builder();
    for (Condition condition : conditions) {
        EvaluatedCondition evaluatedCondition = evaluatedConditionPerCondition.get(condition);
        if (evaluatedCondition == null) {
            builder.put(condition, NO_VALUE_STATUS);
        } else {
            builder.put(condition, create(toEvaluationStatus(evaluatedCondition.getLevel()), evaluatedCondition.getActualValue()));
        }
    }
    return builder.build();
}
Also used : EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) ConditionStatus(org.sonar.ce.task.projectanalysis.qualitygate.ConditionStatus) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 14 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class QualityGateMeasuresStepTest method new_measures_are_created_even_if_there_is_no_rawMeasure_for_metric_of_condition.

@Test
public void new_measures_are_created_even_if_there_is_no_rawMeasure_for_metric_of_condition() {
    Condition equals2Condition = createLessThanCondition(INT_METRIC_1, "2");
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equals2Condition)));
    underTest.execute(new TestComputationStepContext());
    Optional<Measure> addedRawMeasure = measureRepository.getAddedRawMeasure(PROJECT_COMPONENT, INT_METRIC_1_KEY);
    assertThat(addedRawMeasure).isAbsent();
    assertThat(getAlertStatusMeasure()).hasQualityGateLevel(OK).hasQualityGateText("");
    assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(OK, Collections.emptyList(), false).toJson());
    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.OK).hasConditionCount(1).hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.NO_VALUE, null);
}
Also used : EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) QualityGateDetailsData(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 15 with Condition

use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.

the class QualityGateMeasuresStepTest method new_measure_has_condition_on_leak_period_when_all_conditions_on_specific_metric_has_same_QG_level.

@Test
public void new_measure_has_condition_on_leak_period_when_all_conditions_on_specific_metric_has_same_QG_level() {
    int rawValue = 0;
    Condition fixedCondition = createLessThanCondition(INT_METRIC_1, "1");
    Condition periodCondition = createLessThanCondition(INT_METRIC_1, "1");
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, 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(new TestComputationStepContext());
    Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
    assertThat(rawMeasure1.get()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(periodCondition, ERROR, rawValue));
}
Also used : EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Aggregations

Condition (org.sonar.ce.task.projectanalysis.qualitygate.Condition)17 Test (org.junit.Test)11 EvaluatedCondition (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)8 Measure (org.sonar.ce.task.projectanalysis.measure.Measure)6 QualityGate (org.sonar.ce.task.projectanalysis.qualitygate.QualityGate)6 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)6 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)4 QualityGateDetailsData (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)3 MetricImpl (org.sonar.ce.task.projectanalysis.metric.MetricImpl)3 EvaluationResult (org.sonar.ce.task.projectanalysis.qualitygate.EvaluationResult)3 ImmutableMap (com.google.common.collect.ImmutableMap)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.ce.task.projectanalysis.measure.QualityGateStatus)1 ConditionEvaluator (org.sonar.ce.task.projectanalysis.qualitygate.ConditionEvaluator)1 ConditionStatus (org.sonar.ce.task.projectanalysis.qualitygate.ConditionStatus)1