Search in sources :

Example 21 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class ConditionEvaluatorTest method testErrorLevel.

@Test
public void testErrorLevel() {
    Metric metric = createMetric(FLOAT);
    Measure measure = newMeasureBuilder().create(10.2d, 1, null);
    assertThat(underTest.evaluate(createCondition(metric, LESS_THAN, "10.3"), measure)).hasLevel(ERROR);
    assertThat(underTest.evaluate(createCondition(metric, LESS_THAN, "10.1"), measure)).hasLevel(OK);
    assertThat(underTest.evaluate(new Condition(metric, LESS_THAN.getDbValue(), "10.3"), measure)).hasLevel(Measure.Level.ERROR);
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Example 22 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class LastCommitVisitorTest method date_is_not_computed_on_file_if_blame_is_not_in_scm_repo.

@Test
public void date_is_not_computed_on_file_if_blame_is_not_in_scm_repo() {
    VisitorsCrawler underTest = new VisitorsCrawler(Lists.newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
    ReportComponent file = createFileComponent(FILE_1_REF);
    treeRootHolder.setRoot(file);
    underTest.visit(file);
    Optional<Measure> measure = measureRepository.getAddedRawMeasure(FILE_1_REF, LAST_COMMIT_DATE_KEY);
    assertThat(measure).isEmpty();
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 23 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class QualityGateMeasuresStep method addProjectMeasure.

private void addProjectMeasure(Component project, QualityGateDetailsDataBuilder builder) {
    Measure globalMeasure = Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(builder.getGlobalLevel(), StringUtils.join(builder.getLabels(), ", "))).create(builder.getGlobalLevel());
    Metric metric = metricRepository.getByKey(CoreMetrics.ALERT_STATUS_KEY);
    measureRepository.add(project, metric, globalMeasure);
    String detailMeasureValue = new QualityGateDetailsData(builder.getGlobalLevel(), builder.getEvaluatedConditions(), builder.isIgnoredConditions()).toJson();
    Measure detailsMeasure = Measure.newMeasureBuilder().create(detailMeasureValue);
    Metric qgDetailsMetric = metricRepository.getByKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
    measureRepository.add(project, qgDetailsMetric, detailsMeasure);
}
Also used : QualityGateStatus(org.sonar.ce.task.projectanalysis.measure.QualityGateStatus) QualityGateDetailsData(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric)

Example 24 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class QualityGateEventsStep method executeForProject.

private void executeForProject(Component project) {
    Metric metric = metricRepository.getByKey(CoreMetrics.ALERT_STATUS_KEY);
    Optional<Measure> rawStatus = measureRepository.getRawMeasure(project, metric);
    if (!rawStatus.isPresent() || !rawStatus.get().hasQualityGateStatus()) {
        return;
    }
    checkQualityGateStatusChange(project, metric, rawStatus.get().getQualityGateStatus());
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric)

Example 25 with Measure

use of org.sonar.ce.task.projectanalysis.measure.Measure 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)

Aggregations

Measure (org.sonar.ce.task.projectanalysis.measure.Measure)27 Test (org.junit.Test)19 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)15 EvaluatedCondition (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)6 Condition (org.sonar.ce.task.projectanalysis.qualitygate.Condition)6 QualityGate (org.sonar.ce.task.projectanalysis.qualitygate.QualityGate)5 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)5 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)4 QualityGateDetailsData (org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)3 QualityGateStatus (org.sonar.ce.task.projectanalysis.measure.QualityGateStatus)3 Component (org.sonar.ce.task.projectanalysis.component.Component)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 Map (java.util.Map)1 VisitorsCrawler (org.sonar.ce.task.projectanalysis.component.VisitorsCrawler)1 MetricType (org.sonar.ce.task.projectanalysis.metric.Metric.MetricType)1