Search in sources :

Example 1 with QualityGate

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

the class PostProjectAnalysisTasksExecutorTest method setUp.

@Before
public void setUp() {
    qualityGateHolder.setQualityGate(new QualityGate(QUALITY_GATE_UUID, 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));
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(BranchType.BRANCH);
    analysisMetadataHolder.setBranch(branch);
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Before(org.junit.Before)

Example 2 with QualityGate

use of org.sonar.ce.task.projectanalysis.qualitygate.QualityGate 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);
}
Also used : Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 3 with QualityGate

use of org.sonar.ce.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 = 3;
    Condition fixedCondition = createLessThanCondition(INT_METRIC_1, "4");
    Condition periodCondition = createLessThanCondition(INT_METRIC_1, "2");
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(fixedCondition, periodCondition)));
    Measure measure = newMeasureBuilder().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(fixedCondition, 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 4 with QualityGate

use of org.sonar.ce.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 = 3;
    Condition equalsOneErrorCondition = createLessThanCondition(INT_METRIC_1, "4");
    Condition equalsOneOkCondition = createLessThanCondition(INT_METRIC_2, "2");
    Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equalsOneErrorCondition, equalsOneOkCondition)));
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure);
    underTest.execute(new TestComputationStepContext());
    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(equalsOneErrorCondition, ERROR, rawValue));
    assertThat(rawMeasure2.get()).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
    assertThat(getAlertStatusMeasure()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(equalsOneErrorCondition, ERROR, rawValue) + ", " + dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
    assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(ERROR, of(new EvaluatedCondition(equalsOneErrorCondition, ERROR, rawValue), new EvaluatedCondition(equalsOneOkCondition, OK, rawValue)), false).toJson());
    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.ERROR).hasConditionCount(2).hasCondition(equalsOneErrorCondition, ConditionStatus.EvaluationStatus.ERROR, String.valueOf(rawValue)).hasCondition(equalsOneOkCondition, 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)

Example 5 with QualityGate

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

the class LoadQualityGateStepTest method execute_sets_default_QualityGate_when_project_has_no_settings.

@Test
public void execute_sets_default_QualityGate_when_project_has_no_settings() {
    QualityGate defaultGate = mock(QualityGate.class);
    when(qualityGateService.findDefaultQualityGate()).thenReturn(defaultGate);
    underTest.execute(new TestComputationStepContext());
    assertThat(mutableQualityGateHolder.getQualityGate().get()).isSameAs(defaultGate);
}
Also used : 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