@Test public void insert_measures_from_report() { metricRepository.add(1, STRING_METRIC); metricRepository.add(2, DOUBLE_METRIC); reportReader.putMeasures( PROJECT_REF, Arrays.asList( BatchReport.Measure.newBuilder() .setValueType(MeasureValueType.STRING) .setStringValue("measure-data") .setVariationValue1(1.1d) .setVariationValue2(2.2d) .setVariationValue3(3.3d) .setVariationValue4(4.4d) .setVariationValue5(5.5d) .setDescription("measure-description") .setMetricKey(STRING_METRIC_KEY) .build())); reportReader.putMeasures( FILE_REF, Arrays.asList( BatchReport.Measure.newBuilder() .setValueType(MeasureValueType.DOUBLE) .setDoubleValue(123.123d) .setVariationValue1(1.1d) .setVariationValue2(2.2d) .setVariationValue3(3.3d) .setVariationValue4(4.4d) .setVariationValue5(5.5d) .setDescription("measure-description") .setMetricKey(DOUBLE_METRIC_KEY) .build())); sut.execute(); session.commit(); assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(2); List<Map<String, Object>> dtos = retrieveDtos(); Map<String, Object> dto = dtos.get(0); assertThat(dto.get("snapshotId")).isEqualTo(3L); assertThat(dto.get("componentId")).isEqualTo(projectDto.getId()); assertThat(dto.get("metricId")).isEqualTo(1L); assertThat(dto.get("textValue")).isEqualTo("measure-data"); assertThat(dto.get("severity")).isNull(); dto = dtos.get(PROJECT_REF); assertThat(dto.get("snapshotId")).isEqualTo(4L); assertThat(dto.get("componentId")).isEqualTo(fileDto.getId()); assertThat(dto.get("metricId")).isEqualTo(2L); assertThat(dto.get("value")).isEqualTo(123.1d); assertThat(dto.get("severity")).isNull(); }
@Test(expected = IllegalStateException.class) public void fail_with_ISE_when_trying_to_insert_forbidden_measures() { metricRepository.add(1, DUPLICATIONS_DATA); reportReader.putMeasures( FILE_REF, Arrays.asList( BatchReport.Measure.newBuilder() .setValueType(MeasureValueType.STRING) .setStringValue("{duplications}") .setMetricKey(DUPLICATIONS_DATA_KEY) .build())); sut.execute(); }
@Test public void empty_values_are_not_persisted() { metricRepository.add(1, STRING_METRIC); metricRepository.add(2, DOUBLE_METRIC); reportReader.putMeasures( FILE_REF, Arrays.asList( BatchReport.Measure.newBuilder() .setValueType(MeasureValueType.STRING) .setMetricKey(STRING_METRIC_KEY) .build(), BatchReport.Measure.newBuilder() .setValueType(MeasureValueType.DOUBLE) .setMetricKey(DOUBLE_METRIC_KEY) .build())); sut.execute(); session.commit(); assertThat(retrieveDtos()).isEmpty(); }
@Test public void bestValue_measure_of_bestValueOptimized_metrics_are_not_persisted() { metricRepository.add( 1, new Metric.Builder(OPTIMIZED_METRIC_KEY, "Optimized metric", Metric.ValueType.BOOL) .setOptimizedBestValue(true) .setBestValue(1d) .create()); reportReader.putMeasures( FILE_REF, Arrays.asList( BatchReport.Measure.newBuilder() .setValueType(MeasureValueType.BOOLEAN) .setBooleanValue(true) .setMetricKey(OPTIMIZED_METRIC_KEY) .build())); sut.execute(); session.commit(); assertThat(retrieveDtos()).isEmpty(); }
@Test public void do_not_insert_function_complexity_distribution_metric_on_files() { metricRepository.add(1, FUNCTION_COMPLEXITY_DISTRIBUTION); reportReader.putMeasures( PROJECT_REF, Arrays.asList( BatchReport.Measure.newBuilder() .setValueType(MeasureValueType.STRING) .setStringValue("0=1;2=10") .setMetricKey(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY) .build())); // Should not be persisted reportReader.putMeasures( FILE_REF, Arrays.asList( BatchReport.Measure.newBuilder() .setValueType(MeasureValueType.STRING) .setStringValue("0=1;2=10") .setMetricKey(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY) .build())); sut.execute(); session.commit(); assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1); List<Map<String, Object>> dtos = retrieveDtos(); Map<String, Object> dto = dtos.get(0); assertThat(dto.get("snapshotId")).isEqualTo(3L); assertThat(dto.get("componentId")).isEqualTo(projectDto.getId()); assertThat(dto.get("textValue")).isEqualTo("0=1;2=10"); }
private void assertVariation(Component component, String metricKey, int variation) { Measure newMeasure = measureRepository.getRawMeasure(component, metricRepository.getByKey(metricKey)).get(); assertThat(newMeasure.getVariations().getVariation(PERIOD.getIndex())).isEqualTo(variation); assertThat(newMeasure.getVariations().hasVariation(PERIOD.getIndex() + 1)).isFalse(); }