use of eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetServiceTest method testGetRowWrapper.
// the tesat fails when running in suite because no dataset is available, running the test in eclipse works as expected.
@Ignore
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet(value = "/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"), @DataSet(value = "StructuredDescriptionAggregationTest.xml") })
public void testGetRowWrapper() {
createDefaultFeatureTree();
DescriptiveDataSet dataSet = createTestDataset();
commitAndStartNewTransaction();
List<RowWrapperDTO<?>> rowWrappers = datasetService.getRowWrapper(dataSet.getUuid(), monitor);
// There are 4 specimen descriptions and one literature description (taxon association)
assertTrue(rowWrappers.size() == 5);
// check rowWrapper
// specimen_1 2 categorical and 1 quantitative
List<SpecimenRowWrapperDTO> alpinaSpec1List = rowWrappers.stream().filter(r -> r instanceof SpecimenRowWrapperDTO).map(r -> (SpecimenRowWrapperDTO) r).filter(s -> s.getSpecimenDto().getLabel().equals("alpina specimen1")).collect(Collectors.toList());
Assert.assertEquals(1, alpinaSpec1List.size());
SpecimenRowWrapperDTO alpinaSpec1Dto = alpinaSpec1List.get(0);
// leafColor
Set<DescriptionElementDto> leafColorElements = alpinaSpec1Dto.getDataValueForFeature(uuidFeatureLeafColor);
Assert.assertNotNull(leafColorElements);
Assert.assertTrue(leafColorElements.size() == 1);
DescriptionElementDto dto = leafColorElements.iterator().next();
Assert.assertTrue(dto instanceof CategoricalDataDto);
CategoricalDataDto cDto = (CategoricalDataDto) dto;
assertTrue("The states should contain one element", cDto.getStates().size() == 1);
StateDataDto stateData = cDto.getStates().iterator().next();
assertEquals(uuidLeafColorBlue, stateData.getState().getUuid());
// leaf length
Set<DescriptionElementDto> leafLengthElements = alpinaSpec1Dto.getDataValueForFeature(uuidFeatureLeafLength);
Assert.assertNotNull(leafLengthElements);
Assert.assertTrue(leafLengthElements.size() == 1);
dto = leafLengthElements.iterator().next();
Assert.assertTrue(dto instanceof QuantitativeDataDto);
QuantitativeDataDto qDto = (QuantitativeDataDto) dto;
assertTrue("The statistical values should contain one element", qDto.getValues().size() == 1);
StatisticalMeasurementValueDto statValue = qDto.getValues().iterator().next();
assertEquals(new BigDecimal("5.0"), statValue.getValue());
Set<DescriptionElementDto> leafPAElements = alpinaSpec1Dto.getDataValueForFeature(uuidFeatureLeafPA);
Assert.assertNotNull(leafPAElements);
Assert.assertTrue(leafPAElements.size() == 1);
dto = leafPAElements.iterator().next();
Assert.assertTrue(dto instanceof CategoricalDataDto);
cDto = (CategoricalDataDto) dto;
assertTrue("The statistical values should contain one element", cDto.getStates().size() == 1);
stateData = cDto.getStates().iterator().next();
assertEquals(State.uuidPresent, stateData.getState().getUuid());
// taxon descriptions
List<TaxonRowWrapperDTO> taxonDescList = rowWrappers.stream().filter(r -> r instanceof TaxonRowWrapperDTO).map(r -> (TaxonRowWrapperDTO) r).collect(Collectors.toList());
Assert.assertEquals(1, taxonDescList.size());
// .filter(s->s.getTaxonDto().getLabel().equals("alpina specimen1")).collect(Collectors.toList());
TaxonRowWrapperDTO taxonDto = taxonDescList.get(0);
leafLengthElements = taxonDto.getDataValueForFeature(uuidFeatureLeafLength);
Assert.assertNotNull(leafLengthElements);
Assert.assertTrue(leafLengthElements.size() == 1);
dto = leafLengthElements.iterator().next();
Assert.assertTrue(dto instanceof QuantitativeDataDto);
qDto = (QuantitativeDataDto) dto;
assertTrue("The statistical values should contain one element", qDto.getValues().size() == 2);
List<StatisticalMeasurementValueDto> minList = qDto.getValues().stream().filter(vs -> vs.getValue().equals(new BigDecimal("4.5"))).collect(Collectors.toList());
Assert.assertEquals(1, minList.size());
TermDto minDtoType = minList.get(0).getType();
Assert.assertTrue(minDtoType.getUuid().equals(StatisticalMeasure.MIN().getUuid()));
Assert.assertTrue(minDtoType.getTermType().equals(TermType.StatisticalMeasure));
}
Aggregations