Search in sources :

Example 16 with Measure

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

the class NewMaintainabilityMeasuresVisitorTest method leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt.

@Test
public void leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt() {
    when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
    Component file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build();
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(DIRECTORY, 111).addChildren(file).build()).build());
    Measure newDebtMeasure = createNewDebtMeasure(50);
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
    measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150));
    measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250));
    // 4 lines file, only first one is not ncloc
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    // first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date
    setNewLines(file, 3, 4);
    underTest.visit(treeRootHolder.getRoot());
    assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33);
    assertNewDebtRatioValues(111, 83.33);
    assertNewDebtRatioValues(ROOT_REF, 83.33);
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 17 with Measure

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

the class NewMaintainabilityMeasuresVisitorTest method setupOneFileAloneInAProject.

private void setupOneFileAloneInAProject(int newDebt, Flag isUnitTest, Flag withNclocLines, Flag withNewLines) {
    checkArgument(isUnitTest == Flag.UT_FILE || isUnitTest == Flag.SRC_FILE);
    checkArgument(withNclocLines == Flag.WITH_NCLOC || withNclocLines == Flag.NO_NCLOC || withNclocLines == Flag.MISSING_MEASURE_NCLOC);
    checkArgument(withNewLines == Flag.WITH_NEW_LINES || withNewLines == Flag.NO_NEW_LINES);
    Component file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(isUnitTest == Flag.UT_FILE, LANGUAGE_1_KEY, 1)).build();
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(file).build());
    Measure newDebtMeasure = createNewDebtMeasure(newDebt);
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
    if (withNclocLines == Flag.WITH_NCLOC) {
        // 4 lines file, only first one is not ncloc
        measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    } else if (withNclocLines == Flag.NO_NCLOC) {
        // 4 lines file, none of which is ncloc
        measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNoNclocDataMeasure(4));
    }
    if (withNewLines == Flag.WITH_NEW_LINES) {
        // 2 last lines are new
        setNewLines(file, 3, 4);
    }
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes)

Example 18 with Measure

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

the class SecurityReviewMeasuresVisitorTest method verifySecurityReviewRating.

private void verifySecurityReviewRating(int componentRef, Rating rating) {
    Measure measure = measureRepository.getAddedRawMeasure(componentRef, SECURITY_REVIEW_RATING_KEY).get();
    assertThat(measure.getIntValue()).isEqualTo(rating.getIndex());
    assertThat(measure.getData()).isEqualTo(rating.name());
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure)

Example 19 with Measure

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

the class ConditionEvaluatorTest method condition_is_always_ok_when_measure_is_noValue.

@Test
public void condition_is_always_ok_when_measure_is_noValue() {
    for (MetricType metricType : from(asList(values())).filter(not(in(ImmutableSet.of(BOOL, DATA, DISTRIB, STRING))))) {
        Metric metric = createMetric(metricType);
        Measure measure = newMeasureBuilder().createNoValue();
        assertThat(underTest.evaluate(createCondition(metric, LESS_THAN, "10.2"), measure)).hasLevel(OK);
    }
}
Also used : MetricType(org.sonar.ce.task.projectanalysis.metric.Metric.MetricType) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Example 20 with Measure

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

the class ConditionEvaluatorTest method fail_when_condition_on_leak_period_is_using_unsupported_metric.

@Test
public void fail_when_condition_on_leak_period_is_using_unsupported_metric() {
    Metric metric = createNewMetric(LEVEL);
    Measure measure = newMeasureBuilder().setVariation(0d).createNoValue();
    assertThatThrownBy(() -> underTest.evaluate(new Condition(metric, LESS_THAN.getDbValue(), "3"), measure)).isInstanceOf(IllegalArgumentException.class).hasMessage("Unsupported metric type LEVEL");
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) 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