Search in sources :

Example 26 with Measure

use of org.sonar.server.computation.task.projectanalysis.measure.Measure 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)

Example 27 with Measure

use of org.sonar.server.computation.task.projectanalysis.measure.Measure 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 28 with Measure

use of org.sonar.server.computation.task.projectanalysis.measure.Measure 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 29 with Measure

use of org.sonar.server.computation.task.projectanalysis.measure.Measure 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 30 with Measure

use of org.sonar.server.computation.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class ConditionEvaluatorTest method test_input_numbers.

@Test
public void test_input_numbers() {
    try {
        Metric metric = createMetric(FLOAT);
        Measure measure = newMeasureBuilder().create(10.2d, 1, null);
        underTest.evaluate(createErrorCondition(metric, LESS_THAN, "20"), measure);
    } catch (NumberFormatException ex) {
        fail();
    }
    try {
        Metric metric = createMetric(INT);
        Measure measure = newMeasureBuilder().create(5, null);
        underTest.evaluate(createErrorCondition(metric, LESS_THAN, "20.1"), measure);
    } catch (NumberFormatException ex) {
        fail();
    }
    try {
        Metric metric = createMetric(PERCENT);
        Measure measure = newMeasureBuilder().create(10.2d, 1, null);
        underTest.evaluate(createErrorCondition(metric, LESS_THAN, "20.1"), measure);
    } catch (NumberFormatException ex) {
        fail();
    }
}
Also used : Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Aggregations

Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)46 Test (org.junit.Test)35 Metric (org.sonar.server.computation.task.projectanalysis.metric.Metric)30 EvaluatedCondition (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)8 Condition (org.sonar.server.computation.task.projectanalysis.qualitygate.Condition)8 QualityGate (org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate)7 QualityGateDetailsData (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)5 FileAttributes (org.sonar.server.computation.task.projectanalysis.component.FileAttributes)3 QualityGateStatus (org.sonar.server.computation.task.projectanalysis.measure.QualityGateStatus)3 MetricType (org.sonar.server.computation.task.projectanalysis.metric.Metric.MetricType)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 Map (java.util.Map)1 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)1 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)1 VisitorsCrawler (org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler)1 ScmInfo (org.sonar.server.computation.task.projectanalysis.scm.ScmInfo)1