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));
}
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));
}
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));
}
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));
}
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();
}
}
Aggregations