TypeDesignationStatus renamed to SpecimenTypeDesignationStatus
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / dao / hibernate / taxon / TaxonDaoHibernateImplTest.java
1 package eu.etaxonomy.cdm.persistence.dao.hibernate.taxon;
2
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.assertTrue;
7 import static org.junit.Assert.assertNull;
8 import static org.junit.Assert.fail;
9
10 import java.util.List;
11 import java.util.UUID;
12
13 import org.hibernate.Hibernate;
14 import org.junit.After;
15 import org.junit.Before;
16 import org.junit.Ignore;
17 import org.junit.Test;
18 import org.unitils.dbunit.annotation.DataSet;
19 import org.unitils.dbunit.annotation.ExpectedDataSet;
20 import org.unitils.spring.annotation.SpringBeanByType;
21
22 import eu.etaxonomy.cdm.model.name.Rank;
23 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
24 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
25 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
26 import eu.etaxonomy.cdm.model.taxon.Taxon;
27 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
28 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
29 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
30 import eu.etaxonomy.cdm.model.view.AuditEvent;
31 import eu.etaxonomy.cdm.model.view.AuditEventRecord;
32 import eu.etaxonomy.cdm.model.view.context.AuditEventContextHolder;
33 import eu.etaxonomy.cdm.persistence.dao.common.AuditEventSort;
34 import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
35 import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
36 import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
37 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
38
39 /**
40 * @author a.mueller
41 * @author ben.clark
42 *
43 */
44 public class TaxonDaoHibernateImplTest extends CdmTransactionalIntegrationTest {
45
46 @SpringBeanByType
47 private ITaxonDao taxonDao;
48
49 @SpringBeanByType
50 private IReferenceDao referenceDao;
51
52 private UUID uuid;
53 private UUID sphingidae;
54 private UUID acherontia;
55 private UUID acherontiaLachesis;
56 private AuditEvent previousAuditEvent;
57 private AuditEvent mostRecentAuditEvent;
58
59 @Before
60 public void setUp() {
61 uuid = UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
62 sphingidae = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
63 acherontia = UUID.fromString("c5cc8674-4242-49a4-aada-72d63194f5fa");
64 acherontiaLachesis = UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06");
65 previousAuditEvent = new AuditEvent();
66 previousAuditEvent.setRevisionNumber(1000);
67 previousAuditEvent.setUuid(UUID.fromString("a680fab4-365e-4765-b49e-768f2ee30cda"));
68 mostRecentAuditEvent = new AuditEvent();
69 mostRecentAuditEvent.setRevisionNumber(1025);
70 mostRecentAuditEvent.setUuid(UUID.fromString("afe8e761-8545-497b-9134-6a6791fc0b0d"));
71 AuditEventContextHolder.clearContext(); // By default we're in the current view (i.e. view == null)
72 }
73
74 @After
75 public void tearDown() {
76 AuditEventContextHolder.clearContext();
77 }
78
79 // @Test
80 // @DataSet
81 // public final void testPrintDataSet() {
82 // printDataSet(System.out);
83 // }
84
85 /**
86 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#TaxonDaoHibernateImpl()}.
87 */
88 @Test
89 @DataSet
90 public void testInit() {
91 assertNotNull("Instance of ITaxonDao expected",taxonDao);
92 assertNotNull("Instance of IReferenceDao expected",referenceDao);
93 }
94
95 /**
96 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getRootTaxa(eu.etaxonomy.cdm.model.reference.ReferenceBase)}.
97 */
98 @Test
99 @DataSet
100 public void testGetRootTaxa() {
101 ReferenceBase sec1 = referenceDao.findById(1);
102 assert sec1 != null : "sec1 must exist";
103 ReferenceBase sec2 = referenceDao.findById(2);
104 assert sec2 != null : "sec2 must exist";
105
106 List<Taxon> rootTaxa = taxonDao.getRootTaxa(sec1);
107 assertNotNull("getRootTaxa should return a List",rootTaxa);
108 assertFalse("The list should not be empty",rootTaxa.isEmpty());
109 assertEquals("There should be one root taxon",1, rootTaxa.size());
110
111 rootTaxa = taxonDao.getRootTaxa(sec1, CdmFetch.FETCH_CHILDTAXA(), true, false);
112 assertNotNull("getRootTaxa should return a List",rootTaxa);
113 assertFalse("The list should not be empty",rootTaxa.isEmpty());
114 assertEquals("There should be one root taxon",1, rootTaxa.size());
115
116 rootTaxa = taxonDao.getRootTaxa(Rank.GENUS(), sec1, CdmFetch.FETCH_CHILDTAXA(), true, false);
117 assertNotNull("getRootTaxa should return a List",rootTaxa);
118 assertFalse("The list should not be empty",rootTaxa.isEmpty());
119 assertEquals("There should be one root taxon",1, rootTaxa.size());
120
121 rootTaxa = taxonDao.getRootTaxa(Rank.FAMILY(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false);
122 if (logger.isDebugEnabled()) {
123 logger.debug("Root taxa rank Family (" + rootTaxa.size() + "):");
124 for (Taxon taxon: rootTaxa) {
125 logger.debug(taxon.getTitleCache());
126 }
127 }
128 assertEquals("There should be one root taxon rank Family",1, rootTaxa.size());
129 rootTaxa = taxonDao.getRootTaxa(Rank.GENUS(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false);
130 assertNotNull("getRootTaxa should return a List",rootTaxa);
131 assertFalse("The list should not be empty",rootTaxa.isEmpty());
132 if (logger.isDebugEnabled()) {
133 logger.debug("Root taxa rank Genus (" + rootTaxa.size() + "):");
134 for (Taxon taxon: rootTaxa) {
135 logger.debug(taxon.getTitleCache());
136 }
137 }
138 assertEquals("There should be 22 root taxa rank Genus",22, rootTaxa.size());
139
140 rootTaxa = taxonDao.getRootTaxa(Rank.SPECIES(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false);
141 if (logger.isDebugEnabled()) {
142 logger.debug("Root taxa rank Species (" + rootTaxa.size() + "):");
143 for (Taxon taxon: rootTaxa) {
144 logger.debug(taxon.getTitleCache());
145 }
146 }
147 assertEquals("There should be 4 root taxa rank Species",3, rootTaxa.size());
148 }
149
150 /**
151 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.ReferenceBase)}.
152 */
153 @Test
154 @DataSet
155 public void testGetTaxaByName() {
156 ReferenceBase sec = referenceDao.findById(1);
157 assert sec != null : "sec must exist";
158
159 List<TaxonBase> results = taxonDao.getTaxaByName("Aus", sec);
160 assertNotNull("getTaxaByName should return a List",results);
161 assertFalse("The list should not be empty",results.isEmpty());
162 }
163
164 @Test
165 @DataSet
166 public void testFindByUuid() {
167 Taxon taxon = (Taxon)taxonDao.findByUuid(uuid);
168 assertNotNull("findByUuid should return a taxon",taxon);
169 assertTrue("findByUuid should return a taxon with it's name initialized",Hibernate.isInitialized(taxon.getName()));
170 }
171
172 @Test
173 @DataSet
174 public void testCountRelatedTaxa() {
175 Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
176 assert taxon != null : "taxon must exist";
177
178 int numberOfRelatedTaxa = taxonDao.countRelatedTaxa(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN());
179 assertEquals("countRelatedTaxa should return 23", 23, numberOfRelatedTaxa);
180 }
181
182 @Test
183 @DataSet
184 public void testRelatedTaxa() {
185 Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
186 assert taxon != null : "taxon must exist";
187
188 List<TaxonRelationship> relatedTaxa = taxonDao.getRelatedTaxa(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null);
189 assertNotNull("getRelatedTaxa should return a List",relatedTaxa);
190 assertEquals("getRelatedTaxa should return all 23 related taxa",relatedTaxa.size(),23);
191 assertTrue("getRelatedTaxa should return TaxonRelationship objects with the relatedFrom taxon initialized",Hibernate.isInitialized(relatedTaxa.get(0).getFromTaxon()));
192 }
193
194 @Test
195 @DataSet
196 public void testGetRelatedTaxaPaged() {
197 Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
198 assert taxon != null : "taxon must exist";
199
200 List<TaxonRelationship> firstPage = taxonDao.getRelatedTaxa(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), 10, 0);
201 List<TaxonRelationship> secondPage = taxonDao.getRelatedTaxa(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),10, 1);
202 List<TaxonRelationship> thirdPage = taxonDao.getRelatedTaxa(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), 10, 2);
203
204 assertNotNull("getRelatedTaxa: 10, 0 should return a List",firstPage);
205 assertEquals("getRelatedTaxa: 10, 0 should return a List with 10 elements",10,firstPage.size());
206 assertNotNull("getRelatedTaxa: 10, 1 should return a List",secondPage);
207 assertEquals("getRelatedTaxa: 10, 1 should return a List with 10 elements",secondPage.size(),10);
208 assertNotNull("getRelatedTaxa: 10, 2 should return a List",thirdPage);
209 assertEquals("getRelatedTaxa: 10, 2 should return a List with 3 elements",thirdPage.size(),3);
210 }
211
212 @Test
213 @DataSet
214 public void testCountSynonymRelationships() {
215 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
216 assert taxon != null : "taxon must exist";
217
218 int numberOfSynonymRelationships = taxonDao.countSynonyms(taxon,null);
219 assertEquals("countSynonymRelationships should return 5",5,numberOfSynonymRelationships);
220 }
221
222 @Test
223 @DataSet
224 public void testSynonymRelationships() {
225 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
226 assert taxon != null : "taxon must exist";
227
228 List<SynonymRelationship> synonyms = taxonDao.getSynonyms(taxon, null, null, null);
229
230 assertNotNull("getSynonyms should return a List",synonyms);
231 assertEquals("getSynonyms should return 5 SynonymRelationship entities",synonyms.size(),5);
232 assertTrue("getSynonyms should return SynonymRelationship objects with the synonym initialized",Hibernate.isInitialized(synonyms.get(0).getSynonym()));
233 }
234
235 @Test
236 @DataSet
237 public void testCountSynonymRelationshipsByType() {
238 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
239 assert taxon != null : "taxon must exist";
240
241 int numberOfTaxonomicSynonyms = taxonDao.countSynonyms(taxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
242 assertEquals("countSynonyms should return 4",numberOfTaxonomicSynonyms, 4);
243 }
244
245 @Test
246 @DataSet
247 public void testSynonymRelationshipsByType() {
248 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
249 assert taxon != null : "taxon must exist";
250
251 List<SynonymRelationship> synonyms = taxonDao.getSynonyms(taxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null);
252
253 assertNotNull("getSynonyms should return a List",synonyms);
254 assertEquals("getSynonyms should return 4 SynonymRelationship entities",synonyms.size(),4);
255 }
256
257 @Test
258 @DataSet
259 public void testPageSynonymRelationships(){
260 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
261 assert taxon != null : "taxon must exist";
262
263 List<SynonymRelationship> firstPage = taxonDao.getSynonyms(taxon, null, 4, 0);
264 List<SynonymRelationship> secondPage = taxonDao.getSynonyms(taxon, null, 4, 1);
265
266 assertNotNull("getSynonyms: 4, 0 should return a List",firstPage);
267 assertEquals("getSynonyms: 4, 0 should return 4 SynonymRelationships", firstPage.size(),4);
268 assertNotNull("getSynonyms: 4, 1 should return a List",secondPage);
269 assertEquals("getSynonyms: 4, 1 should return 1 SynonymRelationship",secondPage.size(),1);
270 }
271
272 @Test
273 @DataSet
274 public void testGetTaxonMatchingUninomial() {
275 List<TaxonBase> result = taxonDao.findTaxaByName(true, "Smerinthus", null, null, null,null,null,null);
276
277 assertNotNull("findTaxaByName should return a List", result);
278 assertEquals("findTaxaByName should return two Taxa",2,result.size());
279 assertEquals("findTaxaByName should return a Taxon with id 5",5,result.get(0).getId());
280 }
281
282 @Test
283 @DataSet
284 public void testGetTaxonMatchingSpeciesBinomial() {
285 List<TaxonBase> result = taxonDao.findTaxaByName(true,"Smerinthus", null, "kindermannii", null,null,null,null);
286
287 assertNotNull("findTaxaByName should return a List", result);
288 assertEquals("findTaxaByName should return one Taxon",1,result.size());
289 assertEquals("findTaxaByName should return a Taxon with id 8",8,result.get(0).getId());
290 }
291
292 @Test
293 @DataSet
294 public void testGetTaxonMatchingTrinomial() {
295 List<TaxonBase> result = taxonDao.findTaxaByName(true,"Cryptocoryne", null,"purpurea","borneoensis",null,null,null);
296
297 assertNotNull("findTaxaByName should return a List", result);
298 assertEquals("findTaxaByName should return one Taxon",1,result.size());
299 assertEquals("findTaxaByName should return a Taxon with id 38",38,result.get(0).getId());
300 }
301
302 @Test
303 @DataSet
304 public void testNegativeMatch() {
305 List<TaxonBase> result = taxonDao.findTaxaByName(true,"Acherontia", null,"atropos","dehli",null,null,null);
306
307 assertNotNull("findTaxaByName should return a List", result);
308 assertTrue("findTaxaByName should return an empty List",result.isEmpty());
309 }
310
311 @Test
312 @DataSet
313 public void testCountAllTaxa() {
314 int numberOfTaxa = taxonDao.count(Taxon.class);
315 assertEquals("count should return 33 taxa",33, numberOfTaxa);
316 }
317
318 @Test
319 @DataSet
320 public void testListAllTaxa() {
321 List<Taxon> taxa = taxonDao.list(Taxon.class,100, 0);
322 assertNotNull("list should return a List",taxa);
323 assertEquals("list should return 33 taxa",33, taxa.size());
324 }
325
326 @Test
327 @DataSet
328 @ExpectedDataSet
329 public void testDelete() {
330 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
331 assert taxon != null : "taxon must exist";
332 taxonDao.delete(taxon);
333 setComplete();
334 endTransaction();
335 }
336
337 @Test
338 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
339 public void testFindDeleted() {
340 TaxonBase taxon = taxonDao.findByUuid(acherontia);
341 assertNull("findByUuid should return null in this view", taxon);
342 assertFalse("exist should return false in this view",taxonDao.exists(acherontia));
343 }
344
345 @Test
346 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
347 public void testFindDeletedInPreviousView() {
348 AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
349 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
350 assertNotNull("findByUuid should return a taxon in this view",taxon);
351 assertTrue("exists should return true in this view", taxonDao.exists(acherontia));
352
353 try{
354 assertEquals("There should be 3 relations to this taxon in this view",3,taxon.getRelationsToThisTaxon().size());
355 } catch(Exception e) {
356 fail("We should not experience any problems initializing proxies with envers");
357 }
358 }
359
360 @Test
361 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
362 public void testGetAuditEvents() {
363 TaxonBase taxon = taxonDao.findByUuid(sphingidae);
364 assert taxon != null : "taxon cannot be null";
365
366 List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(taxon, null,null,null);
367 assertNotNull("getAuditEvents should return a list",auditEvents);
368 assertFalse("the list should not be empty",auditEvents.isEmpty());
369 assertEquals("There should be two AuditEventRecords in the list",2, auditEvents.size());
370 }
371
372 @Test
373 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
374 public void testGetAuditEventsFromNow() {
375 AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
376 TaxonBase taxon = taxonDao.findByUuid(sphingidae);
377 assert taxon != null : "taxon cannot be null";
378
379 List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(taxon, null,null,AuditEventSort.FORWARDS);
380 assertNotNull("getAuditEvents should return a list",auditEvents);
381 assertFalse("the list should not be empty",auditEvents.isEmpty());
382 assertEquals("There should be one audit event in the list",1,auditEvents.size());
383 }
384
385 @Test
386 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
387 public void testCountAuditEvents() {
388 TaxonBase taxon = taxonDao.findByUuid(sphingidae);
389 assert taxon != null : "taxon cannot be null";
390
391 int numberOfAuditEvents = taxonDao.countAuditEvents(taxon,null);
392 assertEquals("countAuditEvents should return 2",numberOfAuditEvents,2);
393 }
394
395 @Test
396 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
397 public void getPreviousAuditEvent() {
398 TaxonBase taxon = taxonDao.findByUuid(sphingidae);
399 assert taxon != null : "taxon cannot be null";
400
401 AuditEventRecord<TaxonBase> auditEvent = taxonDao.getPreviousAuditEvent(taxon);
402 assertNotNull("getPreviousAuditEvent should not return null as there is at least one audit event prior to the current one",auditEvent);
403 }
404
405 @Test
406 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
407 public void getPreviousAuditEventAtBeginning() {
408 AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
409 TaxonBase taxon = taxonDao.findByUuid(sphingidae);
410 assert taxon != null : "taxon cannot be null";
411
412 AuditEventRecord<TaxonBase> auditEvent = taxonDao.getPreviousAuditEvent(taxon);
413 assertNull("getPreviousAuditEvent should return null if we're at the first audit event anyway",auditEvent);
414 }
415
416 @Test
417 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
418 public void getNextAuditEvent() {
419 AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
420 TaxonBase taxon = taxonDao.findByUuid(sphingidae);
421 assert taxon != null : "taxon cannot be null";
422
423 AuditEventRecord<TaxonBase> auditEvent = taxonDao.getNextAuditEvent(taxon);
424 assertNotNull("getNextAuditEvent should not return null as there is at least one audit event after the current one",auditEvent);
425 }
426
427 @Test
428 @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
429 public void getNextAuditEventAtEnd() {
430 AuditEventContextHolder.getContext().setAuditEvent(mostRecentAuditEvent);
431 TaxonBase taxon = taxonDao.findByUuid(sphingidae);
432 assert taxon != null : "taxon cannot be null";
433
434 AuditEventRecord<TaxonBase> auditEvent = taxonDao.getNextAuditEvent(taxon);
435 assertNull("getNextAuditEvent should return null as there no more audit events after the current one",auditEvent);
436 }
437
438 @Test
439 @DataSet
440 @ExpectedDataSet
441 @Ignore
442 public void testAddChild() throws Exception {
443 Taxon parent = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
444 assert parent != null : "taxon cannot be null";
445 Taxon child = Taxon.NewInstance(null, null);
446 child.setTitleCache("Acherontia lachesis diehli Eitschberger, 2003", true);
447 child.addTaxonRelation(parent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),null, null);
448 taxonDao.save(child);
449 setComplete();
450 endTransaction();
451 }
452
453 @Test
454 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
455 public void testFind() {
456 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
457 assert taxon != null : "taxon cannot be null";
458
459 assertEquals("getTaxonomicChildrenCount should return 1 in this view",1,taxon.getTaxonomicChildrenCount());
460 assertEquals("getRelationsToThisTaxon should contain 1 TaxonRelationship in this view",1,taxon.getRelationsToThisTaxon().size());
461 }
462
463 @Test
464 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
465 public void testFindInPreviousView() {
466 AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
467 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
468 assert taxon != null : "taxon cannot be null";
469
470 assertEquals("getTaxonomicChildrenCount should return 0 in this view",0,taxon.getTaxonomicChildrenCount());
471 assertTrue("getRelationsToThisTaxon should contain 0 TaxonRelationship in this view",taxon.getRelationsToThisTaxon().isEmpty());
472 }
473
474 @Test
475 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
476 public void testGetRelations() {
477 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
478 assert taxon != null : "taxon cannot be null";
479 List<TaxonRelationship> taxonRelations = taxonDao.getRelatedTaxa(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null);
480 assertNotNull("getRelatedTaxa should return a list", taxonRelations);
481 assertEquals("there should be one TaxonRelationship in the list in the current view",1,taxonRelations.size());
482 }
483
484 @Test
485 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
486 public void testCountRelations() {
487 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
488 assert taxon != null : "taxon cannot be null";
489 assertEquals("countRelatedTaxa should return 1 in the current view",1, taxonDao.countRelatedTaxa(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()));
490 }
491
492 @Test
493 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
494 public void testGetRelationsInPreviousView() {
495 AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
496 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
497 assert taxon != null : "taxon cannot be null";
498
499 List<TaxonRelationship> taxonRelations = taxonDao.getRelatedTaxa(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null);
500 assertNotNull("getRelatedTaxa should return a list",taxonRelations);
501 assertTrue("there should be no TaxonRelationships in the list in the prior view",taxonRelations.isEmpty());
502 }
503
504 @Test
505 @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
506 public void testCountRelationsInPreviousView() {
507 AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
508 Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
509 assert taxon != null : "taxon cannot be null";
510 assertEquals("countRelatedTaxa should return 0 in the current view",0, taxonDao.countRelatedTaxa(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()));
511 }
512 }