Search in sources :

Example 41 with MeasureDto

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

the class MeasureDtoToMeasureTest method toMeasure_for_LEVEL_Metric_ignores_data.

@Test(expected = IllegalStateException.class)
public void toMeasure_for_LEVEL_Metric_ignores_data() {
    MeasureDto measureDto = new MeasureDto().setAlertStatus(Level.ERROR.name()).setData(SOME_DATA);
    Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_LEVEL_METRIC);
    assertThat(measure).isPresent();
    measure.get().getStringValue();
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test)

Example 42 with MeasureDto

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

the class MeasureDtoToMeasureTest method toMeasure_maps_alert_properties_in_dto_for_String_Metric.

@Test
public void toMeasure_maps_alert_properties_in_dto_for_String_Metric() {
    MeasureDto measureDto = new MeasureDto().setData(SOME_DATA).setAlertStatus(Level.OK.name()).setAlertText(SOME_ALERT_TEXT);
    Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_STRING_METRIC);
    assertThat(measure.isPresent()).isTrue();
    assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.STRING);
    assertThat(measure.get().getStringValue()).isEqualTo(SOME_DATA);
    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 43 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_Int_Metric.

@Test
public void toMeasure_maps_data_and_alert_properties_in_dto_for_Int_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_INT_METRIC);
    assertThat(measure.isPresent()).isTrue();
    assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.INT);
    assertThat(measure.get().getIntValue()).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 44 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_Boolean_metric.

@Test
public void toMeasure_maps_data_and_alert_properties_in_dto_for_Boolean_metric() {
    MeasureDto measureDto = new MeasureDto().setValue(1d).setData(SOME_DATA).setAlertStatus(Level.OK.name()).setAlertText(SOME_ALERT_TEXT);
    Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_BOOLEAN_METRIC);
    assertThat(measure.isPresent()).isTrue();
    assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN);
    assertThat(measure.get().getBooleanValue()).isTrue();
    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 45 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