Search in sources :

Example 1 with QualityGateDetailsData

use of org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData 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 = 3;
    Condition equalsOneErrorCondition = createLessThanCondition(INT_METRIC_1, "4");
    Condition equalsOneOkCondition = createLessThanCondition(INT_METRIC_2, "2");
    Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equalsOneErrorCondition, equalsOneOkCondition)));
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure);
    underTest.execute(new TestComputationStepContext());
    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(equalsOneErrorCondition, ERROR, rawValue));
    assertThat(rawMeasure2.get()).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
    assertThat(getAlertStatusMeasure()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(equalsOneErrorCondition, ERROR, rawValue) + ", " + dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
    assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(ERROR, of(new EvaluatedCondition(equalsOneErrorCondition, ERROR, rawValue), new EvaluatedCondition(equalsOneOkCondition, OK, rawValue)), false).toJson());
    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.ERROR).hasConditionCount(2).hasCondition(equalsOneErrorCondition, ConditionStatus.EvaluationStatus.ERROR, String.valueOf(rawValue)).hasCondition(equalsOneOkCondition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue));
}
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) EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 2 with QualityGateDetailsData

use of org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData in project sonarqube by SonarSource.

the class QualityGateMeasuresStep method addProjectMeasure.

private void addProjectMeasure(Component project, QualityGateDetailsDataBuilder builder) {
    Measure globalMeasure = Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(builder.getGlobalLevel(), StringUtils.join(builder.getLabels(), ", "))).create(builder.getGlobalLevel());
    Metric metric = metricRepository.getByKey(CoreMetrics.ALERT_STATUS_KEY);
    measureRepository.add(project, metric, globalMeasure);
    String detailMeasureValue = new QualityGateDetailsData(builder.getGlobalLevel(), builder.getEvaluatedConditions(), builder.isIgnoredConditions()).toJson();
    Measure detailsMeasure = Measure.newMeasureBuilder().create(detailMeasureValue);
    Metric qgDetailsMetric = metricRepository.getByKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
    measureRepository.add(project, qgDetailsMetric, detailsMeasure);
}
Also used : QualityGateStatus(org.sonar.ce.task.projectanalysis.measure.QualityGateStatus) QualityGateDetailsData(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric)

Example 3 with QualityGateDetailsData

use of org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData 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 4 with QualityGateDetailsData

use of org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData in project sonarqube by SonarSource.

the class QualityGateMeasuresStepTest method rawMeasure_is_updated_if_present_and_new_measures_are_created_if_project_has_measure_for_metric_of_condition.

@Test
public void rawMeasure_is_updated_if_present_and_new_measures_are_created_if_project_has_measure_for_metric_of_condition() {
    int rawValue = 3;
    Condition equals2Condition = createLessThanCondition(INT_METRIC_1, "2");
    Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equals2Condition)));
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
    underTest.execute(new TestComputationStepContext());
    Optional<Measure> addedRawMeasure = measureRepository.getAddedRawMeasure(PROJECT_COMPONENT, INT_METRIC_1_KEY);
    assertThat(addedRawMeasure).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
    assertThat(getAlertStatusMeasure()).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
    assertThat(getQGDetailsMeasure().get()).hasValue(new QualityGateDetailsData(OK, of(new EvaluatedCondition(equals2Condition, OK, rawValue)), false).toJson());
    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.OK).hasConditionCount(1).hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue));
}
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) EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Aggregations

Measure (org.sonar.ce.task.projectanalysis.measure.Measure)4 QualityGateDetailsData (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)4 Test (org.junit.Test)3 EvaluatedCondition (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)3 Condition (org.sonar.ce.task.projectanalysis.qualitygate.Condition)3 QualityGate (org.sonar.ce.task.projectanalysis.qualitygate.QualityGate)3 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)3 QualityGateStatus (org.sonar.ce.task.projectanalysis.measure.QualityGateStatus)1 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)1