Project

General

Profile

Download (43.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/ 
9

    
10
package eu.etaxonomy.cdm.persistence.dao.hibernate.taxon;
11

    
12
import static junit.framework.Assert.assertEquals;
13
import static junit.framework.Assert.assertFalse;
14
import static junit.framework.Assert.assertNotNull;
15
import static junit.framework.Assert.assertSame;
16
import static junit.framework.Assert.assertTrue;
17
import static org.junit.Assert.assertNull;
18
import static org.junit.Assert.fail;
19

    
20
import java.io.FileOutputStream;
21
import java.util.ArrayList;
22
import java.util.HashSet;
23
import java.util.List;
24
import java.util.Set;
25
import java.util.UUID;
26

    
27
import org.hibernate.Hibernate;
28
import org.hibernate.envers.query.AuditEntity;
29
import org.hibernate.envers.query.criteria.AuditCriterion;
30
import org.junit.After;
31
import org.junit.Before;
32
import org.junit.Ignore;
33
import org.junit.Test;
34
import org.unitils.dbunit.annotation.DataSet;
35
import org.unitils.dbunit.annotation.ExpectedDataSet;
36
import org.unitils.spring.annotation.SpringBeanByType;
37

    
38
import eu.etaxonomy.cdm.model.location.NamedArea;
39
import eu.etaxonomy.cdm.model.name.NonViralName;
40
import eu.etaxonomy.cdm.model.name.Rank;
41
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
42
import eu.etaxonomy.cdm.model.reference.Reference;
43
import eu.etaxonomy.cdm.model.taxon.Synonym;
44
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
45
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
46
import eu.etaxonomy.cdm.model.taxon.Taxon;
47
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
48
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
49
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
50
import eu.etaxonomy.cdm.model.taxon.Classification;
51
import eu.etaxonomy.cdm.model.view.AuditEvent;
52
import eu.etaxonomy.cdm.model.view.AuditEventRecord;
53
import eu.etaxonomy.cdm.model.view.context.AuditEventContextHolder;
54
import eu.etaxonomy.cdm.persistence.dao.common.AuditEventSort;
55
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
56
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
57
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
58
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
59
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
60
import eu.etaxonomy.cdm.persistence.query.GroupByCount;
61
import eu.etaxonomy.cdm.persistence.query.GroupByDate;
62
import eu.etaxonomy.cdm.persistence.query.Grouping;
63
import eu.etaxonomy.cdm.persistence.query.MatchMode;
64
import eu.etaxonomy.cdm.persistence.query.NativeSqlOrderHint;
65
import eu.etaxonomy.cdm.persistence.query.OrderHint;
66
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
67
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
68

    
69
/**
70
 * @author a.mueller
71
 * @author ben.clark
72
 *
73
 */
74
public class TaxonDaoHibernateImplTest extends CdmTransactionalIntegrationTest {
75
	
76
	@SpringBeanByType	
77
	private ITaxonDao taxonDao;
78
	
79
	@SpringBeanByType	
80
	private IClassificationDao classificationDao;
81
	
82
	@SpringBeanByType	
83
	private IReferenceDao referenceDao;
84
	
85
	@SpringBeanByType
86
	IDefinedTermDao definedTermDao;
87
	
88
	private UUID uuid;
89
	private UUID sphingidae;
90
	private UUID acherontia;
91
	private UUID mimas;
92
	private UUID rethera;
93
	private UUID retheraSecCdmtest;
94
	private UUID atroposAgassiz;
95
	private UUID atroposLeach;
96
	private UUID acherontiaLachesis;
97
	private AuditEvent previousAuditEvent;
98
	private AuditEvent mostRecentAuditEvent;
99

    
100
	private UUID northernAmericaUuid;
101
	private UUID southernAmericaUuid;
102
	private UUID antarcticaUuid;
103

    
104
	private UUID classificationUuid;
105
	
106

    
107
	@Before
108
	public void setUp() {
109
		
110
		uuid = UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
111
		sphingidae = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
112
		acherontia = UUID.fromString("c5cc8674-4242-49a4-aada-72d63194f5fa");
113
		acherontiaLachesis = UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06");
114
		atroposAgassiz = UUID.fromString("d75b2e3d-7394-4ada-b6a5-93175b8751c1");
115
		atroposLeach =  UUID.fromString("3da4ab34-6c50-4586-801e-732615899b07");
116
		rethera = UUID.fromString("a9f42927-e507-4fda-9629-62073a908aae");
117
		retheraSecCdmtest = UUID.fromString("a9f42927-e507-433a-9629-62073a908aae");
118
		
119
		
120
		mimas = UUID.fromString("900052b7-b69c-4e26-a8f0-01c215214c40");
121
		previousAuditEvent = new AuditEvent();
122
		previousAuditEvent.setRevisionNumber(1025);
123
		previousAuditEvent.setUuid(UUID.fromString("a680fab4-365e-4765-b49e-768f2ee30cda"));
124
		mostRecentAuditEvent = new AuditEvent();
125
		mostRecentAuditEvent.setRevisionNumber(1026);
126
		mostRecentAuditEvent.setUuid(UUID.fromString("afe8e761-8545-497b-9134-6a6791fc0b0d"));
127
		AuditEventContextHolder.clearContext(); // By default we're in the current view (i.e. view == null)
128
		
129
		northernAmericaUuid = UUID.fromString("2757e726-d897-4546-93bd-7951d203bf6f");
130
		southernAmericaUuid = UUID.fromString("6310b3ba-96f4-4855-bb5b-326e7af188ea");
131
		antarcticaUuid = UUID.fromString("791b3aa0-54dd-4bed-9b68-56b4680aad0c");
132
		
133
		classificationUuid = UUID.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
134
	}
135
	
136
	@After
137
	public void tearDown() {
138
		AuditEventContextHolder.clearContext();
139
	}
140
	
141
	/**
142
	 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#TaxonDaoHibernateImpl()}.
143
	 */
144
	@Test
145
	@DataSet
146
	public void testInit() {
147
		logger.warn("testInit()");
148
		assertNotNull("Instance of ITaxonDao expected",taxonDao);
149
		assertNotNull("Instance of IReferenceDao expected",referenceDao);
150
	}
151
	
152
	/**
153
	 * Test method for
154
	 * {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getRootTaxa(eu.etaxonomy.cdm.model.reference.Reference)}
155
	 * .
156
	 */
157
	@Test
158
	@DataSet
159
	public void testGetRootTaxa() {
160
		Reference sec1 = referenceDao.findById(1);
161
		assert sec1 != null : "sec1 must exist";
162
		Reference sec2 = referenceDao.findById(2);
163
		assert sec2 != null : "sec2 must exist";
164

    
165
		List<Taxon> rootTaxa = taxonDao.getRootTaxa(sec1);
166
		assertNotNull("getRootTaxa should return a List", rootTaxa);
167
		assertFalse("The list should not be empty", rootTaxa.isEmpty());
168
		assertEquals("There should be one root taxon", 1, rootTaxa.size());
169

    
170
		rootTaxa = taxonDao.getRootTaxa(sec1, CdmFetch.FETCH_CHILDTAXA(), true, false);
171
		assertNotNull("getRootTaxa should return a List", rootTaxa);
172
		assertFalse("The list should not be empty", rootTaxa.isEmpty());
173
		assertEquals("There should be one root taxon", 1, rootTaxa.size());
174

    
175
		rootTaxa = taxonDao.getRootTaxa(Rank.GENUS(), sec1, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
176
		assertNotNull("getRootTaxa should return a List", rootTaxa);
177
		assertFalse("The list should not be empty", rootTaxa.isEmpty());
178
		assertEquals("There should be one root taxon", 1, rootTaxa.size());
179

    
180
		rootTaxa = taxonDao.getRootTaxa(Rank.FAMILY(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
181
		if (logger.isDebugEnabled()) {
182
			logger.debug("Root taxa rank Family (" + rootTaxa.size() + "):");
183
			for (Taxon taxon : rootTaxa) {
184
				logger.debug(taxon.getTitleCache());
185
			}
186
		}
187
		assertEquals("There should be one root taxon rank Family", 1, rootTaxa.size());
188
		rootTaxa = taxonDao.getRootTaxa(Rank.GENUS(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
189
		assertNotNull("getRootTaxa should return a List", rootTaxa);
190
		assertFalse("The list should not be empty", rootTaxa.isEmpty());
191
		if (logger.isDebugEnabled()) {
192
			logger.debug("Root taxa rank Genus (" + rootTaxa.size() + "):");
193
			for (Taxon taxon : rootTaxa) {
194
				logger.debug(taxon.getTitleCache());
195
			}
196
		}
197
		assertEquals("There should be 22 root taxa rank Genus", 22, rootTaxa.size());
198

    
199
		rootTaxa = taxonDao.getRootTaxa(Rank.SPECIES(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
200
		if (logger.isDebugEnabled()) {
201
			logger.debug("Root taxa rank Species (" + rootTaxa.size() + "):");
202
			for (Taxon taxon : rootTaxa) {
203
				logger.debug(taxon.getTitleCache());
204
			}
205
		}
206
		assertEquals("There should be 4 root taxa rank Species", 3, rootTaxa.size());
207
	}
208
	
209
	/**
210
	 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}.
211
	 */
212
	@Test
213
	@DataSet
214
	public void testGetTaxaByName() {
215
		Reference sec = referenceDao.findById(1);
216
		assert sec != null : "sec must exist";
217

    
218
		List<TaxonBase> results = taxonDao.getTaxaByName("Aus", sec);
219
		assertNotNull("getTaxaByName should return a List", results);
220
		//assertFalse("The list should not be empty", results.isEmpty());
221
		assertTrue(results.size() == 1);
222

    
223
		results = taxonDao.getTaxaByName("A*", MatchMode.BEGINNING, 
224
				true, null, null);
225
		assertNotNull("getTaxaByName should return a List", results);
226
		assertTrue(results.size() == 9);
227

    
228
		if (logger.isDebugEnabled()) {
229
			for (int i = 0; i < results.size(); i++) {
230
				String nameCache = "";
231
				TaxonNameBase<?,?> taxonNameBase= ((TaxonBase)results.get(i)).getName();
232
				nameCache = ((NonViralName)taxonNameBase).getNameCache();
233
				logger.debug(results.get(i).getClass() + "(" + i +")" + 
234
						": Name Cache = " + nameCache + ", Title Cache = " + results.get(i).getTitleCache());
235
			}
236
		}
237
//		assertEquals(results.get(0).getTitleCache(), "Abies sec. ???");
238
//		assertEquals(results.get(1).getTitleCache(), "Abies Mill.");
239
//		assertEquals(results.get(2).getTitleCache(), "Abies mill. sec. ???");
240
//		assertEquals(results.get(3).getTitleCache(), "Abies alba sec. ???");
241
//		assertEquals(results.get(4).getTitleCache(), "Abies alba Michx. sec. ???");
242
//		assertEquals(results.get(5).getTitleCache(), "Abies alba Mill. sec. ???");
243

    
244
		results = taxonDao.getTaxaByName("A", MatchMode.BEGINNING, true, null, null);
245
		assertNotNull("getTaxaByName should return a List", results);
246
		assertTrue(results.size() == 9);
247
		
248
		results = taxonDao.getTaxaByName("Aus", MatchMode.EXACT, true, null, null);
249
		assertNotNull("getTaxaByName should return a List", results);
250
		assertEquals("Results list should contain one entity",1,results.size());
251
	}	
252
	
253
	/**
254
	 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}
255
	 * restricting the search by a set of Areas.
256
	 */
257
	@SuppressWarnings("unchecked")
258
	@Test
259
	@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
260
	public void testGetTaxaByNameAndArea() {
261
		
262
		Set<NamedArea> namedAreas = new HashSet<NamedArea>();
263
		namedAreas.add((NamedArea)definedTermDao.load(northernAmericaUuid));
264
		//namedAreas.add((NamedArea)definedTermDao.load(southernAmericaUuid));
265
		//namedAreas.add((NamedArea)definedTermDao.load(antarcticaUuid));
266

    
267
		Classification taxonmicTree = classificationDao.findByUuid(classificationUuid);
268
		
269
		// prepare some synonym relation ships for some tests
270
		Synonym synAtroposAgassiz = (Synonym)taxonDao.findByUuid(atroposAgassiz);
271
		Taxon taxonRethera = (Taxon)taxonDao.findByUuid(rethera);
272
		taxonRethera.addSynonym(synAtroposAgassiz, SynonymRelationshipType.SYNONYM_OF());
273
		logger.warn("addSynonym(..)");
274
		this.taxonDao.clear();
275
		Synonym synAtroposLeach = (Synonym)taxonDao.findByUuid(atroposLeach);
276
		Taxon taxonRetheraSecCdmtest = (Taxon)taxonDao.findByUuid(retheraSecCdmtest);
277
		taxonRetheraSecCdmtest.addSynonym(synAtroposLeach, SynonymRelationshipType.SYNONYM_OF());
278
		this.taxonDao.clear();
279
		// 1. searching for a taxon (Rethera)
280
		//long numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "Rethera", null, MatchMode.BEGINNING, namedAreas);
281
		
282
		List<TaxonBase> results = taxonDao.getTaxaByName(Taxon.class, "Rethera", null, MatchMode.BEGINNING, namedAreas,
283
			null, null, null);
284
		assertNotNull("getTaxaByName should return a List", results);
285
		assertTrue("expected to find two taxa but found "+results.size(), results.size() == 2);
286
		
287
		// 2. searching for a taxon (Rethera) contained in a specific classification
288
		results = taxonDao.getTaxaByName(Taxon.class, "Rethera", taxonmicTree, MatchMode.BEGINNING, namedAreas,
289
			null, null, null);
290
		assertNotNull("getTaxaByName should return a List", results);
291
		assertTrue("expected to find one taxon but found "+results.size(), results.size() == 1);
292
		
293

    
294
		// 3. searching for Synonyms
295
		results = taxonDao.getTaxaByName(Synonym.class, "Atropo", null, MatchMode.ANYWHERE, null,
296
			null, null, null);
297
		assertNotNull("getTaxaByName should return a List", results);
298
	
299
		assertTrue("expected to find two taxa but found "+results.size(), results.size() == 3);
300
		
301
		// 4. searching for Synonyms
302
		results = taxonDao.getTaxaByName(Synonym.class, "Atropo", null, MatchMode.BEGINNING, null,
303
			null, null, null);
304
		assertNotNull("getTaxaByName should return a List", results);
305
		assertTrue("expected to find two taxa but found "+results.size(), results.size() == 3);
306
		
307
		
308
		// 5. searching for a Synonyms and Taxa
309
		//   create a synonym relationship first
310
		results = taxonDao.getTaxaByName(TaxonBase.class, "A", null, MatchMode.BEGINNING, namedAreas,
311
			null, null, null);
312
		assertNotNull("getTaxaByName should return a List", results);
313
		assertTrue("expected to find 8 taxa but found "+results.size(), results.size() == 8);
314
	}
315

    
316
	
317
	/**
318
	 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#findByNameTitleCache(Class<? extends TaxonBase>clazz, String queryString, Classification classification, MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageNumber, Integer pageSize, List<String> propertyPaths)}
319
	 * restricting the search by a set of Areas.
320
	 */
321
	@SuppressWarnings("unchecked")
322
	@Test
323
	@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
324
	public void testFindByNameTitleCache() {
325
		
326
		Set<NamedArea> namedAreas = new HashSet<NamedArea>();
327
		namedAreas.add((NamedArea)definedTermDao.load(northernAmericaUuid));
328
		//namedAreas.add((NamedArea)definedTermDao.load(southernAmericaUuid));
329
		//namedAreas.add((NamedArea)definedTermDao.load(antarcticaUuid));
330

    
331
		Classification classification = classificationDao.findByUuid(classificationUuid);
332
		
333
		// prepare some synonym relation ships for some tests
334
		Synonym synAtroposAgassiz = (Synonym)taxonDao.findByUuid(atroposAgassiz);
335
		Taxon taxonRethera = (Taxon)taxonDao.findByUuid(rethera);
336
		taxonRethera.addSynonym(synAtroposAgassiz, SynonymRelationshipType.SYNONYM_OF());
337
		logger.warn("addSynonym(..)");
338
		this.taxonDao.clear();
339
		Synonym synAtroposLeach = (Synonym)taxonDao.findByUuid(atroposLeach);
340
		Taxon taxonRetheraSecCdmtest = (Taxon)taxonDao.findByUuid(retheraSecCdmtest);
341
		taxonRetheraSecCdmtest.addSynonym(synAtroposLeach, SynonymRelationshipType.SYNONYM_OF());
342
		this.taxonDao.clear();
343
		// 1. searching for a taxon (Rethera)
344
		//long numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "Rethera", null, MatchMode.BEGINNING, namedAreas);
345
		
346
		List<TaxonBase> results = taxonDao.findByNameTitleCache(Taxon.class, "Rethera Rothschild & Jordan, 1903", null, MatchMode.EXACT, namedAreas,
347
			null, null, null);
348
		assertNotNull("getTaxaByName should return a List", results);
349
		assertTrue("expected to find two taxa but found "+results.size(), results.size() == 2);
350
		
351
		// 2. searching for a taxon (Rethera) contained in a specific classification
352
		results = taxonDao.findByNameTitleCache(Taxon.class, "Rethera Rothschild & Jordan, 1903", classification, MatchMode.EXACT, namedAreas,
353
			null, null, null);
354
		assertNotNull("getTaxaByName should return a List", results);
355
		assertTrue("expected to find one taxon but found "+results.size(), results.size() == 1);
356
		
357

    
358
		// 3. searching for Synonyms
359
		results = taxonDao.findByNameTitleCache(Synonym.class, "Atropo", null, MatchMode.ANYWHERE, null,
360
			null, null, null);
361
		assertNotNull("getTaxaByName should return a List", results);
362
	
363
		assertTrue("expected to find two taxa but found "+results.size(), results.size() == 3);
364
		
365
		// 4. searching for Synonyms
366
		results = taxonDao.findByNameTitleCache(Synonym.class, "Atropo", null, MatchMode.BEGINNING, null,
367
			null, null, null);
368
		assertNotNull("getTaxaByName should return a List", results);
369
		assertTrue("expected to find two taxa but found "+results.size(), results.size() == 3);
370
		
371
		
372
		// 5. searching for a Synonyms and Taxa
373
		//   create a synonym relationship first
374
		results = taxonDao.findByNameTitleCache(TaxonBase.class, "A", null, MatchMode.BEGINNING, namedAreas,
375
			null, null, null);
376
		assertNotNull("getTaxaByName should return a List", results);
377
		assertTrue("expected to find 8 taxa but found "+results.size(), results.size() == 8);
378
	}
379

    
380
	
381
	@Test
382
	@DataSet
383
	public void testFindByUuid() {
384
		Taxon taxon = (Taxon)taxonDao.findByUuid(uuid);
385
		assertNotNull("findByUuid should return a taxon",taxon);
386
		assertFalse("findByUuid should not return a taxon with it's name initialized",Hibernate.isInitialized(taxon.getName()));
387
	}
388
	
389
	@Test
390
	@DataSet
391
	public void testLoad() {
392
		List<String> propertyPaths = new ArrayList<String>();
393
		propertyPaths.add("name");
394
		propertyPaths.add("sec");
395
		Taxon taxon = (Taxon)taxonDao.load(uuid, propertyPaths);
396
		assertNotNull("findByUuid should return a taxon",taxon);
397
		assertTrue("load should return a taxon with it's name initialized, given that the property was specified in the method",Hibernate.isInitialized(taxon.getName()));
398
		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()));
399
	}
400
	
401
	@Test
402
	@DataSet
403
	public void testCountTaxonRelationships()	{
404
		Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
405
		assert taxon != null : "taxon must exist"; 
406
		
407
		int numberOfRelatedTaxa = taxonDao.countTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), TaxonRelationship.Direction.relatedTo);
408
		assertEquals("countTaxonRelationships should return 23", 23, numberOfRelatedTaxa);
409
	}
410
	
411
	@Test
412
	@DataSet
413
	public void testCountTaxaByName() {
414
		long numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "A*", null, MatchMode.BEGINNING, null);
415
		assertEquals(numberOfTaxa, 9);
416
		numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "A*", null, MatchMode.BEGINNING, null);
417
		assertEquals(numberOfTaxa, 9);
418
		numberOfTaxa = taxonDao.countTaxaByName(Synonym.class, "A*", null, MatchMode.BEGINNING, null);
419
		assertEquals(numberOfTaxa, 3);
420
		numberOfTaxa = taxonDao.countTaxaByName(TaxonBase.class, "A*", null, MatchMode.BEGINNING, null);
421
		assertEquals(numberOfTaxa, 12);
422
		numberOfTaxa = taxonDao.countTaxaByName(TaxonBase.class, "Aasfwerfwf fffe", null, MatchMode.BEGINNING, null);
423
		assertEquals(numberOfTaxa, 0);
424
//	FIXME implement test for search in specific classification 		
425
//		Reference reference = referenceDao.findByUuid(UUID.fromString("596b1325-be50-4b0a-9aa2-3ecd610215f2"));
426
//		numberOfTaxa = taxonDao.countTaxaByName("A*", MatchMode.BEGINNING, SelectMode.ALL, null, null);
427
//		assertEquals(numberOfTaxa, 2);
428
	}
429
	
430
	@Test
431
	@DataSet
432
	public void testRelatedTaxa() {
433
		Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
434
		assert taxon != null : "taxon must exist"; 
435
		
436
		List<String> propertyPaths = new ArrayList<String>();
437
		propertyPaths.add("fromTaxon");
438
		propertyPaths.add("fromTaxon.name");
439
		List<OrderHint> orderHints = new ArrayList<OrderHint>();
440
		orderHints.add(new OrderHint("relatedFrom.name.genusOrUninomial", SortOrder.ASCENDING));
441
		orderHints.add(new OrderHint("relatedFrom.name.specificEpithet", SortOrder.ASCENDING));
442
		orderHints.add(new OrderHint("relatedFrom.name.infraSpecificEpithet", SortOrder.ASCENDING));
443
		                                               
444
		List<TaxonRelationship> relatedTaxa = taxonDao.getTaxonRelationships(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null, orderHints,propertyPaths, TaxonRelationship.Direction.relatedTo);
445
		assertNotNull("getRelatedTaxa should return a List",relatedTaxa);
446
		assertEquals("getRelatedTaxa should return all 23 related taxa",relatedTaxa.size(),23);
447
		assertTrue("getRelatedTaxa should return TaxonRelationship objects with the relatedFrom taxon initialized",Hibernate.isInitialized(relatedTaxa.get(0).getFromTaxon()));
448
		assertTrue("getRelatedTaxa should return TaxonRelationship objects with the relatedFrom taxon initialized",Hibernate.isInitialized(relatedTaxa.get(0).getFromTaxon().getName()));
449
		
450
		assertEquals("Acherontia should appear first in the list of related taxa", relatedTaxa.get(0).getFromTaxon().getTitleCache(), "Acherontia Laspeyres, 1809 sec. cate-sphingidae.org");
451
		assertEquals("Sphingonaepiopsis should appear last in the list of related taxa", relatedTaxa.get(22).getFromTaxon().getTitleCache(), "Sphinx Linnaeus, 1758 sec. cate-sphingidae.org");
452
	}
453
	
454
	@Test
455
	@DataSet
456
	public void testGetRelatedTaxaPaged()	{
457
		Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
458
		assert taxon != null : "taxon must exist";
459
		
460
		List<String> propertyPaths = new ArrayList<String>();
461
		propertyPaths.add("fromTaxon");
462
		propertyPaths.add("fromTaxon.name");
463
		
464
		List<OrderHint> orderHints = new ArrayList<OrderHint>();
465
		orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));
466
		
467
		List<TaxonRelationship> firstPage = taxonDao.getTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), 10, 0, orderHints,propertyPaths, TaxonRelationship.Direction.relatedTo);
468
		List<TaxonRelationship> secondPage = taxonDao.getTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),10, 1, orderHints,propertyPaths, TaxonRelationship.Direction.relatedTo);
469
		List<TaxonRelationship> thirdPage = taxonDao.getTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), 10, 2, orderHints,propertyPaths, TaxonRelationship.Direction.relatedTo);
470
		
471
		assertNotNull("getRelatedTaxa: 10, 0 should return a List",firstPage);
472
		assertEquals("getRelatedTaxa: 10, 0 should return a List with 10 elements",10,firstPage.size());
473
		assertNotNull("getRelatedTaxa: 10, 1 should return a List",secondPage);
474
		assertEquals("getRelatedTaxa: 10, 1 should return a List with 10 elements",secondPage.size(),10);
475
		assertNotNull("getRelatedTaxa: 10, 2 should return a List",thirdPage);
476
		assertEquals("getRelatedTaxa: 10, 2 should return a List with 3 elements",thirdPage.size(),3);
477
	}
478
	
479
	@Test
480
	@DataSet
481
	public void testCountSynonymRelationships() {
482
		Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
483
		assert taxon != null : "taxon must exist";
484
		
485
		int numberOfSynonymRelationships = taxonDao.countSynonyms(taxon,null);
486
		assertEquals("countSynonymRelationships should return 5",5,numberOfSynonymRelationships);
487
	}
488
	
489
	@Test
490
	@DataSet
491
	public void testSynonymRelationships()	{
492
		Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
493
		assert taxon != null : "taxon must exist";
494
		List<String> propertyPaths = new ArrayList<String>();
495
		propertyPaths.add("synonym");
496
		propertyPaths.add("synonym.name");
497
		
498
		List<OrderHint> orderHints = new ArrayList<OrderHint>();
499
		orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));
500
		
501
		List<SynonymRelationship> synonyms = taxonDao.getSynonyms(taxon, null, null, null,orderHints,propertyPaths);
502
		
503
		assertNotNull("getSynonyms should return a List",synonyms);
504
		assertEquals("getSynonyms should return 5 SynonymRelationship entities",synonyms.size(),5);
505
		assertTrue("getSynonyms should return SynonymRelationship objects with the synonym initialized",Hibernate.isInitialized(synonyms.get(0).getSynonym()));
506
	}
507
	
508
	@Test
509
	@DataSet
510
	public void testCountSynonymRelationshipsByType()	{
511
		Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
512
		assert taxon != null : "taxon must exist";
513
		
514
		int numberOfTaxonomicSynonyms = taxonDao.countSynonyms(taxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
515
		assertEquals("countSynonyms should return 4",numberOfTaxonomicSynonyms, 4);
516
	}
517
	
518
	@Test
519
	@DataSet
520
	public void testSynonymRelationshipsByType() {
521
		Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
522
		assert taxon != null : "taxon must exist";
523
		
524
        List<SynonymRelationship> synonyms = taxonDao.getSynonyms(taxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null,null,null);
525
		
526
        assertNotNull("getSynonyms should return a List",synonyms);
527
		assertEquals("getSynonyms should return 4 SynonymRelationship entities",synonyms.size(),4);
528
	}
529
	
530
	@Test
531
	@DataSet
532
	public void testPageSynonymRelationships(){
533
		Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
534
		assert taxon != null : "taxon must exist";
535
		
536
		List<SynonymRelationship> firstPage = taxonDao.getSynonyms(taxon, null, 4, 0,null,null);
537
		List<SynonymRelationship> secondPage = taxonDao.getSynonyms(taxon, null, 4, 1,null,null);
538
		
539
		assertNotNull("getSynonyms: 4, 0 should return a List",firstPage);
540
		assertEquals("getSynonyms: 4, 0 should return 4 SynonymRelationships", firstPage.size(),4);
541
		assertNotNull("getSynonyms: 4, 1 should return a List",secondPage);
542
		assertEquals("getSynonyms: 4, 1 should return 1 SynonymRelationship",secondPage.size(),1);
543
	}
544
	
545
	@Test
546
	@DataSet
547
	public void testGetTaxonMatchingUninomial() {
548
		List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class, "Smerinthus", "*", "*", "*",null,null,null);
549
		
550
		assertNotNull("findTaxaByName should return a List", result);
551
		assertEquals("findTaxaByName should return two Taxa",2,result.size());
552
		assertEquals("findTaxaByName should return a Taxon with id 5",5,result.get(0).getId());
553
	}
554
	
555
	@Test
556
	@DataSet
557
	public void testGetTaxonMatchingSpeciesBinomial() {
558
		List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Smerinthus", null, "kindermannii", null,null,null,null);
559
		
560
		assertNotNull("findTaxaByName should return a List", result);
561
		assertEquals("findTaxaByName should return one Taxon",1,result.size());
562
		assertEquals("findTaxaByName should return a Taxon with id 8",8,result.get(0).getId());
563
	}
564
	  
565
	@Test
566
	@DataSet
567
	public void testGetTaxonMatchingTrinomial() {
568
		List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Cryptocoryne", null,"purpurea","borneoensis",null,null,null);
569
		
570
		assertNotNull("findTaxaByName should return a List", result);
571
		assertEquals("findTaxaByName should return one Taxon",1,result.size());
572
		assertEquals("findTaxaByName should return a Taxon with id 38",38,result.get(0).getId());
573
	}
574
	
575
	@Test
576
	@DataSet
577
	public void testNegativeMatch() {
578
		List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Acherontia", null,"atropos","dehli",null,null,null);
579
		
580
		assertNotNull("findTaxaByName should return a List", result);
581
		assertTrue("findTaxaByName should return an empty List",result.isEmpty());
582
	}
583
	
584
	@Test
585
	@DataSet
586
	public void testCountAllTaxa() {
587
		int numberOfTaxa = taxonDao.count(Taxon.class);
588
		assertEquals("count should return 33 taxa",33, numberOfTaxa);
589
	}
590
	
591
	@Test
592
	@DataSet
593
	public void testListAllTaxa() {
594
		List<TaxonBase> taxa = taxonDao.list(Taxon.class,100, 0);
595
		assertNotNull("list should return a List",taxa);
596
		assertEquals("list should return 33 taxa",33, taxa.size());
597
	}
598
	
599
	@Test
600
	@DataSet
601
	@ExpectedDataSet
602
	public void testDelete() {
603
		Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
604
		assert taxon != null : "taxon must exist";
605
		taxonDao.delete(taxon);
606
		setComplete();
607
		endTransaction();
608
		try {printDataSet(new FileOutputStream("test.xml"));} catch(Exception e) { } 
609
	}
610
	
611
	@Test
612
	@DataSet
613
	public void testDeleteWithChildren() {
614
		Taxon taxonWithChildren = (Taxon)taxonDao.findByUuid(mimas);
615
		assert taxonWithChildren != null : "taxon must exist";
616
		assertEquals(taxonWithChildren.getTaxonomicChildrenCount(), 2);
617
		Taxon parent = (Taxon)taxonDao.findByUuid(sphingidae);
618
		assertSame(taxonWithChildren.getTaxonomicParent(), parent);
619
		assertEquals(parent.getTaxonomicChildrenCount(), 204);
620
		taxonDao.delete(taxonWithChildren);
621
		assertEquals(parent.getTaxonomicChildrenCount(), 203);
622
	}
623
	
624
	@Test
625
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
626
    public void testFindDeleted() {
627
    	TaxonBase taxon = taxonDao.findByUuid(acherontia);
628
    	assertNull("findByUuid should return null in this view", taxon);
629
    	assertFalse("exist should return false in this view",taxonDao.exists(acherontia));
630
    }
631
    
632
    @Test
633
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
634
    public void testFindDeletedInPreviousView() {
635
    	AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
636
    	Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
637
    	assertNotNull("findByUuid should return a taxon in this view",taxon);
638
    	assertTrue("exists should return true in this view", taxonDao.exists(acherontia));
639
    	    	
640
    	try{
641
    		assertEquals("There should be 3 relations to this taxon in this view",3,taxon.getRelationsToThisTaxon().size());
642
    	} catch(Exception e) {
643
    		fail("We should not experience any problems initializing proxies with envers");
644
    	}
645
    }
646
    
647
    @Test
648
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
649
    public void testGetAuditEvents() {
650
    	TaxonBase taxon = taxonDao.findByUuid(sphingidae);
651
    	assert taxon != null : "taxon cannot be null";
652
    	
653
    	List<String> propertyPaths = new ArrayList<String>();
654
    	propertyPaths.add("name");
655
    	propertyPaths.add("createdBy");
656
    	propertyPaths.add("updatedBy");
657
    	
658
    	List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(taxon, null,null,null,propertyPaths);
659
    	assertNotNull("getAuditEvents should return a list",auditEvents);
660
    	assertFalse("the list should not be empty",auditEvents.isEmpty());
661
    	assertEquals("There should be two AuditEventRecords in the list",2, auditEvents.size());
662
    }
663
    
664
    @Test
665
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
666
    public void testGetAuditEventsFromNow() {
667
    	AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
668
    	TaxonBase taxon =  taxonDao.findByUuid(sphingidae);
669
    	assert taxon != null : "taxon cannot be null";
670
    	
671
    	List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(taxon, null,null,AuditEventSort.FORWARDS,null);
672
    	assertNotNull("getAuditEvents should return a list",auditEvents);
673
    	assertFalse("the list should not be empty",auditEvents.isEmpty());
674
    	assertEquals("There should be one audit event in the list",1,auditEvents.size());
675
    }
676

    
677
    @Test
678
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
679
    public void testCountAuditEvents() {
680
    	TaxonBase taxon = taxonDao.findByUuid(sphingidae);
681
    	assert taxon != null : "taxon cannot be null";
682
    	
683
    	int numberOfAuditEvents = taxonDao.countAuditEvents(taxon,null);
684
    	assertEquals("countAuditEvents should return 2",numberOfAuditEvents,2);
685
    }
686
    
687
    @Test
688
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
689
    public void getPreviousAuditEvent() {
690
    	TaxonBase taxon = taxonDao.findByUuid(sphingidae);
691
    	assert taxon != null : "taxon cannot be null";
692
    	
693
    	AuditEventRecord<TaxonBase> auditEvent = taxonDao.getPreviousAuditEvent(taxon);
694
    	assertNotNull("getPreviousAuditEvent should not return null as there is at least one audit event prior to the current one",auditEvent);
695
    }
696
    
697
    @Test
698
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
699
    public void getPreviousAuditEventAtBeginning() {
700
    	AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
701
    	TaxonBase taxon = taxonDao.findByUuid(sphingidae);
702
    	assert taxon != null : "taxon cannot be null";
703
    	
704
    	AuditEventRecord<TaxonBase> auditEvent = taxonDao.getPreviousAuditEvent(taxon);
705
    	assertNull("getPreviousAuditEvent should return null if we're at the first audit event anyway",auditEvent);
706
    }
707
    
708
    @Test
709
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
710
    public void getNextAuditEvent() {
711
    	AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
712
    	TaxonBase taxon = taxonDao.findByUuid(sphingidae);
713
    	assert taxon != null : "taxon cannot be null";
714
    	
715
    	AuditEventRecord<TaxonBase> auditEvent = taxonDao.getNextAuditEvent(taxon);
716
    	assertNotNull("getNextAuditEvent should not return null as there is at least one audit event after the current one",auditEvent);
717
    }
718
    
719
    @Test
720
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
721
    public void getNextAuditEventAtEnd() {
722
    	AuditEventContextHolder.getContext().setAuditEvent(mostRecentAuditEvent);
723
    	TaxonBase taxon = taxonDao.findByUuid(sphingidae);
724
    	assert taxon != null : "taxon cannot be null";
725
    	
726
    	AuditEventRecord<TaxonBase> auditEvent = taxonDao.getNextAuditEvent(taxon);
727
    	assertNull("getNextAuditEvent should return null as there no more audit events after the current one",auditEvent);
728
    }
729
    
730
	@Test
731
	@DataSet
732
	@ExpectedDataSet
733
	@Ignore
734
	public void testAddChild() throws Exception {
735
		Taxon parent = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
736
		assert parent != null : "taxon cannot be null";
737
		Taxon child = Taxon.NewInstance(null, null);
738
		child.setTitleCache("Acherontia lachesis diehli Eitschberger, 2003", true);
739
		child.addTaxonRelation(parent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),null, null);
740
		taxonDao.save(child);
741
		setComplete();
742
		endTransaction();
743
	}
744
	
745
    @Test
746
    @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
747
    public void testFind() {
748
    	Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
749
    	assert taxon != null : "taxon cannot be null";
750
    	
751
    	assertEquals("getTaxonomicChildrenCount should return 1 in this view",1,taxon.getTaxonomicChildrenCount());
752
    	assertEquals("getRelationsToThisTaxon should contain 1 TaxonRelationship in this view",1,taxon.getRelationsToThisTaxon().size());
753
    }
754
    
755
    @Test
756
    @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
757
    public void testFindInPreviousView() {
758
    	AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
759
    	Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
760
    	assert taxon != null : "taxon cannot be null";
761
    	
762
    	assertEquals("getTaxonomicChildrenCount should return 0 in this view",0,taxon.getTaxonomicChildrenCount());
763
    	assertTrue("getRelationsToThisTaxon should contain 0 TaxonRelationship in this view",taxon.getRelationsToThisTaxon().isEmpty());
764
    }
765
    
766
    @Test
767
    @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
768
    public void testGetRelations() {
769
    	Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
770
    	assert taxon != null : "taxon cannot be null";
771
    	
772
    	List<String> propertyPaths = new ArrayList<String>();
773
 	    propertyPaths.add("fromTaxon");
774
 	    propertyPaths.add("fromTaxon.name");
775
 		
776
 	    List<OrderHint> orderHints = new ArrayList<OrderHint>();
777
 	    orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));
778
    	
779
    	List<TaxonRelationship> taxonRelations = taxonDao.getTaxonRelationships(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null,orderHints,propertyPaths, TaxonRelationship.Direction.relatedFrom);
780
    	assertNotNull("getRelatedTaxa should return a list", taxonRelations);
781
    	assertEquals("there should be one TaxonRelationship in the list in the current view",1,taxonRelations.size());
782
    	assertTrue("TaxonRelationship.relatedFrom should be initialized",Hibernate.isInitialized(taxonRelations.get(0).getFromTaxon()));
783
    	assertTrue("TaxonRelationship.relatedFrom.name should be initialized",Hibernate.isInitialized(taxonRelations.get(0).getFromTaxon().getName()));
784
    }
785
    
786
    @Test
787
    @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
788
    public void testCountRelations() {
789
    	Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
790
    	assert taxon != null : "taxon cannot be null";
791
    	assertEquals("countRelatedTaxa should return 1 in the current view",1, taxonDao.countTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), TaxonRelationship.Direction.relatedTo));
792
    }
793
    
794
    @Test
795
    @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
796
    public void testGetRelationsInPreviousView() {
797
       AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
798
       Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
799
       assert taxon != null : "taxon cannot be null";
800
       
801
       List<String> propertyPaths = new ArrayList<String>();
802
	   propertyPaths.add("relatedFrom");
803
	   propertyPaths.add("relatedFrom.name");
804
		
805
	   List<OrderHint> orderHints = new ArrayList<OrderHint>();
806
	   orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));
807
    
808
       List<TaxonRelationship> taxonRelations = taxonDao.getTaxonRelationships(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null,orderHints,propertyPaths, TaxonRelationship.Direction.relatedFrom);
809
       assertNotNull("getRelatedTaxa should return a list",taxonRelations);
810
       assertTrue("there should be no TaxonRelationships in the list in the prior view",taxonRelations.isEmpty());
811
    }
812
    
813
    @Test
814
    @DataSet("TaxonDaoHibernateImplTest.testFind.xml")
815
    public void testCountRelationsInPreviousView() {
816
    	AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
817
    	Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
818
    	assert taxon != null : "taxon cannot be null";
819
    	assertEquals("countRelatedTaxa should return 0 in the current view",0, taxonDao.countTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), TaxonRelationship.Direction.relatedTo));
820
    }
821
    
822
	@Test
823
	@DataSet
824
	public void testGroupTaxa() { 
825
		List<Grouping> groups = new ArrayList<Grouping>();
826
		groups.add(new GroupByCount("count",SortOrder.DESCENDING));
827
		groups.add(new Grouping("name.genusOrUninomial", "genus", "n", SortOrder.ASCENDING));
828
		List<Object[]> results = taxonDao.group(null, null, null, groups,null);
829
		System.out.println("count\tname.genuOrUninomial");
830
		for(Object[] result : results) {
831
			System.out.println(result[0] + "\t" + result[1]);
832
		}
833
	}
834
	
835
	@Test
836
	@DataSet
837
	public void testGroupTaxaByClass() { 
838
		List<Grouping> groups = new ArrayList<Grouping>();
839
		groups.add(new GroupByCount("count",SortOrder.DESCENDING));
840
		groups.add(new Grouping("class", "class",null, SortOrder.ASCENDING));
841
		List<Object[]> results = taxonDao.group(null, null, null, groups,null);
842
		System.out.println("count\tclass");
843
		for(Object[] result : results) {
844
			System.out.println(result[0] + "\t" + result[1]);
845
		}
846
	}
847
	
848
	@Test
849
	@DataSet
850
	public void testNativeSQLOrder() { 
851
		List<OrderHint> orderHints = new ArrayList<OrderHint>();
852
		orderHints.add(new NativeSqlOrderHint("case when {alias}.titleCache like 'C%' then 0 else 1 end",SortOrder.ASCENDING));
853
		
854
		List<TaxonBase> results = taxonDao.list(null, null, orderHints);
855
		System.out.println("native SQL order");
856
		for(TaxonBase result : results) {
857
			System.out.println(result.getTitleCache());
858
		}
859
	}
860
	
861
	@Test
862
	@DataSet
863
	public void testGroupByDateTaxa() { 
864
		List<Grouping> groups = new ArrayList<Grouping>();
865
		groups.add(new GroupByCount("count",null));
866
		groups.add(new GroupByDate("created", "dateGroup", SortOrder.ASCENDING, GroupByDate.Resolution.MONTH));
867
		List<Object[]> results = taxonDao.group(null, null, null, groups,null);
868
		System.out.println("count\tyear\tmonth");
869
		for(Object[] result : results) {
870
			System.out.println(result[0] + "\t" + result[1] + "\t" + result[2]);
871
		}
872
	}
873
    
874
    @Test
875
    @DataSet
876
	public final void testGetTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(){
877
    	Classification classification = classificationDao.findByUuid(classificationUuid);
878
		assertNotNull(taxonDao.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(classification));
879
	}
880
    
881
    @Test
882
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
883
    public void testGetAuditEventsByType() {
884
    	
885
    	List<String> propertyPaths = new ArrayList<String>();
886
    	propertyPaths.add("name");
887
    	propertyPaths.add("createdBy");
888
    	propertyPaths.add("updatedBy");
889
    	
890
    	List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(TaxonBase.class, previousAuditEvent, mostRecentAuditEvent, null,null, null, AuditEventSort.FORWARDS, propertyPaths);
891
    	assertNotNull("getAuditEvents should return a list",auditEvents);
892
    	assertFalse("the list should not be empty",auditEvents.isEmpty());
893
    	assertEquals("There should be thirty eight AuditEventRecords in the list",38, auditEvents.size());
894
    }
895
    
896
    @Test
897
    @Ignore
898
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
899
    public void testGetAuditEventsByTypeWithRestrictions() {
900
    	
901
    	List<String> propertyPaths = new ArrayList<String>();
902
    	propertyPaths.add("name");
903
    	propertyPaths.add("createdBy");
904
    	propertyPaths.add("updatedBy");
905
    	
906
    	List<AuditCriterion> criteria = new ArrayList<AuditCriterion>();
907
    	criteria.add(AuditEntity.property("lsid_lsid").isNotNull());
908
    	
909
    	List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(TaxonBase.class, previousAuditEvent, mostRecentAuditEvent, criteria,null, null, AuditEventSort.FORWARDS, propertyPaths);
910
    	assertNotNull("getAuditEvents should return a list",auditEvents);
911
    	assertFalse("the list should not be empty",auditEvents.isEmpty());
912
    	assertEquals("There should be one AuditEventRecord in the list",1, auditEvents.size());
913
    }
914
    @Test
915
    @DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
916
    public void testGetCommonName(){
917
    	
918
    	
919
    	List textData = taxonDao.getTaxaByCommonName("common%", null,
920
    			MatchMode.BEGINNING, null, null, null, null);
921
    	
922
    	assertNotNull("getTaxaByCommonName should return a list", textData);
923
    	assertFalse("the list should not be empty", textData.isEmpty());
924
    	assertEquals("There should be one Taxon with common name", 1,textData.size());
925
//    	System.err.println("Number of common names: " +textData.size());
926
    	
927
    }
928
    
929
    @Test
930
    @DataSet("TaxonNodeDaoHibernateImplTest.xml")
931
    @Ignore
932
    public void testCreateInferredSynonymy(){
933
    	Classification tree = this.classificationDao.findById(1);
934
    	Taxon taxon = (Taxon)taxonDao.findByUuid(UUID.fromString("bc09aca6-06fd-4905-b1e7-cbf7cc65d783"));
935
    	List <Synonym> synonyms = taxonDao.getAllSynonyms(null, null);
936
    	assertEquals("Number of synonyms should be 2",2,synonyms.size());
937
    	
938
    	//synonyms = taxonDao.getAllSynonyms(null, null);
939
    	//assertEquals("Number of synonyms should be 2",2,synonyms.size());
940
    	List<Synonym> inferredSynonyms = taxonDao.createInferredSynonyms(taxon, tree, SynonymRelationshipType.INFERRED_EPITHET_OF());
941
    	assertNotNull("there should be a new synonym ", inferredSynonyms);
942
    	System.err.println(inferredSynonyms.get(0).getTitleCache());
943
    	assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms.get(0).getTitleCache(), "SynGenus lachesis sec. ???");
944
    	inferredSynonyms = taxonDao.createInferredSynonyms(taxon, tree, SynonymRelationshipType.INFERRED_GENUS_OF());
945
    	assertNotNull("there should be a new synonym ", inferredSynonyms);
946
    	System.err.println(inferredSynonyms.get(0).getTitleCache());
947
    	assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms.get(0).getTitleCache(), "Acherontia ciprosus sec. ???");
948
    	inferredSynonyms = taxonDao.createInferredSynonyms(taxon, tree, SynonymRelationshipType.POTENTIAL_COMBINATION_OF());
949
    	assertNotNull("there should be a new synonym ", inferredSynonyms);
950
    	assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms.get(0).getTitleCache(), "SynGenus ciprosus sec. ???");
951
    	
952
    	//assertTrue("set of synonyms should contain an inferred Synonym ", synonyms.contains(arg0))
953
    }
954
    
955
    
956
    
957
}
(1-1/2)