Search in sources :

Example 6 with QualityGate

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

the class LoadQualityGateStepTest 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("10", "name", emptyList());
    when(analysisMetadataHolder.getProject()).thenReturn(mock(Project.class));
    when(qualityGateService.findQualityGate(any(Project.class))).thenReturn(Optional.of(qualityGate));
    underTest.execute(new TestComputationStepContext());
    assertThat(mutableQualityGateHolder.getQualityGate().get()).isSameAs(qualityGate);
}
Also used : Project(org.sonar.server.project.Project) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 7 with QualityGate

use of org.sonar.ce.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 = 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 8 with QualityGate

use of org.sonar.ce.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 = 0;
    Condition fixedCondition = createLessThanCondition(INT_METRIC_1, "1");
    Condition periodCondition = createLessThanCondition(INT_METRIC_1, "1");
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, 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(new TestComputationStepContext());
    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.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) 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 9 with QualityGate

use of org.sonar.ce.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 = 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

QualityGate (org.sonar.ce.task.projectanalysis.qualitygate.QualityGate)9 Test (org.junit.Test)8 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)8 Condition (org.sonar.ce.task.projectanalysis.qualitygate.Condition)6 Measure (org.sonar.ce.task.projectanalysis.measure.Measure)5 EvaluatedCondition (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)5 QualityGateDetailsData (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)3 Before (org.junit.Before)1 Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)1 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)1 MetricImpl (org.sonar.ce.task.projectanalysis.metric.MetricImpl)1 Project (org.sonar.server.project.Project)1