Revision 59174ab0
Added by Andreas Müller over 3 years ago
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImplTest.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.api.service; |
11 | 11 |
|
12 | 12 |
import static org.junit.Assert.assertEquals; |
13 |
import static org.junit.Assert.assertNotNull; |
|
13 | 14 |
import static org.junit.Assert.assertNull; |
15 |
import static org.junit.Assert.assertTrue; |
|
14 | 16 |
|
15 | 17 |
import java.io.FileNotFoundException; |
16 | 18 |
import java.util.ArrayList; |
... | ... | |
20 | 22 |
import java.util.List; |
21 | 23 |
import java.util.Set; |
22 | 24 |
import java.util.UUID; |
25 |
import java.util.stream.Collectors; |
|
23 | 26 |
|
24 | 27 |
import org.apache.commons.lang.StringUtils; |
25 | 28 |
import org.apache.log4j.Logger; |
... | ... | |
29 | 32 |
import org.unitils.dbunit.annotation.DataSet; |
30 | 33 |
import org.unitils.spring.annotation.SpringBeanByType; |
31 | 34 |
|
35 |
import eu.etaxonomy.cdm.api.service.config.SubtreeCloneConfigurator; |
|
32 | 36 |
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO; |
33 | 37 |
import eu.etaxonomy.cdm.model.name.IBotanicalName; |
34 | 38 |
import eu.etaxonomy.cdm.model.name.Rank; |
... | ... | |
39 | 43 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
40 | 44 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
41 | 45 |
import eu.etaxonomy.cdm.model.taxon.TaxonNodeByNameComparator; |
46 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
|
42 | 47 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
43 | 48 |
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao; |
44 | 49 |
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao; |
... | ... | |
288 | 293 |
Assert.assertFalse(StringUtils.isBlank(result.get(2).getGroupTaxonName())); |
289 | 294 |
} |
290 | 295 |
|
291 |
|
|
292 | 296 |
@Test |
293 | 297 |
@DataSet |
294 | 298 |
public final void testCloneClassification(){ |
295 |
Classification classification = classificationDao.load(CLASSIFICATION_UUID); |
|
296 |
Reference sec = ReferenceFactory.newGeneric(); |
|
297 |
sec.setTitle("cloned sec"); |
|
298 |
Classification clone = (Classification) classificationService.cloneClassification(CLASSIFICATION_UUID, "Cloned classification", sec, TaxonRelationshipType.CONGRUENT_TO()).getCdmEntity(); |
|
299 |
|
|
300 |
List<TaxonNode> childNodes = classification.getChildNodes(); |
|
301 |
for (TaxonNode taxonNode : childNodes) { |
|
302 |
System.out.println(taxonNode.getTaxon().getTitleCache()); |
|
303 |
} |
|
304 |
childNodes = clone.getChildNodes(); |
|
305 |
for (TaxonNode taxonNode : childNodes) { |
|
306 |
System.out.println(taxonNode.getTaxon().getTitleCache()); |
|
307 |
} |
|
308 |
Set<TaxonNode> allNodes = classification.getAllNodes(); |
|
309 |
assertEquals("# of direct children does not match", classification.getChildNodes().size(), clone.getChildNodes().size()); |
|
310 |
assertEquals("# of all nodes does not match", allNodes.size(), clone.getAllNodes().size()); |
|
311 | 299 |
|
312 |
//check that original taxon does not appear in cloned classification |
|
313 |
for (TaxonNode taxonNode : allNodes) { |
|
314 |
assertNull(clone.getNode(taxonNode.getTaxon())); |
|
300 |
Classification originalClassification = classificationDao.load(CLASSIFICATION_UUID); |
|
301 |
|
|
302 |
SubtreeCloneConfigurator config = SubtreeCloneConfigurator.NewBaseInstance( |
|
303 |
originalClassification.getRootNode().getUuid(), "Cloned classification"); |
|
304 |
|
|
305 |
Classification classificatonClone = (Classification) classificationService.cloneClassification(config).getCdmEntity(); |
|
306 |
|
|
307 |
assertEquals("# of direct children does not match", originalClassification.getChildNodes().size(), classificatonClone.getChildNodes().size()); |
|
308 |
assertEquals("# of all nodes does not match", originalClassification.getAllNodes().size(), classificatonClone.getAllNodes().size()); |
|
309 |
|
|
310 |
Set<UUID> originalTaxonSecUuids = originalClassification.getAllNodes().stream().map(tn -> tn.getTaxon().getSec().getUuid()).collect(Collectors.toSet()); |
|
311 |
for (TaxonNode clonedTaxonNode : classificatonClone.getChildNodes()) { |
|
312 |
//test no reuse of taxon |
|
313 |
Taxon clonedTaxon = clonedTaxonNode.getTaxon(); |
|
314 |
TaxonNode originalNode = originalClassification.getNode(clonedTaxon); |
|
315 |
assertNull(originalNode); |
|
316 |
|
|
317 |
//check relationship |
|
318 |
assertEquals(0, clonedTaxon.getRelationsFromThisTaxon().size()); |
|
319 |
|
|
320 |
//test taxon sec |
|
321 |
assertTrue(originalTaxonSecUuids.contains(clonedTaxon.getSec().getUuid())); |
|
315 | 322 |
} |
323 |
|
|
324 |
//test reuse taxon |
|
325 |
config.setReuseTaxa(true); |
|
326 |
classificatonClone = (Classification) classificationService.cloneClassification(config).getCdmEntity(); |
|
327 |
assertEquals("# of direct children does not match", originalClassification.getChildNodes().size(), classificatonClone.getChildNodes().size()); |
|
328 |
originalTaxonSecUuids = originalClassification.getAllNodes().stream().map(tn -> tn.getTaxon().getSec().getUuid()).collect(Collectors.toSet()); |
|
329 |
for (TaxonNode taxonNode : classificatonClone.getChildNodes()) { |
|
330 |
//test no reuse of taxon |
|
331 |
Taxon clonedTaxon = taxonNode.getTaxon(); |
|
332 |
TaxonNode originalNode = originalClassification.getNode(clonedTaxon); |
|
333 |
assertNotNull(originalNode); |
|
334 |
Taxon originalTaxon = originalNode.getTaxon(); |
|
335 |
assertNotNull(originalTaxon); |
|
336 |
|
|
337 |
//check relationship |
|
338 |
assertEquals(0, clonedTaxon.getRelationsFromThisTaxon().size()); |
|
339 |
|
|
340 |
//test taxon sec |
|
341 |
assertEquals(originalTaxon.getSec().getUuid(), clonedTaxon.getSec().getUuid()); |
|
342 |
} |
|
343 |
|
|
344 |
config.setReuseTaxa(false); //reset |
|
345 |
config.setRelationTypeToOldTaxon(TaxonRelationshipType.CONGRUENT_TO()); |
|
346 |
Reference sec = referenceDao.findByUuid(UUID.fromString("719d136b-409e-40d0-9561-46f6999465b4")); |
|
347 |
config.setTaxonSecundumUuid(sec.getUuid()); |
|
348 |
classificatonClone = (Classification) classificationService.cloneClassification(config).getCdmEntity(); |
|
349 |
originalTaxonSecUuids = originalClassification.getAllNodes().stream().map(tn -> tn.getTaxon().getSec().getUuid()).collect(Collectors.toSet()); |
|
350 |
for (TaxonNode taxonNode : classificatonClone.getChildNodes()) { |
|
351 |
//test no reuse of taxon |
|
352 |
Taxon clonedTaxon = taxonNode.getTaxon(); |
|
353 |
TaxonNode originalNode = originalClassification.getNode(clonedTaxon); |
|
354 |
assertNull(originalNode); |
|
355 |
|
|
356 |
//check relationship |
|
357 |
TaxonRelationship relShip = clonedTaxon.getRelationsFromThisTaxon().iterator().next(); |
|
358 |
Taxon relatedTaxon = relShip.getToTaxon(); |
|
359 |
Taxon relatedOriginalTaxon = originalClassification.getNode(relatedTaxon).getTaxon(); |
|
360 |
assertEquals(relatedOriginalTaxon.getName(), clonedTaxon.getName()); |
|
361 |
assertTrue(relShip.getType().equals(TaxonRelationshipType.CONGRUENT_TO())); |
|
362 |
|
|
363 |
//test taxon sec |
|
364 |
assertEquals(relatedOriginalTaxon.getSec().getUuid(), clonedTaxon.getSec().getUuid()); |
|
365 |
} |
|
316 | 366 |
} |
317 | 367 |
|
318 | 368 |
|
... | ... | |
320 | 370 |
private UUID acacia_cuspidifolia_uuid = UUID.fromString("94123e4d-da49-4ed0-9d59-f52a9f7a3618"); |
321 | 371 |
private UUID acacia_sect_botrycephalae_uuid = UUID.fromString("2c73a166-35d1-483d-b8e8-209214cb6193"); |
322 | 372 |
|
323 |
|
|
324 |
/** |
|
325 |
* {@inheritDoc} |
|
326 |
*/ |
|
327 | 373 |
@Override |
328 | 374 |
// @Test |
329 | 375 |
public void createTestDataSet() throws FileNotFoundException { |
Also available in: Unified diff
ref #4866, ref #9228 implement subtree clone in branch