use of org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate 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));
}
use of org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateLoadingStepTest method execute_sets_QualityGate_if_it_can_be_found_by_service.
@Test
public void execute_sets_QualityGate_if_it_can_be_found_by_service() {
QualityGate qualityGate = new QualityGate(465, "name", Collections.<Condition>emptyList());
treeRootHolder.setRoot(PROJECT_ALONE);
when(settingsRepository.getSettings(PROJECT_ALONE)).thenReturn(new MapSettings().setProperty("sonar.qualitygate", 10));
when(qualityGateService.findById(10)).thenReturn(Optional.of(qualityGate));
underTest.execute();
assertThat(mutableQualityGateHolder.getQualityGate().get()).isSameAs(qualityGate);
}
use of org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateMeasuresStepTest method new_measures_have_WARNING_level_if_no_updated_measure_has_ERROR_level.
@Test
public void new_measures_have_WARNING_level_if_no_updated_measure_has_ERROR_level() {
int rawValue = 1;
Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", 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(equals2Condition, 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(OK).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
assertThat(rawMeasure2.get()).hasQualityGateLevel(WARN).hasQualityGateText(dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
assertThat(getAlertStatusMeasure()).hasQualityGateLevel(WARN).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue) + ", " + dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(WARN, of(new EvaluatedCondition(equals2Condition, OK, rawValue), new EvaluatedCondition(equals1WarningCondition, WARN, rawValue))).toJson());
QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.WARN).hasConditionCount(2).hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue)).hasCondition(equals1WarningCondition, ConditionStatus.EvaluationStatus.WARN, String.valueOf(rawValue));
}
use of org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate 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 = createEqualsCondition(INT_METRIC_1, "2", null);
qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition)));
underTest.execute();
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.<EvaluatedCondition>emptyList()).toJson());
QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.OK).hasConditionCount(1).hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.NO_VALUE, null);
}
use of org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate 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 = 1;
Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", null);
Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition)));
measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
underTest.execute();
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))).toJson());
QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.OK).hasConditionCount(1).hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue));
}
Aggregations