Revision 9b8a8049
Added by Andreas Müller over 2 years ago
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/description/StructuredDescriptionAggregationTest.java | ||
---|---|---|
308 | 308 |
datasetService.save(dataSet); |
309 | 309 |
|
310 | 310 |
SpecimenDescription specDescAlpina1 = createSpecimenDescription(dataSet, T_LAPSANA_COMMUNIS_ALPINA_UUID, "alpina specimen1", T_LAPSANA_COMMUNIS_ALPINA_SPEC1_UUID); |
311 |
//create empty categorical data |
|
311 | 312 |
addCategoricalData(specDescAlpina1, uuidFeatureLeafColor, null); |
312 | 313 |
|
313 | 314 |
TaxonNode tnLapsana = taxonNodeService.find(TN_LAPSANA_UUID); |
... | ... | |
321 | 322 |
|
322 | 323 |
//aggregate |
323 | 324 |
StructuredDescriptionAggregationConfiguration config = createConfig(dataSet); |
324 |
|
|
325 | 325 |
UpdateResult result = engine.invoke(config, repository); |
326 |
verifyStatusOk(result); |
|
327 | 326 |
|
327 |
//test aggregation with categorical data without states (empty categorical data) |
|
328 |
verifyStatusOk(result); |
|
328 | 329 |
Taxon taxLapsanaCommunisAlpina = (Taxon)taxonService.find(T_LAPSANA_COMMUNIS_ALPINA_UUID); |
330 |
//if no state at all exists in description even the description is not created (this was different before but changed with xxx) |
|
331 |
verifyNumberTaxonDescriptions(taxLapsanaCommunisAlpina, 0); |
|
332 |
|
|
333 |
//add data for another feature |
|
334 |
specDescAlpina1 = (SpecimenDescription)descriptionService.find(specDescAlpina1.getUuid()); |
|
335 |
addCategoricalData(specDescAlpina1, uuidFeatureLeafPA, State.uuidPresent); |
|
336 |
commitAndStartNewTransaction(); |
|
337 |
result = engine.invoke(config, repository); |
|
338 |
verifyStatusOk(result); |
|
339 |
taxLapsanaCommunisAlpina = (Taxon)taxonService.find(T_LAPSANA_COMMUNIS_ALPINA_UUID); |
|
329 | 340 |
TaxonDescription aggrDescLapsanaCommunisAlpina = verifyTaxonDescriptions(taxLapsanaCommunisAlpina, 1); |
341 |
verifyNumberDescriptionElements(aggrDescLapsanaCommunisAlpina, uuidFeatureLeafColor, 0); |
|
342 |
// List<StateData> sdAlpinaLeafColor = verifyCategoricalData(uuidFeatureLeafColor, 0, aggrDescLapsanaCommunisAlpina, false); |
|
343 |
// verifyState(sdAlpinaLeafColor, uuidLeafColorBlue, 0); |
|
344 |
// verifyState(sdAlpinaLeafColor, uuidLeafColorYellow, 0); |
|
345 |
|
|
346 |
//test duplicates |
|
347 |
specDescAlpina1 = (SpecimenDescription)descriptionService.find(specDescAlpina1.getUuid()); |
|
348 |
addCategoricalData(specDescAlpina1, uuidFeatureLeafColor, uuidLeafColorBlue); |
|
349 |
addCategoricalData(specDescAlpina1, uuidFeatureLeafColor, uuidLeafColorBlue); |
|
350 |
commitAndStartNewTransaction(); |
|
351 |
result = engine.invoke(config, repository); |
|
352 |
|
|
353 |
verifyStatusOk(result); |
|
354 |
taxLapsanaCommunisAlpina = (Taxon)taxonService.find(T_LAPSANA_COMMUNIS_ALPINA_UUID); |
|
355 |
aggrDescLapsanaCommunisAlpina = verifyTaxonDescriptions(taxLapsanaCommunisAlpina, 2); //for leafPA and for color |
|
330 | 356 |
List<StateData> sdAlpinaLeafColor = verifyCategoricalData(uuidFeatureLeafColor, 1, aggrDescLapsanaCommunisAlpina, false); |
331 |
verifyState(sdAlpinaLeafColor, uuidLeafColorBlue, 0);
|
|
357 |
verifyState(sdAlpinaLeafColor, uuidLeafColorBlue, 2);
|
|
332 | 358 |
verifyState(sdAlpinaLeafColor, uuidLeafColorYellow, 0); |
359 |
|
|
333 | 360 |
} |
334 | 361 |
|
335 | 362 |
@Test |
... | ... | |
700 | 727 |
return dataSet; |
701 | 728 |
} |
702 | 729 |
|
703 |
private TaxonDescription verifyTaxonDescriptions(Taxon taxon, int elementSize){
|
|
704 |
List<TaxonDescription> taxonDescriptions = taxon.getDescriptions().stream()
|
|
730 |
private TaxonDescription verifyTaxonDescriptions(Taxon taxon, int elementCount){
|
|
731 |
List<TaxonDescription> aggrNonCloneTaxonDescriptions = taxon.getDescriptions().stream()
|
|
705 | 732 |
.filter(desc->desc.getTypes().contains(DescriptionType.AGGREGATED_STRUC_DESC)) |
706 | 733 |
.filter(desc->!desc.getTypes().contains(DescriptionType.CLONE_FOR_SOURCE)) |
707 | 734 |
.collect(Collectors.toList()); |
708 | 735 |
|
709 |
Assert.assertEquals(1, taxonDescriptions.size());
|
|
710 |
TaxonDescription aggrDesc = taxonDescriptions.iterator().next();
|
|
736 |
Assert.assertEquals(1, aggrNonCloneTaxonDescriptions.size());
|
|
737 |
TaxonDescription aggrDesc = aggrNonCloneTaxonDescriptions.iterator().next();
|
|
711 | 738 |
Set<DescriptionElementBase> elements = aggrDesc.getElements(); |
712 |
Assert.assertEquals(elementSize, elements.size());
|
|
739 |
Assert.assertEquals(elementCount, elements.size());
|
|
713 | 740 |
return aggrDesc; |
714 | 741 |
} |
715 | 742 |
|
743 |
private void verifyNumberTaxonDescriptions(Taxon taxon, long descriptionCount){ |
|
744 |
long n = taxon.getDescriptions().stream() |
|
745 |
.filter(desc->desc.getTypes().contains(DescriptionType.AGGREGATED_STRUC_DESC)) |
|
746 |
.filter(desc->!desc.getTypes().contains(DescriptionType.CLONE_FOR_SOURCE)).count(); |
|
747 |
Assert.assertEquals(descriptionCount, n); |
|
748 |
} |
|
749 |
|
|
750 |
private void verifyNumberDescriptionElements(DescriptionBase<?> description, UUID featureUuid, long elementCount){ |
|
751 |
long n = description.getElements().stream() |
|
752 |
.filter(element->element.getFeature().getUuid().equals(featureUuid)) |
|
753 |
.map(catData->CdmBase.deproxy(catData, CategoricalData.class)) |
|
754 |
.count(); |
|
755 |
Assert.assertEquals(elementCount, n); |
|
756 |
} |
|
757 |
|
|
716 | 758 |
private void verifyQuantitativeData(UUID featureUuid, BigDecimal sampleSize, BigDecimal min, |
717 | 759 |
BigDecimal max, BigDecimal avg, TaxonDescription aggrDesc) { |
718 | 760 |
List<QuantitativeData> quantitativeDatas = aggrDesc.getElements().stream() |
Also available in: Unified diff
ref #9804 improve handling for empty categorical data (empty or null value state data)