Search in sources :

Example 6 with Condition

use of org.sonar.server.computation.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 = 1;
    Condition fixedCondition = createEqualsCondition(INT_METRIC_1, "1", null);
    Condition periodCondition = createEqualsCondition(INT_METRIC_1, "1", null, 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(ERROR).hasQualityGateText(dumbResultTextAnswer(periodCondition, ERROR, 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)

Example 7 with Condition

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

the class QualityGateMeasuresStepTest method new_measures_have_ERROR_level_if_at_least_one_updated_measure_has_ERROR_level.

@Test
public void new_measures_have_ERROR_level_if_at_least_one_updated_measure_has_ERROR_level() {
    int rawValue = 1;
    Condition equals1ErrorCondition = createEqualsCondition(INT_METRIC_1, "1", null);
    Condition equals1WarningCondition = createEqualsCondition(INT_METRIC_2, null, "1");
    Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals1ErrorCondition, equals1WarningCondition)));
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure);
    underTest.execute();
    Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
    Optional<Measure> rawMeasure2 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_2_KEY);
    assertThat(rawMeasure1.get()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(equals1ErrorCondition, ERROR, rawValue));
    assertThat(rawMeasure2.get()).hasQualityGateLevel(WARN).hasQualityGateText(dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
    assertThat(getAlertStatusMeasure()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(equals1ErrorCondition, ERROR, rawValue) + ", " + dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
    assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(ERROR, of(new EvaluatedCondition(equals1ErrorCondition, ERROR, rawValue), new EvaluatedCondition(equals1WarningCondition, WARN, rawValue))).toJson());
    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.ERROR).hasConditionCount(2).hasCondition(equals1ErrorCondition, ConditionStatus.EvaluationStatus.ERROR, String.valueOf(rawValue)).hasCondition(equals1WarningCondition, ConditionStatus.EvaluationStatus.WARN, String.valueOf(rawValue));
}
Also used : EvaluatedCondition(org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) QualityGateDetailsData(org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData) Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) EvaluatedCondition(org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) QualityGate(org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 8 with Condition

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

the class QualityGateMeasuresStepTest method new_measure_has_ERROR_level_of_all_conditions_for_a_specific_metric_if_its_the_worst.

@Test
public void new_measure_has_ERROR_level_of_all_conditions_for_a_specific_metric_if_its_the_worst() {
    int rawValue = 1;
    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().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(ERROR).hasQualityGateText(dumbResultTextAnswer(fixedCondition, ERROR, 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)

Example 9 with Condition

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

the class ConditionToConditionTest method apply_converts_all_values_of_operator.

@Test
@UseDataProvider("allOperatorValues")
public void apply_converts_all_values_of_operator(Condition.Operator operator) {
    Condition condition = new Condition(newMetric(METRIC_KEY), operator.getDbValue(), ERROR_THRESHOLD, WARN_THRESHOLD, true);
    ConditionToCondition underTest = new ConditionToCondition(of(condition, SOME_CONDITION_STATUS));
    assertThat(underTest.apply(condition).getOperator().name()).isEqualTo(operator.name());
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 10 with Condition

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

the class ConditionToConditionTest method apply_copies_value.

@Test
public void apply_copies_value() {
    Condition otherCondition = 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, otherCondition, ConditionStatus.NO_VALUE_STATUS));
    assertThat(underTest.apply(SOME_CONDITION).getValue()).isEqualTo(SOME_VALUE);
    QualityGate.Condition res = underTest.apply(otherCondition);
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("There is no value when status is NO_VALUE");
    res.getValue();
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) QualityGate(org.sonar.api.ce.posttask.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