Search in sources :

Example 56 with MeasureDto

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

the class PersistMeasuresStepTest 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 = execute();
    MeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get();
    assertThat(persistedMeasure.getValue()).isNull();
    assertThat(persistedMeasure.getVariation()).isEqualTo(42.0);
    assertNbOfInserts(context, 1);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MeasureToMeasureDto(org.sonar.ce.task.projectanalysis.measure.MeasureToMeasureDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 57 with MeasureDto

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

the class MeasureToMeasureDtoTest method toMeasureDto_returns_Dto_with_alertStatus_and_alertText_if_Measure_has_QualityGateStatus.

@Test
public void toMeasureDto_returns_Dto_with_alertStatus_and_alertText_if_Measure_has_QualityGateStatus() {
    String alertText = "some error";
    MeasureDto measureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(Measure.Level.ERROR, alertText)).create(SOME_STRING), SOME_STRING_METRIC, SOME_COMPONENT);
    assertThat(measureDto.getAlertStatus()).isEqualTo(Measure.Level.ERROR.name());
    assertThat(measureDto.getAlertText()).isEqualTo(alertText);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test)

Example 58 with MeasureDto

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

the class MeasureToMeasureDtoTest method toMeasureDto_maps_name_of_Level_to_data_and_has_no_value_for_LEVEL_metric.

@Test
public void toMeasureDto_maps_name_of_Level_to_data_and_has_no_value_for_LEVEL_metric() {
    MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(Measure.Level.OK), SOME_LEVEL_METRIC, SOME_COMPONENT);
    assertThat(trueMeasureDto.getValue()).isNull();
    assertThat(trueMeasureDto.getData()).isEqualTo(Measure.Level.OK.name());
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test)

Example 59 with MeasureDto

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

the class MeasureToMeasureDtoTest method toMeasureDto_maps_value_and_data_from_data_field_for_DOUBLE_metric.

@Test
public void toMeasureDto_maps_value_and_data_from_data_field_for_DOUBLE_metric() {
    MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(789, 1, SOME_DATA), SOME_DOUBLE_METRIC, SOME_COMPONENT);
    assertThat(trueMeasureDto.getValue()).isEqualTo(789);
    assertThat(trueMeasureDto.getData()).isEqualTo(SOME_DATA);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test)

Example 60 with MeasureDto

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

the class MeasureToMeasureDtoTest method toMeasureDto_set_componentId_and_snapshotId_from_method_arguments.

@Test
@UseDataProvider("all_types_Measures")
public void toMeasureDto_set_componentId_and_snapshotId_from_method_arguments(Measure measure, Metric metric) {
    MeasureDto measureDto = underTest.toMeasureDto(measure, metric, SOME_COMPONENT);
    assertThat(measureDto.getComponentUuid()).isEqualTo(SOME_COMPONENT.getUuid());
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

MeasureDto (org.sonar.db.measure.MeasureDto)67 Test (org.junit.Test)51 LiveMeasureDto (org.sonar.db.measure.LiveMeasureDto)15 SnapshotDto (org.sonar.db.component.SnapshotDto)12 MetricDto (org.sonar.db.metric.MetricDto)12 ComponentDto (org.sonar.db.component.ComponentDto)8 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)7 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)6 DbSession (org.sonar.db.DbSession)6 MeasureQuery (org.sonar.db.measure.MeasureQuery)6 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)3 Double.parseDouble (java.lang.Double.parseDouble)2 String.format (java.lang.String.format)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Optional.ofNullable (java.util.Optional.ofNullable)2 LongStream (java.util.stream.LongStream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2