1 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.taxon
;
3 import static junit
.framework
.Assert
.assertEquals
;
4 import static junit
.framework
.Assert
.assertFalse
;
5 import static junit
.framework
.Assert
.assertNotNull
;
6 import static junit
.framework
.Assert
.assertSame
;
7 import static junit
.framework
.Assert
.assertTrue
;
8 import static org
.junit
.Assert
.assertNull
;
9 import static org
.junit
.Assert
.fail
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import org
.hibernate
.Hibernate
;
16 import org
.junit
.After
;
17 import org
.junit
.Before
;
18 import org
.junit
.Ignore
;
19 import org
.junit
.Test
;
20 import org
.unitils
.dbunit
.annotation
.DataSet
;
21 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
22 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
24 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
32 import eu
.etaxonomy
.cdm
.model
.view
.AuditEvent
;
33 import eu
.etaxonomy
.cdm
.model
.view
.AuditEventRecord
;
34 import eu
.etaxonomy
.cdm
.model
.view
.context
.AuditEventContextHolder
;
35 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.AuditEventSort
;
36 import eu
.etaxonomy
.cdm
.persistence
.dao
.reference
.IReferenceDao
;
37 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
38 import eu
.etaxonomy
.cdm
.persistence
.fetch
.CdmFetch
;
39 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
40 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
41 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
42 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
49 public class TaxonDaoHibernateImplTest
extends CdmTransactionalIntegrationTest
{
52 private ITaxonDao taxonDao
;
55 private IReferenceDao referenceDao
;
58 private UUID sphingidae
;
59 private UUID acherontia
;
61 private UUID acherontiaLachesis
;
62 private AuditEvent previousAuditEvent
;
63 private AuditEvent mostRecentAuditEvent
;
67 uuid
= UUID
.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
68 sphingidae
= UUID
.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
69 acherontia
= UUID
.fromString("c5cc8674-4242-49a4-aada-72d63194f5fa");
70 acherontiaLachesis
= UUID
.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06");
71 mimas
= UUID
.fromString("900052b7-b69c-4e26-a8f0-01c215214c40");
72 previousAuditEvent
= new AuditEvent();
73 previousAuditEvent
.setRevisionNumber(1025);
74 previousAuditEvent
.setUuid(UUID
.fromString("a680fab4-365e-4765-b49e-768f2ee30cda"));
75 mostRecentAuditEvent
= new AuditEvent();
76 mostRecentAuditEvent
.setRevisionNumber(1026);
77 mostRecentAuditEvent
.setUuid(UUID
.fromString("afe8e761-8545-497b-9134-6a6791fc0b0d"));
78 AuditEventContextHolder
.clearContext(); // By default we're in the current view (i.e. view == null)
82 public void tearDown() {
83 AuditEventContextHolder
.clearContext();
87 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#TaxonDaoHibernateImpl()}.
91 public void testInit() {
92 assertNotNull("Instance of ITaxonDao expected",taxonDao
);
93 assertNotNull("Instance of IReferenceDao expected",referenceDao
);
97 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getRootTaxa(eu.etaxonomy.cdm.model.reference.ReferenceBase)}.
101 public void testGetRootTaxa() {
102 ReferenceBase sec1
= referenceDao
.findById(1);
103 assert sec1
!= null : "sec1 must exist";
104 ReferenceBase sec2
= referenceDao
.findById(2);
105 assert sec2
!= null : "sec2 must exist";
107 List
<Taxon
> rootTaxa
= taxonDao
.getRootTaxa(sec1
);
108 assertNotNull("getRootTaxa should return a List",rootTaxa
);
109 assertFalse("The list should not be empty",rootTaxa
.isEmpty());
110 assertEquals("There should be one root taxon",1, rootTaxa
.size());
112 rootTaxa
= taxonDao
.getRootTaxa(sec1
, CdmFetch
.FETCH_CHILDTAXA(), true, false);
113 assertNotNull("getRootTaxa should return a List",rootTaxa
);
114 assertFalse("The list should not be empty",rootTaxa
.isEmpty());
115 assertEquals("There should be one root taxon",1, rootTaxa
.size());
117 rootTaxa
= taxonDao
.getRootTaxa(Rank
.GENUS(), sec1
, CdmFetch
.FETCH_CHILDTAXA(), true, false, null);
118 assertNotNull("getRootTaxa should return a List",rootTaxa
);
119 assertFalse("The list should not be empty",rootTaxa
.isEmpty());
120 assertEquals("There should be one root taxon",1, rootTaxa
.size());
122 rootTaxa
= taxonDao
.getRootTaxa(Rank
.FAMILY(), sec2
, CdmFetch
.FETCH_CHILDTAXA(), true, false, null);
123 if (logger
.isDebugEnabled()) {
124 logger
.debug("Root taxa rank Family (" + rootTaxa
.size() + "):");
125 for (Taxon taxon
: rootTaxa
) {
126 logger
.debug(taxon
.getTitleCache());
129 assertEquals("There should be one root taxon rank Family",1, rootTaxa
.size());
130 rootTaxa
= taxonDao
.getRootTaxa(Rank
.GENUS(), sec2
, CdmFetch
.FETCH_CHILDTAXA(), true, false, null);
131 assertNotNull("getRootTaxa should return a List",rootTaxa
);
132 assertFalse("The list should not be empty",rootTaxa
.isEmpty());
133 if (logger
.isDebugEnabled()) {
134 logger
.debug("Root taxa rank Genus (" + rootTaxa
.size() + "):");
135 for (Taxon taxon
: rootTaxa
) {
136 logger
.debug(taxon
.getTitleCache());
139 assertEquals("There should be 22 root taxa rank Genus",22, rootTaxa
.size());
141 rootTaxa
= taxonDao
.getRootTaxa(Rank
.SPECIES(), sec2
, CdmFetch
.FETCH_CHILDTAXA(), true, false, null);
142 if (logger
.isDebugEnabled()) {
143 logger
.debug("Root taxa rank Species (" + rootTaxa
.size() + "):");
144 for (Taxon taxon
: rootTaxa
) {
145 logger
.debug(taxon
.getTitleCache());
148 assertEquals("There should be 4 root taxa rank Species",3, rootTaxa
.size());
152 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.ReferenceBase)}.
156 public void testGetTaxaByName() {
157 ReferenceBase sec
= referenceDao
.findById(1);
158 assert sec
!= null : "sec must exist";
160 List
<TaxonBase
> results
= taxonDao
.getTaxaByName("Aus", sec
);
161 assertNotNull("getTaxaByName should return a List", results
);
162 //assertFalse("The list should not be empty", results.isEmpty());
163 assertTrue(results
.size() == 1);
165 results
= taxonDao
.getTaxaByName("A*", MatchMode
.BEGINNING
,
167 assertNotNull("getTaxaByName should return a List", results
);
168 assertTrue(results
.size() == 9);
170 results
= taxonDao
.getTaxaByName("A", MatchMode
.BEGINNING
,
172 assertNotNull("getTaxaByName should return a List", results
);
173 assertTrue(results
.size() == 9);
175 results
= taxonDao
.getTaxaByName("Aus", MatchMode
.EXACT
,
177 assertNotNull("getTaxaByName should return a List", results
);
178 assertTrue(results
.size() == 1);
183 public void testFindByUuid() {
184 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(uuid
);
185 assertNotNull("findByUuid should return a taxon",taxon
);
186 assertFalse("findByUuid should not return a taxon with it's name initialized",Hibernate
.isInitialized(taxon
.getName()));
191 public void testLoad() {
192 List
<String
> propertyPaths
= new ArrayList
<String
>();
193 propertyPaths
.add("name");
194 propertyPaths
.add("sec");
195 Taxon taxon
= (Taxon
)taxonDao
.load(uuid
, propertyPaths
);
196 assertNotNull("findByUuid should return a taxon",taxon
);
197 assertTrue("load should return a taxon with it's name initialized, given that the property was specified in the method",Hibernate
.isInitialized(taxon
.getName()));
198 assertTrue("load should return a taxon with it's secundum reference initialized, given that the property was specified in the method",Hibernate
.isInitialized(taxon
.getSec()));
203 public void testCountRelatedTaxa() {
204 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(sphingidae
);
205 assert taxon
!= null : "taxon must exist";
207 int numberOfRelatedTaxa
= taxonDao
.countRelatedTaxa(taxon
,TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN());
208 assertEquals("countRelatedTaxa should return 23", 23, numberOfRelatedTaxa
);
213 public void testRelatedTaxa() {
214 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(sphingidae
);
215 assert taxon
!= null : "taxon must exist";
217 List
<String
> propertyPaths
= new ArrayList
<String
>();
218 propertyPaths
.add("fromTaxon");
219 propertyPaths
.add("fromTaxon.name");
220 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
221 orderHints
.add(new OrderHint("relatedFrom.titleCache", SortOrder
.ASCENDING
));
223 List
<TaxonRelationship
> relatedTaxa
= taxonDao
.getRelatedTaxa(taxon
, TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN(), null, null, orderHints
,propertyPaths
);
224 assertNotNull("getRelatedTaxa should return a List",relatedTaxa
);
225 assertEquals("getRelatedTaxa should return all 23 related taxa",relatedTaxa
.size(),23);
226 assertTrue("getRelatedTaxa should return TaxonRelationship objects with the relatedFrom taxon initialized",Hibernate
.isInitialized(relatedTaxa
.get(0).getFromTaxon()));
227 assertTrue("getRelatedTaxa should return TaxonRelationship objects with the relatedFrom taxon initialized",Hibernate
.isInitialized(relatedTaxa
.get(0).getFromTaxon().getName()));
229 assertEquals("Acherontia should appear first in the list of related taxa", relatedTaxa
.get(0).getFromTaxon().getTitleCache(), "Acherontia Laspeyres, 1809 sec. cate-sphingidae.org");
230 assertEquals("Sphingonaepiopsis should appear last in the list of related taxa", relatedTaxa
.get(22).getFromTaxon().getTitleCache(), "Sphinx Linnaeus, 1758 sec. cate-sphingidae.org");
235 public void testGetRelatedTaxaPaged() {
236 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(sphingidae
);
237 assert taxon
!= null : "taxon must exist";
239 List
<String
> propertyPaths
= new ArrayList
<String
>();
240 propertyPaths
.add("fromTaxon");
241 propertyPaths
.add("fromTaxon.name");
243 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
244 orderHints
.add(new OrderHint("relatedFrom.titleCache", SortOrder
.ASCENDING
));
246 List
<TaxonRelationship
> firstPage
= taxonDao
.getRelatedTaxa(taxon
,TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN(), 10, 0, orderHints
,propertyPaths
);
247 List
<TaxonRelationship
> secondPage
= taxonDao
.getRelatedTaxa(taxon
,TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN(),10, 1, orderHints
,propertyPaths
);
248 List
<TaxonRelationship
> thirdPage
= taxonDao
.getRelatedTaxa(taxon
,TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN(), 10, 2, orderHints
,propertyPaths
);
250 assertNotNull("getRelatedTaxa: 10, 0 should return a List",firstPage
);
251 assertEquals("getRelatedTaxa: 10, 0 should return a List with 10 elements",10,firstPage
.size());
252 assertNotNull("getRelatedTaxa: 10, 1 should return a List",secondPage
);
253 assertEquals("getRelatedTaxa: 10, 1 should return a List with 10 elements",secondPage
.size(),10);
254 assertNotNull("getRelatedTaxa: 10, 2 should return a List",thirdPage
);
255 assertEquals("getRelatedTaxa: 10, 2 should return a List with 3 elements",thirdPage
.size(),3);
260 public void testCountSynonymRelationships() {
261 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontia
);
262 assert taxon
!= null : "taxon must exist";
264 int numberOfSynonymRelationships
= taxonDao
.countSynonyms(taxon
,null);
265 assertEquals("countSynonymRelationships should return 5",5,numberOfSynonymRelationships
);
270 public void testSynonymRelationships() {
271 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontia
);
272 assert taxon
!= null : "taxon must exist";
273 List
<String
> propertyPaths
= new ArrayList
<String
>();
274 propertyPaths
.add("synonym");
275 propertyPaths
.add("synonym.name");
277 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
278 orderHints
.add(new OrderHint("relatedFrom.titleCache", SortOrder
.ASCENDING
));
280 List
<SynonymRelationship
> synonyms
= taxonDao
.getSynonyms(taxon
, null, null, null,orderHints
,propertyPaths
);
282 assertNotNull("getSynonyms should return a List",synonyms
);
283 assertEquals("getSynonyms should return 5 SynonymRelationship entities",synonyms
.size(),5);
284 assertTrue("getSynonyms should return SynonymRelationship objects with the synonym initialized",Hibernate
.isInitialized(synonyms
.get(0).getSynonym()));
289 public void testCountSynonymRelationshipsByType() {
290 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontia
);
291 assert taxon
!= null : "taxon must exist";
293 int numberOfTaxonomicSynonyms
= taxonDao
.countSynonyms(taxon
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
294 assertEquals("countSynonyms should return 4",numberOfTaxonomicSynonyms
, 4);
299 public void testSynonymRelationshipsByType() {
300 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontia
);
301 assert taxon
!= null : "taxon must exist";
303 List
<SynonymRelationship
> synonyms
= taxonDao
.getSynonyms(taxon
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), null, null,null,null);
305 assertNotNull("getSynonyms should return a List",synonyms
);
306 assertEquals("getSynonyms should return 4 SynonymRelationship entities",synonyms
.size(),4);
311 public void testPageSynonymRelationships(){
312 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontia
);
313 assert taxon
!= null : "taxon must exist";
315 List
<SynonymRelationship
> firstPage
= taxonDao
.getSynonyms(taxon
, null, 4, 0,null,null);
316 List
<SynonymRelationship
> secondPage
= taxonDao
.getSynonyms(taxon
, null, 4, 1,null,null);
318 assertNotNull("getSynonyms: 4, 0 should return a List",firstPage
);
319 assertEquals("getSynonyms: 4, 0 should return 4 SynonymRelationships", firstPage
.size(),4);
320 assertNotNull("getSynonyms: 4, 1 should return a List",secondPage
);
321 assertEquals("getSynonyms: 4, 1 should return 1 SynonymRelationship",secondPage
.size(),1);
326 public void testGetTaxonMatchingUninomial() {
327 List
<TaxonBase
> result
= taxonDao
.findTaxaByName(Taxon
.class, "Smerinthus", "*", "*", "*",null,null,null);
329 assertNotNull("findTaxaByName should return a List", result
);
330 assertEquals("findTaxaByName should return two Taxa",2,result
.size());
331 assertEquals("findTaxaByName should return a Taxon with id 5",5,result
.get(0).getId());
336 public void testGetTaxonMatchingSpeciesBinomial() {
337 List
<TaxonBase
> result
= taxonDao
.findTaxaByName(Taxon
.class,"Smerinthus", null, "kindermannii", null,null,null,null);
339 assertNotNull("findTaxaByName should return a List", result
);
340 assertEquals("findTaxaByName should return one Taxon",1,result
.size());
341 assertEquals("findTaxaByName should return a Taxon with id 8",8,result
.get(0).getId());
346 public void testGetTaxonMatchingTrinomial() {
347 List
<TaxonBase
> result
= taxonDao
.findTaxaByName(Taxon
.class,"Cryptocoryne", null,"purpurea","borneoensis",null,null,null);
349 assertNotNull("findTaxaByName should return a List", result
);
350 assertEquals("findTaxaByName should return one Taxon",1,result
.size());
351 assertEquals("findTaxaByName should return a Taxon with id 38",38,result
.get(0).getId());
356 public void testNegativeMatch() {
357 List
<TaxonBase
> result
= taxonDao
.findTaxaByName(Taxon
.class,"Acherontia", null,"atropos","dehli",null,null,null);
359 assertNotNull("findTaxaByName should return a List", result
);
360 assertTrue("findTaxaByName should return an empty List",result
.isEmpty());
365 public void testCountAllTaxa() {
366 int numberOfTaxa
= taxonDao
.count(Taxon
.class);
367 assertEquals("count should return 33 taxa",33, numberOfTaxa
);
372 public void testListAllTaxa() {
373 List
<Taxon
> taxa
= taxonDao
.list(Taxon
.class,100, 0);
374 assertNotNull("list should return a List",taxa
);
375 assertEquals("list should return 33 taxa",33, taxa
.size());
381 public void testDelete() {
382 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontia
);
383 assert taxon
!= null : "taxon must exist";
384 taxonDao
.delete(taxon
);
385 Taxon taxonWithChildren
= (Taxon
)taxonDao
.findByUuid(mimas
);
386 assert taxonWithChildren
!= null : "taxon must exist";
387 assertEquals(taxonWithChildren
.getTaxonomicChildrenCount(), 2);
388 Taxon parent
= (Taxon
)taxonDao
.findByUuid(sphingidae
);
389 assertSame(taxonWithChildren
.getTaxonomicParent(), parent
);
390 assertEquals(parent
.getTaxonomicChildrenCount(), 203);
391 taxonDao
.delete(taxonWithChildren
);
392 assertEquals(parent
.getTaxonomicChildrenCount(), 202);
398 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
399 public void testFindDeleted() {
400 TaxonBase taxon
= taxonDao
.findByUuid(acherontia
);
401 assertNull("findByUuid should return null in this view", taxon
);
402 assertFalse("exist should return false in this view",taxonDao
.exists(acherontia
));
406 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
407 public void testFindDeletedInPreviousView() {
408 AuditEventContextHolder
.getContext().setAuditEvent(previousAuditEvent
);
409 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontia
);
410 assertNotNull("findByUuid should return a taxon in this view",taxon
);
411 assertTrue("exists should return true in this view", taxonDao
.exists(acherontia
));
414 assertEquals("There should be 3 relations to this taxon in this view",3,taxon
.getRelationsToThisTaxon().size());
415 } catch(Exception e
) {
416 fail("We should not experience any problems initializing proxies with envers");
421 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
422 public void testGetAuditEvents() {
423 TaxonBase taxon
= taxonDao
.findByUuid(sphingidae
);
424 assert taxon
!= null : "taxon cannot be null";
426 List
<AuditEventRecord
<TaxonBase
>> auditEvents
= taxonDao
.getAuditEvents(taxon
, null,null,null);
427 assertNotNull("getAuditEvents should return a list",auditEvents
);
428 assertFalse("the list should not be empty",auditEvents
.isEmpty());
429 assertEquals("There should be two AuditEventRecords in the list",2, auditEvents
.size());
433 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
434 public void testGetAuditEventsFromNow() {
435 AuditEventContextHolder
.getContext().setAuditEvent(previousAuditEvent
);
436 TaxonBase taxon
= taxonDao
.findByUuid(sphingidae
);
437 assert taxon
!= null : "taxon cannot be null";
439 List
<AuditEventRecord
<TaxonBase
>> auditEvents
= taxonDao
.getAuditEvents(taxon
, null,null,AuditEventSort
.FORWARDS
);
440 assertNotNull("getAuditEvents should return a list",auditEvents
);
441 assertFalse("the list should not be empty",auditEvents
.isEmpty());
442 assertEquals("There should be one audit event in the list",1,auditEvents
.size());
446 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
447 public void testCountAuditEvents() {
448 TaxonBase taxon
= taxonDao
.findByUuid(sphingidae
);
449 assert taxon
!= null : "taxon cannot be null";
451 int numberOfAuditEvents
= taxonDao
.countAuditEvents(taxon
,null);
452 assertEquals("countAuditEvents should return 2",numberOfAuditEvents
,2);
456 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
457 public void getPreviousAuditEvent() {
458 TaxonBase taxon
= taxonDao
.findByUuid(sphingidae
);
459 assert taxon
!= null : "taxon cannot be null";
461 AuditEventRecord
<TaxonBase
> auditEvent
= taxonDao
.getPreviousAuditEvent(taxon
);
462 assertNotNull("getPreviousAuditEvent should not return null as there is at least one audit event prior to the current one",auditEvent
);
466 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
467 public void getPreviousAuditEventAtBeginning() {
468 AuditEventContextHolder
.getContext().setAuditEvent(previousAuditEvent
);
469 TaxonBase taxon
= taxonDao
.findByUuid(sphingidae
);
470 assert taxon
!= null : "taxon cannot be null";
472 AuditEventRecord
<TaxonBase
> auditEvent
= taxonDao
.getPreviousAuditEvent(taxon
);
473 assertNull("getPreviousAuditEvent should return null if we're at the first audit event anyway",auditEvent
);
477 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
478 public void getNextAuditEvent() {
479 AuditEventContextHolder
.getContext().setAuditEvent(previousAuditEvent
);
480 TaxonBase taxon
= taxonDao
.findByUuid(sphingidae
);
481 assert taxon
!= null : "taxon cannot be null";
483 AuditEventRecord
<TaxonBase
> auditEvent
= taxonDao
.getNextAuditEvent(taxon
);
484 assertNotNull("getNextAuditEvent should not return null as there is at least one audit event after the current one",auditEvent
);
488 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
489 public void getNextAuditEventAtEnd() {
490 AuditEventContextHolder
.getContext().setAuditEvent(mostRecentAuditEvent
);
491 TaxonBase taxon
= taxonDao
.findByUuid(sphingidae
);
492 assert taxon
!= null : "taxon cannot be null";
494 AuditEventRecord
<TaxonBase
> auditEvent
= taxonDao
.getNextAuditEvent(taxon
);
495 assertNull("getNextAuditEvent should return null as there no more audit events after the current one",auditEvent
);
502 public void testAddChild() throws Exception
{
503 Taxon parent
= (Taxon
)taxonDao
.findByUuid(acherontiaLachesis
);
504 assert parent
!= null : "taxon cannot be null";
505 Taxon child
= Taxon
.NewInstance(null, null);
506 child
.setTitleCache("Acherontia lachesis diehli Eitschberger, 2003", true);
507 child
.addTaxonRelation(parent
, TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN(),null, null);
508 taxonDao
.save(child
);
514 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
515 public void testFind() {
516 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontiaLachesis
);
517 assert taxon
!= null : "taxon cannot be null";
519 assertEquals("getTaxonomicChildrenCount should return 1 in this view",1,taxon
.getTaxonomicChildrenCount());
520 assertEquals("getRelationsToThisTaxon should contain 1 TaxonRelationship in this view",1,taxon
.getRelationsToThisTaxon().size());
524 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
525 public void testFindInPreviousView() {
526 AuditEventContextHolder
.getContext().setAuditEvent(previousAuditEvent
);
527 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontiaLachesis
);
528 assert taxon
!= null : "taxon cannot be null";
530 assertEquals("getTaxonomicChildrenCount should return 0 in this view",0,taxon
.getTaxonomicChildrenCount());
531 assertTrue("getRelationsToThisTaxon should contain 0 TaxonRelationship in this view",taxon
.getRelationsToThisTaxon().isEmpty());
535 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
536 public void testGetRelations() {
537 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontiaLachesis
);
538 assert taxon
!= null : "taxon cannot be null";
540 List
<String
> propertyPaths
= new ArrayList
<String
>();
541 propertyPaths
.add("fromTaxon");
542 propertyPaths
.add("fromTaxon.name");
544 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
545 orderHints
.add(new OrderHint("relatedFrom.titleCache", SortOrder
.ASCENDING
));
547 List
<TaxonRelationship
> taxonRelations
= taxonDao
.getRelatedTaxa(taxon
, TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN(), null, null,orderHints
,propertyPaths
);
548 assertNotNull("getRelatedTaxa should return a list", taxonRelations
);
549 assertEquals("there should be one TaxonRelationship in the list in the current view",1,taxonRelations
.size());
550 assertTrue("TaxonRelationship.relatedFrom should be initialized",Hibernate
.isInitialized(taxonRelations
.get(0).getFromTaxon()));
551 assertTrue("TaxonRelationship.relatedFrom.name should be initialized",Hibernate
.isInitialized(taxonRelations
.get(0).getFromTaxon().getName()));
555 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
556 public void testCountRelations() {
557 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontiaLachesis
);
558 assert taxon
!= null : "taxon cannot be null";
559 assertEquals("countRelatedTaxa should return 1 in the current view",1, taxonDao
.countRelatedTaxa(taxon
,TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN()));
563 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
564 public void testGetRelationsInPreviousView() {
565 AuditEventContextHolder
.getContext().setAuditEvent(previousAuditEvent
);
566 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontiaLachesis
);
567 assert taxon
!= null : "taxon cannot be null";
569 List
<String
> propertyPaths
= new ArrayList
<String
>();
570 propertyPaths
.add("relatedFrom");
571 propertyPaths
.add("relatedFrom.name");
573 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
574 orderHints
.add(new OrderHint("relatedFrom.titleCache", SortOrder
.ASCENDING
));
576 List
<TaxonRelationship
> taxonRelations
= taxonDao
.getRelatedTaxa(taxon
, TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN(), null, null,orderHints
,propertyPaths
);
577 assertNotNull("getRelatedTaxa should return a list",taxonRelations
);
578 assertTrue("there should be no TaxonRelationships in the list in the prior view",taxonRelations
.isEmpty());
582 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
583 public void testCountRelationsInPreviousView() {
584 AuditEventContextHolder
.getContext().setAuditEvent(previousAuditEvent
);
585 Taxon taxon
= (Taxon
)taxonDao
.findByUuid(acherontiaLachesis
);
586 assert taxon
!= null : "taxon cannot be null";
587 assertEquals("countRelatedTaxa should return 0 in the current view",0, taxonDao
.countRelatedTaxa(taxon
,TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN()));