use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class LiveMeasureDtoToMeasureTest method toMeasure_should_not_loose_decimals_of_float_values.
@Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
LiveMeasureDto LiveMeasureDto = new LiveMeasureDto().setValue(0.12345);
Optional<Measure> measure = underTest.toMeasure(LiveMeasureDto, metric);
assertThat(measure.get().getDoubleValue()).isEqualTo(0.12345, Offset.offset(0.000001));
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class PersistLiveMeasuresStepTest method measures_on_new_code_period_are_persisted.
@Test
public void measures_on_new_code_period_are_persisted() {
prepareProject();
measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().setVariation(42.0).createNoValue());
TestComputationStepContext context = new TestComputationStepContext();
step().execute(context);
LiveMeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get();
assertThat(persistedMeasure.getValue()).isNull();
assertThat(persistedMeasure.getVariation()).isEqualTo(42.0);
verifyStatistics(context, 1);
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class PersistLiveMeasuresStepTest method insertMeasure.
private LiveMeasureDto insertMeasure(String componentUuid, String projectUuid, Metric metric) {
LiveMeasureDto measure = newLiveMeasure().setComponentUuid(componentUuid).setProjectUuid(projectUuid).setMetricUuid(metricRepository.getByKey(metric.getKey()).getUuid());
dbClient.liveMeasureDao().insertOrUpdate(db.getSession(), measure);
return measure;
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class PersistLiveMeasuresStepTest method do_not_persist_file_measures_with_best_value.
@Test
public void do_not_persist_file_measures_with_best_value() {
prepareProject();
// measure to be deleted because new value matches the metric best value
LiveMeasureDto oldMeasure = insertMeasure("file-uuid", "project-uuid", INT_METRIC);
db.commit();
// project measure with metric best value -> persist with value 0
measureRepository.addRawMeasure(REF_1, METRIC_WITH_BEST_VALUE.getKey(), newMeasureBuilder().create(0));
// file measure with metric best value -> do not persist
measureRepository.addRawMeasure(REF_4, METRIC_WITH_BEST_VALUE.getKey(), newMeasureBuilder().create(0));
TestComputationStepContext context = new TestComputationStepContext();
step().execute(context);
assertThatMeasureDoesNotExist(oldMeasure);
assertThatMeasureHasValue("project-uuid", METRIC_WITH_BEST_VALUE, 0);
verifyStatistics(context, 1);
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class PersistLiveMeasuresStepTest method delete_measures_from_db_if_no_longer_computed.
@Test
public void delete_measures_from_db_if_no_longer_computed() {
prepareProject();
// measure to be updated
LiveMeasureDto measureOnFileInProject = insertMeasure("file-uuid", "project-uuid", INT_METRIC);
// measure to be deleted because not computed anymore
LiveMeasureDto otherMeasureOnFileInProject = insertMeasure("file-uuid", "project-uuid", STRING_METRIC);
// measure in another project, not touched
LiveMeasureDto measureInOtherProject = insertMeasure("other-file-uuid", "other-project-uuid", INT_METRIC);
db.commit();
measureRepository.addRawMeasure(REF_4, INT_METRIC.getKey(), newMeasureBuilder().create(42));
TestComputationStepContext context = new TestComputationStepContext();
step().execute(context);
assertThatMeasureHasValue(measureOnFileInProject, 42);
assertThatMeasureDoesNotExist(otherMeasureOnFileInProject);
assertThatMeasureHasValue(measureInOtherProject, (int) measureInOtherProject.getValue().doubleValue());
verifyStatistics(context, 1);
}
Aggregations