Search in sources :

Example 61 with MeasureDto

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

the class MeasureToMeasureDtoTest method toMeasureDto_maps_to_only_data_for_STRING_metric.

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

Example 62 with MeasureDto

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

the class MeasureToMeasureDtoTest method toMeasureDto_returns_Dto_without_any_variation_if_Measure_has_no_MeasureVariations.

@Test
@UseDataProvider("all_types_Measures")
public void toMeasureDto_returns_Dto_without_any_variation_if_Measure_has_no_MeasureVariations(Measure measure, Metric metric) {
    MeasureDto measureDto = underTest.toMeasureDto(measure, metric, SOME_COMPONENT);
    assertThat(measureDto.getVariation()).isNull();
}
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)

Example 63 with MeasureDto

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

the class MeasureDtoToMeasureTest method toMeasure_maps_data_and_alert_properties_in_dto_for_Long_Metric.

@Test
public void toMeasure_maps_data_and_alert_properties_in_dto_for_Long_Metric() {
    MeasureDto measureDto = new MeasureDto().setValue(10d).setData(SOME_DATA).setAlertStatus(Level.OK.name()).setAlertText(SOME_ALERT_TEXT);
    Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_LONG_METRIC);
    assertThat(measure).isPresent();
    assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG);
    assertThat(measure.get().getLongValue()).isEqualTo(10);
    assertThat(measure.get().getData()).isEqualTo(SOME_DATA);
    assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.OK);
    assertThat(measure.get().getQualityGateStatus().getText()).isEqualTo(SOME_ALERT_TEXT);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test)

Example 64 with MeasureDto

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

the class MeasureDtoToMeasureTest 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);
    MeasureDto measureDto = new MeasureDto().setValue(0.12345);
    Optional<Measure> measure = underTest.toMeasure(measureDto, metric);
    assertThat(measure.get().getDoubleValue()).isEqualTo(0.12345, Offset.offset(0.000001));
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MetricImpl(org.sonar.ce.task.projectanalysis.metric.MetricImpl) Test(org.junit.Test)

Example 65 with MeasureDto

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

the class MeasureDtoToMeasureTest method toMeasure_for_LEVEL_Metric_can_have_an_qualityGateStatus.

@Test
public void toMeasure_for_LEVEL_Metric_can_have_an_qualityGateStatus() {
    MeasureDto measureDto = new MeasureDto().setData(Level.OK.name()).setAlertStatus(Level.ERROR.name()).setAlertText(SOME_ALERT_TEXT);
    Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_LEVEL_METRIC);
    assertThat(measure).isPresent();
    assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LEVEL);
    assertThat(measure.get().getLevelValue()).isEqualTo(Level.OK);
    assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.ERROR);
    assertThat(measure.get().getQualityGateStatus().getText()).isEqualTo(SOME_ALERT_TEXT);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test)

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