2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.taxon
;
12 import static junit
.framework
.Assert
.assertNotNull
;
13 import static org
.junit
.Assert
.assertEquals
;
15 import java
.util
.HashSet
;
16 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.junit
.After
;
21 import org
.junit
.Before
;
22 import org
.junit
.Test
;
23 import org
.unitils
.dbunit
.annotation
.DataSet
;
24 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
30 import eu
.etaxonomy
.cdm
.model
.view
.context
.AuditEventContextHolder
;
31 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
32 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonNodeDao
;
33 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.IClassificationDao
;
34 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
36 public class TaxonNodeDaoHibernateImplTest
extends CdmTransactionalIntegrationTest
{
39 private ITaxonNodeDao taxonNodeDao
;
42 private IClassificationDao classificationDao
;
45 private ITaxonDao taxonDao
;
53 uuid1
= UUID
.fromString("20c8f083-5870-4cbd-bf56-c5b2b98ab6a7");
54 uuid2
= UUID
.fromString("770239f6-4fa8-496b-8738-fe8f7b2ad519");
55 AuditEventContextHolder
.clearContext();
59 public void tearDown(){
60 AuditEventContextHolder
.clearContext();
66 public void testInit() {
67 assertNotNull("Instance of ITaxonDao expected",taxonNodeDao
);
68 assertNotNull("Instance of IReferenceDao expected",classificationDao
);
73 public void testFindByUuid() {
74 TaxonNode taxonNode
= (TaxonNode
) taxonNodeDao
.findByUuid(uuid1
);
75 Classification
.class.getDeclaredConstructors();
76 assertNotNull("findByUuid should return a taxon node", taxonNode
);
81 public void testClassification() {
82 Classification classification
= classificationDao
.findByUuid(UUID
.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9"));
84 assertNotNull("findByUuid should return a taxon tree", classification
);
85 assertNotNull("classification should have a name",classification
.getName());
86 assertEquals("classification should have a name which is 'Name'",classification
.getName().getText(),"Name");
87 TaxonNode taxNode
= (TaxonNode
) taxonNodeDao
.findByUuid(uuid1
);
88 TaxonNode taxNode2
= (TaxonNode
) taxonNodeDao
.findByUuid(uuid2
);
89 Set
<TaxonNode
> rootNodes
= new HashSet
<TaxonNode
>();
91 rootNodes
.add(taxNode
);
94 for (TaxonNode rootNode
: rootNodes
){
95 classification
.addChildNode(rootNode
, rootNode
.getReference(), rootNode
.getMicroReference(), rootNode
.getSynonymToBeUsed());
98 taxNode
.addChildNode(taxNode2
, null, null,null);
100 Taxon taxon2
= taxNode2
.getTaxon();
101 Taxon taxon
= taxNode
.getTaxon();
102 UUID uuidTaxon
= taxon
.getUuid();
103 UUID uuidTaxon2
= taxon2
.getUuid();
105 List
<TaxonBase
> taxa
= taxonDao
.getAllTaxonBases(10, 0);
106 assertEquals("there should be only two taxa", 5, taxa
.size());
108 taxonNodeDao
.delete(taxNode2
);
110 taxa
= taxonDao
.getAllTaxonBases(10, 0);
111 assertEquals("there should be only one taxon left", 4, taxa
.size());
113 classificationDao
.delete(classification
);
114 classification
= classificationDao
.findByUuid(UUID
.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9"));
115 assertEquals("The tree should be null", null, classification
);