Search in sources :

Example 11 with LiveMeasureDto

use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.

the class MeasureMatrixTest method setValue_double_updates_variation.

@Test
public void setValue_double_updates_variation() {
    MetricDto metric = newMetricDto().setDecimalScale(2);
    LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(3.14).setVariation(1.14);
    MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
    underTest.setValue(PROJECT, metric.getKey(), 3.56);
    assertThat(underTest.getChanged()).hasSize(1);
    verifyValue(underTest, PROJECT, metric, 3.56);
    verifyVariation(underTest, PROJECT, metric, 3.56 - (3.14 - 1.14));
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test)

Example 12 with LiveMeasureDto

use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.

the class MeasureMatrixTest method setValue_double_rounds_up_and_updates_value.

@Test
public void setValue_double_rounds_up_and_updates_value() {
    MetricDto metric = newMetricDto().setDecimalScale(2);
    LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(1.23);
    MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
    underTest.setValue(PROJECT, metric.getKey(), 3.14159);
    assertThat(underTest.getMeasure(PROJECT, metric.getKey()).get().getValue()).isEqualTo(3.14);
    assertThat(underTest.getChanged()).hasSize(1);
    underTest.setValue(PROJECT, metric.getKey(), 3.148);
    verifyValue(underTest, PROJECT, metric, 3.15);
    verifyVariation(underTest, PROJECT, metric, null);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test)

Example 13 with LiveMeasureDto

use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.

the class MeasureMatrixTest method setValue_double_does_nothing_if_value_is_unchanged.

@Test
public void setValue_double_does_nothing_if_value_is_unchanged() {
    MetricDto metric = newMetricDto().setDecimalScale(2);
    LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(3.14);
    MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
    underTest.setValue(PROJECT, metric.getKey(), 3.14159);
    assertThat(underTest.getChanged()).isEmpty();
    verifyValue(underTest, PROJECT, metric, 3.14);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test)

Example 14 with LiveMeasureDto

use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.

the class MeasureMatrixTest method setLeakValue_double_does_nothing_if_value_is_unchanged.

@Test
public void setLeakValue_double_does_nothing_if_value_is_unchanged() {
    MetricDto metric = newMetricDto().setDecimalScale(2);
    LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(null).setVariation(3.14);
    MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
    underTest.setLeakValue(PROJECT, metric.getKey(), 3.14159);
    assertThat(underTest.getChanged()).isEmpty();
    verifyVariation(underTest, PROJECT, metric, 3.14);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test)

Example 15 with LiveMeasureDto

use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.

the class LiveQualityGateComputerImplTest method refreshGateStatus_provides_measures_to_evaluator.

@Test
public void refreshGateStatus_provides_measures_to_evaluator() {
    ComponentDto project = ComponentTesting.newPublicProjectDto();
    MetricDto numericMetric = newMetricDto().setValueType(Metric.ValueType.FLOAT.name());
    MetricDto numericNewMetric = newMetricDto().setValueType(Metric.ValueType.FLOAT.name()).setKey("new_metric");
    MetricDto stringMetric = newMetricDto().setValueType(Metric.ValueType.STRING.name());
    MetricDto statusMetric = newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY);
    MetricDto detailsMetric = newMetricDto().setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
    QualityGate gate = new QualityGate("1", "foo", Collections.emptySet());
    LiveMeasureDto numericMeasure = new LiveMeasureDto().setMetricUuid(numericMetric.getUuid()).setValue(1.23).setVariation(4.56).setComponentUuid(project.uuid());
    LiveMeasureDto numericNewMeasure = new LiveMeasureDto().setMetricUuid(numericNewMetric.getUuid()).setValue(7.8).setVariation(8.9).setComponentUuid(project.uuid());
    LiveMeasureDto stringMeasure = new LiveMeasureDto().setMetricUuid(stringMetric.getUuid()).setData("bar").setComponentUuid(project.uuid());
    MeasureMatrix matrix = new MeasureMatrix(singleton(project), asList(statusMetric, detailsMetric, numericMetric, numericNewMetric, stringMetric), asList(numericMeasure, numericNewMeasure, stringMeasure));
    underTest.refreshGateStatus(project, gate, matrix, configuration);
    QualityGateEvaluator.Measures measures = qualityGateEvaluator.getCalledMeasures();
    QualityGateEvaluator.Measure loadedStringMeasure = measures.get(stringMetric.getKey()).get();
    assertThat(loadedStringMeasure.getStringValue()).hasValue("bar");
    assertThat(loadedStringMeasure.getValue()).isEmpty();
    assertThat(loadedStringMeasure.getType()).isEqualTo(Metric.ValueType.STRING);
    QualityGateEvaluator.Measure loadedNumericMeasure = measures.get(numericMetric.getKey()).get();
    assertThat(loadedNumericMeasure.getStringValue()).isEmpty();
    assertThat(loadedNumericMeasure.getValue()).hasValue(1.23);
    assertThat(loadedNumericMeasure.getType()).isEqualTo(Metric.ValueType.FLOAT);
    QualityGateEvaluator.Measure loadedNumericNewMeasure = measures.get(numericNewMetric.getKey()).get();
    assertThat(loadedNumericNewMeasure.getStringValue()).isEmpty();
    assertThat(loadedNumericNewMeasure.getNewMetricValue()).hasValue(8.9);
    assertThat(loadedNumericNewMeasure.getType()).isEqualTo(Metric.ValueType.FLOAT);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) QualityGateEvaluator(org.sonar.server.qualitygate.QualityGateEvaluator) QualityGate(org.sonar.server.qualitygate.QualityGate) EvaluatedQualityGate(org.sonar.server.qualitygate.EvaluatedQualityGate) Test(org.junit.Test)

Aggregations

LiveMeasureDto (org.sonar.db.measure.LiveMeasureDto)48 Test (org.junit.Test)29 MetricDto (org.sonar.db.metric.MetricDto)26 ComponentDto (org.sonar.db.component.ComponentDto)15 SnapshotDto (org.sonar.db.component.SnapshotDto)10 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)9 UserRole (org.sonar.api.web.UserRole)8 DbSession (org.sonar.db.DbSession)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Assertions.tuple (org.assertj.core.api.Assertions.tuple)7 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)7 NotFoundException (org.sonar.server.exceptions.NotFoundException)7 Common (org.sonarqube.ws.Common)7 Double.parseDouble (java.lang.Double.parseDouble)6 String.format (java.lang.String.format)6 Map (java.util.Map)6 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)6 Rule (org.junit.Rule)6 Param (org.sonar.api.server.ws.WebService.Param)6 DbClient (org.sonar.db.DbClient)6