Search in sources :

Example 51 with MeasureDto

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

the class ExportMeasuresStepTest method test_null_exported_fields.

@Test
public void test_null_exported_fields() {
    SnapshotDto analysis = insertSnapshot("U_1", PROJECT, STATUS_PROCESSED);
    insertMeasure(analysis, PROJECT, new MeasureDto().setMetricUuid(NCLOC.getUuid()));
    dbTester.commit();
    underTest.execute(new TestComputationStepContext());
    ProjectDump.Measure measure = dumpWriter.getWrittenMessagesOf(DumpElement.MEASURES).get(0);
    assertThat(measure.getAlertStatus()).isEmpty();
    assertThat(measure.getAlertText()).isEmpty();
    assertThat(measure.hasDoubleValue()).isFalse();
    assertThat(measure.getTextValue()).isEmpty();
    assertThat(measure.hasVariation1()).isFalse();
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) SnapshotDto(org.sonar.db.component.SnapshotDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 52 with MeasureDto

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

the class ExportMeasuresStepTest method do_not_export_measures_on_disabled_metrics.

@Test
public void do_not_export_measures_on_disabled_metrics() {
    SnapshotDto firstAnalysis = insertSnapshot("U_1", PROJECT, STATUS_PROCESSED);
    insertMeasure(firstAnalysis, PROJECT, new MeasureDto().setValue(100.0).setMetricUuid(DISABLED_METRIC.getUuid()));
    dbTester.commit();
    underTest.execute(new TestComputationStepContext());
    List<ProjectDump.Measure> exportedMeasures = dumpWriter.getWrittenMessagesOf(DumpElement.MEASURES);
    assertThat(exportedMeasures).isEmpty();
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) SnapshotDto(org.sonar.db.component.SnapshotDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 53 with MeasureDto

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

the class ExportMeasuresStepTest method test_exported_fields.

@Test
public void test_exported_fields() {
    SnapshotDto analysis = insertSnapshot("U_1", PROJECT, STATUS_PROCESSED);
    MeasureDto dto = new MeasureDto().setMetricUuid(NCLOC.getUuid()).setValue(100.0).setData("data").setAlertStatus("OK").setAlertText("alert text").setVariation(1.0);
    insertMeasure(analysis, PROJECT, dto);
    dbTester.commit();
    underTest.execute(new TestComputationStepContext());
    List<ProjectDump.Measure> exportedMeasures = dumpWriter.getWrittenMessagesOf(DumpElement.MEASURES);
    ProjectDump.Measure measure = exportedMeasures.get(0);
    assertThat(measure.getAlertStatus()).isEqualTo(dto.getAlertStatus());
    assertThat(measure.getAlertText()).isEqualTo(dto.getAlertText());
    assertThat(measure.getDoubleValue().getValue()).isEqualTo(dto.getValue());
    assertThat(measure.getTextValue()).isEqualTo(dto.getData());
    assertThat(measure.getMetricRef()).isZero();
    assertThat(measure.getAnalysisUuid()).isEqualTo(analysis.getUuid());
    assertThat(measure.getVariation1().getValue()).isEqualTo(dto.getVariation());
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) SnapshotDto(org.sonar.db.component.SnapshotDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 54 with MeasureDto

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

the class ExportMeasuresStepTest method do_not_export_measures_on_unprocessed_snapshots.

@Test
public void do_not_export_measures_on_unprocessed_snapshots() {
    SnapshotDto firstAnalysis = insertSnapshot("U_1", PROJECT, STATUS_UNPROCESSED);
    insertMeasure(firstAnalysis, PROJECT, new MeasureDto().setValue(100.0).setMetricUuid(NCLOC.getUuid()));
    dbTester.commit();
    underTest.execute(new TestComputationStepContext());
    List<ProjectDump.Measure> exportedMeasures = dumpWriter.getWrittenMessagesOf(DumpElement.MEASURES);
    assertThat(exportedMeasures).isEmpty();
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) SnapshotDto(org.sonar.db.component.SnapshotDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 55 with MeasureDto

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

the class PersistMeasuresStepTest method measures_on_non_historical_metrics_are_not_persisted.

@Test
public void measures_on_non_historical_metrics_are_not_persisted() {
    prepareProject();
    measureRepository.addRawMeasure(REF_1, NON_HISTORICAL_METRIC.getKey(), newMeasureBuilder().create(1));
    measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().create(2));
    TestComputationStepContext context = execute();
    assertThatMeasureIsNotPersisted("project-uuid", NON_HISTORICAL_METRIC);
    MeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get();
    assertThat(persistedMeasure.getValue()).isEqualTo(2);
    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)

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