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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations