Search in sources :

Example 1 with LiveMeasureDto

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));
}
Also used : MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test)

Example 2 with LiveMeasureDto

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);
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 3 with LiveMeasureDto

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;
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto)

Example 4 with LiveMeasureDto

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);
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 5 with LiveMeasureDto

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);
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) 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