use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class ConditionToConditionTest method apply_copies_value.
@Test
public void apply_copies_value() {
Condition otherCondition = new Condition(newMetric(METRIC_KEY), Condition.Operator.LESS_THAN.getDbValue(), ERROR_THRESHOLD);
ConditionToCondition underTest = new ConditionToCondition(of(SOME_CONDITION, SOME_CONDITION_STATUS, otherCondition, ConditionStatus.NO_VALUE_STATUS));
assertThat(underTest.apply(SOME_CONDITION).getValue()).isEqualTo(SOME_VALUE);
QualityGate.Condition res = underTest.apply(otherCondition);
assertThatThrownBy(res::getValue).isInstanceOf(IllegalStateException.class).hasMessage("There is no value when status is NO_VALUE");
}
use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class ConditionToConditionTest method apply_converts_all_values_of_operator.
@Test
@UseDataProvider("allOperatorValues")
public void apply_converts_all_values_of_operator(Condition.Operator operator) {
Condition condition = new Condition(newMetric(METRIC_KEY), operator.getDbValue(), ERROR_THRESHOLD);
ConditionToCondition underTest = new ConditionToCondition(of(condition, SOME_CONDITION_STATUS));
assertThat(underTest.apply(condition).getOperator().name()).isEqualTo(operator.name());
}
use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class QualityGateMeasuresStep method updateMeasures.
private void updateMeasures(Component project, Set<Condition> conditions, QualityGateDetailsDataBuilder builder) {
Multimap<Metric, Condition> conditionsPerMetric = conditions.stream().collect(MoreCollectors.index(Condition::getMetric, java.util.function.Function.identity()));
boolean ignoredConditions = false;
for (Map.Entry<Metric, Collection<Condition>> entry : conditionsPerMetric.asMap().entrySet()) {
Metric metric = entry.getKey();
Optional<Measure> measure = measureRepository.getRawMeasure(project, metric);
if (!measure.isPresent()) {
continue;
}
final MetricEvaluationResult metricEvaluationResult = evaluateQualityGate(measure.get(), entry.getValue());
final MetricEvaluationResult finalMetricEvaluationResult;
if (smallChangesetQualityGateSpecialCase.appliesTo(project, metricEvaluationResult)) {
finalMetricEvaluationResult = smallChangesetQualityGateSpecialCase.apply(metricEvaluationResult);
ignoredConditions = true;
} else {
finalMetricEvaluationResult = metricEvaluationResult;
}
String text = evaluationResultTextConverter.asText(finalMetricEvaluationResult.condition, finalMetricEvaluationResult.evaluationResult);
builder.addLabel(text);
Measure updatedMeasure = Measure.updatedMeasureBuilder(measure.get()).setQualityGateStatus(new QualityGateStatus(finalMetricEvaluationResult.evaluationResult.getLevel(), text)).create();
measureRepository.update(project, metric, updatedMeasure);
builder.addEvaluatedCondition(finalMetricEvaluationResult);
}
builder.setIgnoredConditions(ignoredConditions);
}
use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class QualityGateMeasuresStep method evaluateQualityGate.
private static MetricEvaluationResult evaluateQualityGate(Measure measure, Collection<Condition> conditions) {
ConditionEvaluator conditionEvaluator = new ConditionEvaluator();
MetricEvaluationResult metricEvaluationResult = null;
for (Condition newCondition : conditions) {
EvaluationResult newEvaluationResult = conditionEvaluator.evaluate(newCondition, measure);
if (metricEvaluationResult == null || newEvaluationResult.getLevel().ordinal() > metricEvaluationResult.evaluationResult.getLevel().ordinal()) {
metricEvaluationResult = new MetricEvaluationResult(newEvaluationResult, newCondition);
}
}
return metricEvaluationResult;
}
use of org.sonar.ce.task.projectanalysis.qualitygate.Condition in project sonarqube by SonarSource.
the class LoadQualityGateStepTest method filter_conditions_on_pull_request.
@Test
public void filter_conditions_on_pull_request() {
Metric newMetric = new MetricImpl("1", "new_key", "name", Metric.MetricType.INT);
Metric metric = new MetricImpl("2", "key", "name", Metric.MetricType.INT);
Condition variation = new Condition(newMetric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
Condition condition = new Condition(metric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
QualityGate defaultGate = new QualityGate("1", "qg", Arrays.asList(variation, condition));
when(qualityGateService.findDefaultQualityGate()).thenReturn(defaultGate);
underTest.execute(new TestComputationStepContext());
assertThat(mutableQualityGateHolder.getQualityGate().get().getConditions()).containsExactly(variation);
}
Aggregations