Search in sources :

Example 1 with QualityGate

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

the class LoadQualityGateStep method executeForProject.

private void executeForProject(Component project) {
    String projectKey = project.getKey();
    Settings settings = settingsRepository.getSettings(project);
    String qualityGateSetting = settings.getString(PROPERTY_QUALITY_GATE);
    if (qualityGateSetting == null || StringUtils.isBlank(qualityGateSetting)) {
        LOGGER.debug("No quality gate is configured for project " + projectKey);
        qualityGateHolder.setNoQualityGate();
        return;
    }
    try {
        long qualityGateId = Long.parseLong(qualityGateSetting);
        Optional<QualityGate> qualityGate = qualityGateService.findById(qualityGateId);
        if (qualityGate.isPresent()) {
            qualityGateHolder.setQualityGate(qualityGate.get());
        } else {
            qualityGateHolder.setNoQualityGate();
        }
    } catch (NumberFormatException e) {
        throw new IllegalStateException(String.format("Unsupported value (%s) in property %s", qualityGateSetting, PROPERTY_QUALITY_GATE), e);
    }
}
Also used : Settings(org.sonar.api.config.Settings) QualityGate(org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate)

Example 2 with QualityGate

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

the class PostProjectAnalysisTasksExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    qualityGateHolder.setQualityGate(new QualityGate(QUALITY_GATE_ID, QUALITY_GATE_NAME, of(CONDITION_1, CONDITION_2)));
    qualityGateStatusHolder.setStatus(QualityGateStatus.OK, ImmutableMap.of(CONDITION_1, ConditionStatus.create(ConditionStatus.EvaluationStatus.OK, "value"), CONDITION_2, ConditionStatus.NO_VALUE_STATUS));
}
Also used : QualityGate(org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate) Before(org.junit.Before)

Example 3 with QualityGate

use of org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate 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 4 with QualityGate

use of org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate 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 5 with QualityGate

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

Aggregations

QualityGate (org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate)10 Test (org.junit.Test)8 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)7 EvaluatedCondition (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)7 Condition (org.sonar.server.computation.task.projectanalysis.qualitygate.Condition)7 QualityGateDetailsData (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)4 Before (org.junit.Before)1 MapSettings (org.sonar.api.config.MapSettings)1 Settings (org.sonar.api.config.Settings)1