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.Iterator;
|
24
|
import java.util.List;
|
25
|
import java.util.Set;
|
26
|
import java.util.UUID;
|
27
|
|
28
|
import org.hibernate.Hibernate;
|
29
|
import org.hibernate.envers.query.AuditEntity;
|
30
|
import org.hibernate.envers.query.criteria.AuditCriterion;
|
31
|
import org.junit.After;
|
32
|
import org.junit.Before;
|
33
|
import org.junit.Ignore;
|
34
|
import org.junit.Test;
|
35
|
import org.unitils.dbunit.annotation.DataSet;
|
36
|
import org.unitils.dbunit.annotation.ExpectedDataSet;
|
37
|
import org.unitils.spring.annotation.SpringBeanByType;
|
38
|
|
39
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
40
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
41
|
import eu.etaxonomy.cdm.model.name.Rank;
|
42
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
43
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
44
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
45
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
|
46
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
47
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
48
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
49
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
50
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
51
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
52
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
53
|
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
|
54
|
import eu.etaxonomy.cdm.model.view.AuditEvent;
|
55
|
import eu.etaxonomy.cdm.model.view.AuditEventRecord;
|
56
|
import eu.etaxonomy.cdm.model.view.context.AuditEventContextHolder;
|
57
|
import eu.etaxonomy.cdm.persistence.dao.common.AuditEventSort;
|
58
|
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
|
59
|
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
|
60
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
|
61
|
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
|
62
|
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
|
63
|
import eu.etaxonomy.cdm.persistence.query.GroupByCount;
|
64
|
import eu.etaxonomy.cdm.persistence.query.GroupByDate;
|
65
|
import eu.etaxonomy.cdm.persistence.query.Grouping;
|
66
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
67
|
import eu.etaxonomy.cdm.persistence.query.NativeSqlOrderHint;
|
68
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
69
|
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
|
70
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
71
|
|
72
|
/**
|
73
|
* @author a.mueller
|
74
|
* @author ben.clark
|
75
|
*
|
76
|
*/
|
77
|
public class TaxonDaoHibernateImplTest extends CdmTransactionalIntegrationTest {
|
78
|
|
79
|
@SpringBeanByType
|
80
|
private ITaxonDao taxonDao;
|
81
|
|
82
|
@SpringBeanByType
|
83
|
private IClassificationDao classificationDao;
|
84
|
|
85
|
@SpringBeanByType
|
86
|
private IReferenceDao referenceDao;
|
87
|
|
88
|
@SpringBeanByType
|
89
|
IDefinedTermDao definedTermDao;
|
90
|
|
91
|
private UUID uuid;
|
92
|
private UUID sphingidae;
|
93
|
private UUID acherontia;
|
94
|
private UUID mimas;
|
95
|
private UUID rethera;
|
96
|
private UUID retheraSecCdmtest;
|
97
|
private UUID atroposAgassiz;
|
98
|
private UUID atroposLeach;
|
99
|
private UUID acherontiaLachesis;
|
100
|
private AuditEvent previousAuditEvent;
|
101
|
private AuditEvent mostRecentAuditEvent;
|
102
|
|
103
|
private UUID northernAmericaUuid;
|
104
|
private UUID southernAmericaUuid;
|
105
|
private UUID antarcticaUuid;
|
106
|
|
107
|
private UUID classificationUuid;
|
108
|
|
109
|
|
110
|
@Before
|
111
|
public void setUp() {
|
112
|
|
113
|
uuid = UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
|
114
|
sphingidae = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
|
115
|
acherontia = UUID.fromString("c5cc8674-4242-49a4-aada-72d63194f5fa");
|
116
|
acherontiaLachesis = UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06");
|
117
|
atroposAgassiz = UUID.fromString("d75b2e3d-7394-4ada-b6a5-93175b8751c1");
|
118
|
atroposLeach = UUID.fromString("3da4ab34-6c50-4586-801e-732615899b07");
|
119
|
rethera = UUID.fromString("a9f42927-e507-4fda-9629-62073a908aae");
|
120
|
retheraSecCdmtest = UUID.fromString("a9f42927-e507-433a-9629-62073a908aae");
|
121
|
|
122
|
|
123
|
mimas = UUID.fromString("900052b7-b69c-4e26-a8f0-01c215214c40");
|
124
|
previousAuditEvent = new AuditEvent();
|
125
|
previousAuditEvent.setRevisionNumber(1025);
|
126
|
previousAuditEvent.setUuid(UUID.fromString("a680fab4-365e-4765-b49e-768f2ee30cda"));
|
127
|
mostRecentAuditEvent = new AuditEvent();
|
128
|
mostRecentAuditEvent.setRevisionNumber(1026);
|
129
|
mostRecentAuditEvent.setUuid(UUID.fromString("afe8e761-8545-497b-9134-6a6791fc0b0d"));
|
130
|
AuditEventContextHolder.clearContext(); // By default we're in the current view (i.e. view == null)
|
131
|
|
132
|
northernAmericaUuid = UUID.fromString("2757e726-d897-4546-93bd-7951d203bf6f");
|
133
|
southernAmericaUuid = UUID.fromString("6310b3ba-96f4-4855-bb5b-326e7af188ea");
|
134
|
antarcticaUuid = UUID.fromString("791b3aa0-54dd-4bed-9b68-56b4680aad0c");
|
135
|
|
136
|
classificationUuid = UUID.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
|
137
|
}
|
138
|
|
139
|
@After
|
140
|
public void tearDown() {
|
141
|
AuditEventContextHolder.clearContext();
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#TaxonDaoHibernateImpl()}.
|
146
|
*/
|
147
|
@Test
|
148
|
@DataSet
|
149
|
public void testInit() {
|
150
|
logger.warn("testInit()");
|
151
|
assertNotNull("Instance of ITaxonDao expected",taxonDao);
|
152
|
assertNotNull("Instance of IReferenceDao expected",referenceDao);
|
153
|
}
|
154
|
|
155
|
/**
|
156
|
* Test method for
|
157
|
* {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getRootTaxa(eu.etaxonomy.cdm.model.reference.Reference)}
|
158
|
* .
|
159
|
*/
|
160
|
@Test
|
161
|
@DataSet
|
162
|
public void testGetRootTaxa() {
|
163
|
Reference sec1 = referenceDao.findById(1);
|
164
|
assert sec1 != null : "sec1 must exist";
|
165
|
Reference sec2 = referenceDao.findById(2);
|
166
|
assert sec2 != null : "sec2 must exist";
|
167
|
|
168
|
List<Taxon> rootTaxa = taxonDao.getRootTaxa(sec1);
|
169
|
assertNotNull("getRootTaxa should return a List", rootTaxa);
|
170
|
assertFalse("The list should not be empty", rootTaxa.isEmpty());
|
171
|
assertEquals("There should be one root taxon", 1, rootTaxa.size());
|
172
|
|
173
|
rootTaxa = taxonDao.getRootTaxa(sec1, CdmFetch.FETCH_CHILDTAXA(), true, false);
|
174
|
assertNotNull("getRootTaxa should return a List", rootTaxa);
|
175
|
assertFalse("The list should not be empty", rootTaxa.isEmpty());
|
176
|
assertEquals("There should be one root taxon", 1, rootTaxa.size());
|
177
|
|
178
|
rootTaxa = taxonDao.getRootTaxa(Rank.GENUS(), sec1, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
|
179
|
assertNotNull("getRootTaxa should return a List", rootTaxa);
|
180
|
assertFalse("The list should not be empty", rootTaxa.isEmpty());
|
181
|
assertEquals("There should be one root taxon", 1, rootTaxa.size());
|
182
|
|
183
|
rootTaxa = taxonDao.getRootTaxa(Rank.FAMILY(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
|
184
|
if (logger.isDebugEnabled()) {
|
185
|
logger.debug("Root taxa rank Family (" + rootTaxa.size() + "):");
|
186
|
for (Taxon taxon : rootTaxa) {
|
187
|
logger.debug(taxon.getTitleCache());
|
188
|
}
|
189
|
}
|
190
|
assertEquals("There should be one root taxon rank Family", 1, rootTaxa.size());
|
191
|
rootTaxa = taxonDao.getRootTaxa(Rank.GENUS(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
|
192
|
assertNotNull("getRootTaxa should return a List", rootTaxa);
|
193
|
assertFalse("The list should not be empty", rootTaxa.isEmpty());
|
194
|
if (logger.isDebugEnabled()) {
|
195
|
logger.debug("Root taxa rank Genus (" + rootTaxa.size() + "):");
|
196
|
for (Taxon taxon : rootTaxa) {
|
197
|
logger.debug(taxon.getTitleCache());
|
198
|
}
|
199
|
}
|
200
|
assertEquals("There should be 22 root taxa rank Genus", 22, rootTaxa.size());
|
201
|
|
202
|
rootTaxa = taxonDao.getRootTaxa(Rank.SPECIES(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
|
203
|
if (logger.isDebugEnabled()) {
|
204
|
logger.debug("Root taxa rank Species (" + rootTaxa.size() + "):");
|
205
|
for (Taxon taxon : rootTaxa) {
|
206
|
logger.debug(taxon.getTitleCache());
|
207
|
}
|
208
|
}
|
209
|
assertEquals("There should be 4 root taxa rank Species", 3, rootTaxa.size());
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}.
|
214
|
*/
|
215
|
@Test
|
216
|
@DataSet
|
217
|
public void testGetTaxaByName() {
|
218
|
Reference sec = referenceDao.findById(1);
|
219
|
assert sec != null : "sec must exist";
|
220
|
|
221
|
List<TaxonBase> results = taxonDao.getTaxaByName("Aus", sec);
|
222
|
assertNotNull("getTaxaByName should return a List", results);
|
223
|
//assertFalse("The list should not be empty", results.isEmpty());
|
224
|
assertTrue(results.size() == 1);
|
225
|
|
226
|
results = taxonDao.getTaxaByName("A*", MatchMode.BEGINNING,
|
227
|
true, null, null);
|
228
|
assertNotNull("getTaxaByName should return a List", results);
|
229
|
assertTrue(results.size() == 12);
|
230
|
|
231
|
|
232
|
//System.err.println("Species group: " + Rank.SPECIESGROUP().getId() + "Species: " + Rank.SPECIES().getId() + "Section Botany: "+ Rank.SECTION_BOTANY());
|
233
|
|
234
|
if (logger.isDebugEnabled()) {
|
235
|
for (int i = 0; i < results.size(); i++) {
|
236
|
String nameCache = "";
|
237
|
TaxonNameBase<?,?> taxonNameBase= ((TaxonBase)results.get(i)).getName();
|
238
|
nameCache = ((NonViralName)taxonNameBase).getNameCache();
|
239
|
logger.debug(results.get(i).getClass() + "(" + i +")" +
|
240
|
": Name Cache = " + nameCache + ", Title Cache = " + results.get(i).getTitleCache());
|
241
|
}
|
242
|
}
|
243
|
// assertEquals(results.get(0).getTitleCache(), "Abies sec. ???");
|
244
|
// assertEquals(results.get(1).getTitleCache(), "Abies Mill.");
|
245
|
// assertEquals(results.get(2).getTitleCache(), "Abies mill. sec. ???");
|
246
|
// assertEquals(results.get(3).getTitleCache(), "Abies alba sec. ???");
|
247
|
// assertEquals(results.get(4).getTitleCache(), "Abies alba Michx. sec. ???");
|
248
|
// assertEquals(results.get(5).getTitleCache(), "Abies alba Mill. sec. ???");
|
249
|
|
250
|
results = taxonDao.getTaxaByName("A", MatchMode.BEGINNING, true, null, null);
|
251
|
assertNotNull("getTaxaByName should return a List", results);
|
252
|
assertTrue(results.size() == 12);
|
253
|
|
254
|
results = taxonDao.getTaxaByName("Aus", MatchMode.EXACT, true, null, null);
|
255
|
assertNotNull("getTaxaByName should return a List", results);
|
256
|
assertEquals("Results list should contain one entity",1,results.size());
|
257
|
}
|
258
|
|
259
|
/**
|
260
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}.
|
261
|
*/
|
262
|
@Test
|
263
|
@DataSet
|
264
|
public void testGetTaxaByNameForEditor() {
|
265
|
Reference sec = referenceDao.findById(1);
|
266
|
assert sec != null : "sec must exist";
|
267
|
|
268
|
List<UuidAndTitleCache<TaxonBase>> results = taxonDao.getTaxaByNameForEditor(TaxonBase.class, "Mand*", null, MatchMode.BEGINNING, null);
|
269
|
assertNotNull("getTaxaByName should return a List", results);
|
270
|
//assertFalse("The list should not be empty", results.isEmpty());
|
271
|
assertTrue(results.size() == 5);
|
272
|
|
273
|
|
274
|
results = taxonDao.getTaxaByNameForEditor(TaxonBase.class,"A*",null, MatchMode.BEGINNING, null);
|
275
|
assertNotNull("getTaxaByName should return a List", results);
|
276
|
assertTrue(results.size() == 15);
|
277
|
|
278
|
|
279
|
results = taxonDao.getTaxaByNameForEditor(Taxon.class,"A", null,MatchMode.BEGINNING, null);
|
280
|
assertNotNull("getTaxaByName should return a List", results);
|
281
|
assertTrue(results.size() == 12);
|
282
|
assertEquals(results.get(0).getType(), Taxon.class);
|
283
|
|
284
|
results = taxonDao.getTaxaByNameForEditor(Synonym.class,"A", null,MatchMode.BEGINNING, null);
|
285
|
assertNotNull("getTaxaByName should return a List", results);
|
286
|
assertTrue(results.size() == 3);
|
287
|
assertEquals(results.get(0).getType(), Synonym.class);
|
288
|
|
289
|
results = taxonDao.getTaxaByNameForEditor(TaxonBase.class,"Aus", null,MatchMode.EXACT, null);
|
290
|
assertNotNull("getTaxaByName should return a List", results);
|
291
|
assertEquals("Results list should contain one entity",1,results.size());
|
292
|
}
|
293
|
|
294
|
|
295
|
/**
|
296
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}
|
297
|
* restricting the search by a set of Areas.
|
298
|
*/
|
299
|
@SuppressWarnings("unchecked")
|
300
|
@Test
|
301
|
@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
|
302
|
public void testGetTaxaByNameAndArea() {
|
303
|
|
304
|
Set<NamedArea> namedAreas = new HashSet<NamedArea>();
|
305
|
namedAreas.add((NamedArea)definedTermDao.load(northernAmericaUuid));
|
306
|
//namedAreas.add((NamedArea)definedTermDao.load(southernAmericaUuid));
|
307
|
//namedAreas.add((NamedArea)definedTermDao.load(antarcticaUuid));
|
308
|
|
309
|
Classification taxonmicTree = classificationDao.findByUuid(classificationUuid);
|
310
|
|
311
|
// prepare some synonym relation ships for some tests
|
312
|
Synonym synAtroposAgassiz = (Synonym)taxonDao.findByUuid(atroposAgassiz);
|
313
|
Taxon taxonRethera = (Taxon)taxonDao.findByUuid(rethera);
|
314
|
taxonRethera.addSynonym(synAtroposAgassiz, SynonymRelationshipType.SYNONYM_OF());
|
315
|
logger.warn("addSynonym(..)");
|
316
|
this.taxonDao.clear();
|
317
|
Synonym synAtroposLeach = (Synonym)taxonDao.findByUuid(atroposLeach);
|
318
|
Taxon taxonRetheraSecCdmtest = (Taxon)taxonDao.findByUuid(retheraSecCdmtest);
|
319
|
taxonRetheraSecCdmtest.addSynonym(synAtroposLeach, SynonymRelationshipType.SYNONYM_OF());
|
320
|
this.taxonDao.clear();
|
321
|
// 1. searching for a taxon (Rethera)
|
322
|
//long numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "Rethera", null, MatchMode.BEGINNING, namedAreas);
|
323
|
|
324
|
List<TaxonBase> results = taxonDao.getTaxaByName(Taxon.class, "Rethera", null, MatchMode.BEGINNING, namedAreas,
|
325
|
null, null, null);
|
326
|
assertNotNull("getTaxaByName should return a List", results);
|
327
|
assertTrue("expected to find two taxa but found "+results.size(), results.size() == 2);
|
328
|
|
329
|
// 2. searching for a taxon (Rethera) contained in a specific classification
|
330
|
results = taxonDao.getTaxaByName(Taxon.class, "Rethera", taxonmicTree, MatchMode.BEGINNING, namedAreas,
|
331
|
null, null, null);
|
332
|
assertNotNull("getTaxaByName should return a List", results);
|
333
|
assertTrue("expected to find one taxon but found "+results.size(), results.size() == 1);
|
334
|
|
335
|
|
336
|
// 3. searching for Synonyms
|
337
|
results = taxonDao.getTaxaByName(Synonym.class, "Atropo", null, MatchMode.ANYWHERE, null,
|
338
|
null, null, null);
|
339
|
assertNotNull("getTaxaByName should return a List", results);
|
340
|
|
341
|
assertTrue("expected to find two taxa but found "+results.size(), results.size() == 3);
|
342
|
|
343
|
// 4. searching for Synonyms
|
344
|
results = taxonDao.getTaxaByName(Synonym.class, "Atropo", null, MatchMode.BEGINNING, null,
|
345
|
null, null, null);
|
346
|
assertNotNull("getTaxaByName should return a List", results);
|
347
|
assertTrue("expected to find two taxa but found "+results.size(), results.size() == 3);
|
348
|
|
349
|
|
350
|
// 5. searching for a Synonyms and Taxa
|
351
|
// create a synonym relationship first
|
352
|
results = taxonDao.getTaxaByName(TaxonBase.class, "A", null, MatchMode.BEGINNING, namedAreas,
|
353
|
null, null, null);
|
354
|
assertNotNull("getTaxaByName should return a List", results);
|
355
|
assertTrue("expected to find 8 taxa but found "+results.size(), results.size() == 8);
|
356
|
}
|
357
|
|
358
|
|
359
|
/**
|
360
|
* 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)}
|
361
|
* restricting the search by a set of Areas.
|
362
|
*/
|
363
|
@SuppressWarnings("unchecked")
|
364
|
@Test
|
365
|
@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
|
366
|
public void testFindByNameTitleCache() {
|
367
|
|
368
|
Set<NamedArea> namedAreas = new HashSet<NamedArea>();
|
369
|
namedAreas.add((NamedArea)definedTermDao.load(northernAmericaUuid));
|
370
|
//namedAreas.add((NamedArea)definedTermDao.load(southernAmericaUuid));
|
371
|
//namedAreas.add((NamedArea)definedTermDao.load(antarcticaUuid));
|
372
|
|
373
|
Classification classification = classificationDao.findByUuid(classificationUuid);
|
374
|
|
375
|
// prepare some synonym relation ships for some tests
|
376
|
Synonym synAtroposAgassiz = (Synonym)taxonDao.findByUuid(atroposAgassiz);
|
377
|
Taxon taxonRethera = (Taxon)taxonDao.findByUuid(rethera);
|
378
|
taxonRethera.addSynonym(synAtroposAgassiz, SynonymRelationshipType.SYNONYM_OF());
|
379
|
logger.warn("addSynonym(..)");
|
380
|
this.taxonDao.clear();
|
381
|
Synonym synAtroposLeach = (Synonym)taxonDao.findByUuid(atroposLeach);
|
382
|
Taxon taxonRetheraSecCdmtest = (Taxon)taxonDao.findByUuid(retheraSecCdmtest);
|
383
|
taxonRetheraSecCdmtest.addSynonym(synAtroposLeach, SynonymRelationshipType.SYNONYM_OF());
|
384
|
this.taxonDao.clear();
|
385
|
// 1. searching for a taxon (Rethera)
|
386
|
//long numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "Rethera", null, MatchMode.BEGINNING, namedAreas);
|
387
|
|
388
|
List<TaxonBase> results = taxonDao.findByNameTitleCache(Taxon.class, "Rethera Rothschild & Jordan, 1903", null, MatchMode.EXACT, namedAreas,
|
389
|
null, null, null);
|
390
|
assertNotNull("getTaxaByName should return a List", results);
|
391
|
assertTrue("expected to find two taxa but found "+results.size(), results.size() == 2);
|
392
|
|
393
|
// 2. searching for a taxon (Rethera) contained in a specific classification
|
394
|
results = taxonDao.findByNameTitleCache(Taxon.class, "Rethera Rothschild & Jordan, 1903", classification, MatchMode.EXACT, namedAreas,
|
395
|
null, null, null);
|
396
|
assertNotNull("getTaxaByName should return a List", results);
|
397
|
assertTrue("expected to find one taxon but found "+results.size(), results.size() == 1);
|
398
|
|
399
|
|
400
|
// 3. searching for Synonyms
|
401
|
results = taxonDao.findByNameTitleCache(Synonym.class, "Atropo", null, MatchMode.ANYWHERE, null,
|
402
|
null, null, null);
|
403
|
assertNotNull("getTaxaByName should return a List", results);
|
404
|
|
405
|
assertTrue("expected to find two taxa but found "+results.size(), results.size() == 3);
|
406
|
|
407
|
// 4. searching for Synonyms
|
408
|
results = taxonDao.findByNameTitleCache(Synonym.class, "Atropo", null, MatchMode.BEGINNING, null,
|
409
|
null, null, null);
|
410
|
assertNotNull("getTaxaByName should return a List", results);
|
411
|
assertTrue("expected to find two taxa but found "+results.size(), results.size() == 3);
|
412
|
|
413
|
|
414
|
// 5. searching for a Synonyms and Taxa
|
415
|
// create a synonym relationship first
|
416
|
results = taxonDao.findByNameTitleCache(TaxonBase.class, "A", null, MatchMode.BEGINNING, namedAreas,
|
417
|
null, null, null);
|
418
|
assertNotNull("getTaxaByName should return a List", results);
|
419
|
assertTrue("expected to find 8 taxa but found "+results.size(), results.size() == 8);
|
420
|
}
|
421
|
|
422
|
@Test
|
423
|
@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
|
424
|
public void testTaxonNameInTwoClassifications(){
|
425
|
int numberOfClassifications = classificationDao.count();
|
426
|
List<String> propertyPaths = new ArrayList<String>();
|
427
|
propertyPaths.add("taxonNodes");
|
428
|
List<TaxonBase> taxa = taxonDao.getTaxaByName(TaxonBase.class, "P*", null, MatchMode.BEGINNING, null, null, null, null);
|
429
|
Taxon taxon = (Taxon)taxa.get(0);
|
430
|
Set<TaxonNode> nodes = taxon.getTaxonNodes();
|
431
|
assertTrue(nodes.size() == 1);
|
432
|
//assertNotNull(taxa);
|
433
|
//assertTrue(taxa.size() > 0);
|
434
|
}
|
435
|
|
436
|
|
437
|
@Test
|
438
|
@DataSet
|
439
|
public void testFindByUuid() {
|
440
|
Taxon taxon = (Taxon)taxonDao.findByUuid(uuid);
|
441
|
assertNotNull("findByUuid should return a taxon",taxon);
|
442
|
assertFalse("findByUuid should not return a taxon with it's name initialized",Hibernate.isInitialized(taxon.getName()));
|
443
|
}
|
444
|
|
445
|
@Test
|
446
|
@DataSet
|
447
|
public void testLoad() {
|
448
|
List<String> propertyPaths = new ArrayList<String>();
|
449
|
propertyPaths.add("name");
|
450
|
propertyPaths.add("sec");
|
451
|
Taxon taxon = (Taxon)taxonDao.load(uuid, propertyPaths);
|
452
|
assertNotNull("findByUuid should return a taxon",taxon);
|
453
|
assertTrue("load should return a taxon with it's name initialized, given that the property was specified in the method",Hibernate.isInitialized(taxon.getName()));
|
454
|
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()));
|
455
|
}
|
456
|
|
457
|
@Test
|
458
|
@DataSet
|
459
|
public void testCountTaxonRelationships() {
|
460
|
Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
|
461
|
assert taxon != null : "taxon must exist";
|
462
|
|
463
|
int numberOfRelatedTaxa = taxonDao.countTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), TaxonRelationship.Direction.relatedTo);
|
464
|
assertEquals("countTaxonRelationships should return 23", 23, numberOfRelatedTaxa);
|
465
|
}
|
466
|
|
467
|
@Test
|
468
|
@DataSet
|
469
|
public void testCountTaxaByName() {
|
470
|
long numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "A*", null, MatchMode.BEGINNING, null);
|
471
|
assertEquals(numberOfTaxa, 12);
|
472
|
numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "A*", null, MatchMode.BEGINNING, null);
|
473
|
assertEquals(numberOfTaxa, 12);
|
474
|
numberOfTaxa = taxonDao.countTaxaByName(Synonym.class, "A*", null, MatchMode.BEGINNING, null);
|
475
|
assertEquals(numberOfTaxa, 3);
|
476
|
numberOfTaxa = taxonDao.countTaxaByName(TaxonBase.class, "A*", null, MatchMode.BEGINNING, null);
|
477
|
assertEquals(numberOfTaxa, 15);
|
478
|
numberOfTaxa = taxonDao.countTaxaByName(TaxonBase.class, "Aasfwerfwf fffe", null, MatchMode.BEGINNING, null);
|
479
|
assertEquals(numberOfTaxa, 0);
|
480
|
// FIXME implement test for search in specific classification
|
481
|
// Reference reference = referenceDao.findByUuid(UUID.fromString("596b1325-be50-4b0a-9aa2-3ecd610215f2"));
|
482
|
// numberOfTaxa = taxonDao.countTaxaByName("A*", MatchMode.BEGINNING, SelectMode.ALL, null, null);
|
483
|
// assertEquals(numberOfTaxa, 2);
|
484
|
}
|
485
|
|
486
|
@Test
|
487
|
@DataSet
|
488
|
public void testRelatedTaxa() {
|
489
|
Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
|
490
|
assert taxon != null : "taxon must exist";
|
491
|
|
492
|
List<String> propertyPaths = new ArrayList<String>();
|
493
|
propertyPaths.add("fromTaxon");
|
494
|
propertyPaths.add("fromTaxon.name");
|
495
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
496
|
orderHints.add(new OrderHint("relatedFrom.name.genusOrUninomial", SortOrder.ASCENDING));
|
497
|
orderHints.add(new OrderHint("relatedFrom.name.specificEpithet", SortOrder.ASCENDING));
|
498
|
orderHints.add(new OrderHint("relatedFrom.name.infraSpecificEpithet", SortOrder.ASCENDING));
|
499
|
|
500
|
List<TaxonRelationship> relatedTaxa = taxonDao.getTaxonRelationships(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null, orderHints,propertyPaths, TaxonRelationship.Direction.relatedTo);
|
501
|
assertNotNull("getRelatedTaxa should return a List",relatedTaxa);
|
502
|
assertEquals("getRelatedTaxa should return all 23 related taxa",relatedTaxa.size(),23);
|
503
|
assertTrue("getRelatedTaxa should return TaxonRelationship objects with the relatedFrom taxon initialized",Hibernate.isInitialized(relatedTaxa.get(0).getFromTaxon()));
|
504
|
assertTrue("getRelatedTaxa should return TaxonRelationship objects with the relatedFrom taxon initialized",Hibernate.isInitialized(relatedTaxa.get(0).getFromTaxon().getName()));
|
505
|
|
506
|
assertEquals("Acherontia should appear first in the list of related taxa", relatedTaxa.get(0).getFromTaxon().getTitleCache(), "Acherontia Laspeyres, 1809 sec. cate-sphingidae.org");
|
507
|
assertEquals("Sphingonaepiopsis should appear last in the list of related taxa", relatedTaxa.get(22).getFromTaxon().getTitleCache(), "Sphinx Linnaeus, 1758 sec. cate-sphingidae.org");
|
508
|
}
|
509
|
|
510
|
@Test
|
511
|
@DataSet
|
512
|
public void testGetRelatedTaxaPaged() {
|
513
|
Taxon taxon = (Taxon)taxonDao.findByUuid(sphingidae);
|
514
|
assert taxon != null : "taxon must exist";
|
515
|
|
516
|
List<String> propertyPaths = new ArrayList<String>();
|
517
|
propertyPaths.add("fromTaxon");
|
518
|
propertyPaths.add("fromTaxon.name");
|
519
|
|
520
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
521
|
orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));
|
522
|
|
523
|
List<TaxonRelationship> firstPage = taxonDao.getTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), 10, 0, orderHints,propertyPaths, TaxonRelationship.Direction.relatedTo);
|
524
|
List<TaxonRelationship> secondPage = taxonDao.getTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),10, 1, orderHints,propertyPaths, TaxonRelationship.Direction.relatedTo);
|
525
|
List<TaxonRelationship> thirdPage = taxonDao.getTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), 10, 2, orderHints,propertyPaths, TaxonRelationship.Direction.relatedTo);
|
526
|
|
527
|
assertNotNull("getRelatedTaxa: 10, 0 should return a List",firstPage);
|
528
|
assertEquals("getRelatedTaxa: 10, 0 should return a List with 10 elements",10,firstPage.size());
|
529
|
assertNotNull("getRelatedTaxa: 10, 1 should return a List",secondPage);
|
530
|
assertEquals("getRelatedTaxa: 10, 1 should return a List with 10 elements",secondPage.size(),10);
|
531
|
assertNotNull("getRelatedTaxa: 10, 2 should return a List",thirdPage);
|
532
|
assertEquals("getRelatedTaxa: 10, 2 should return a List with 3 elements",thirdPage.size(),3);
|
533
|
}
|
534
|
|
535
|
@Test
|
536
|
@DataSet
|
537
|
public void testCountSynonymRelationships() {
|
538
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
|
539
|
assert taxon != null : "taxon must exist";
|
540
|
|
541
|
int numberOfSynonymRelationships = taxonDao.countSynonyms(taxon,null);
|
542
|
assertEquals("countSynonymRelationships should return 5",5,numberOfSynonymRelationships);
|
543
|
}
|
544
|
|
545
|
@Test
|
546
|
@DataSet
|
547
|
public void testSynonymRelationships() {
|
548
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
|
549
|
assert taxon != null : "taxon must exist";
|
550
|
List<String> propertyPaths = new ArrayList<String>();
|
551
|
propertyPaths.add("synonym");
|
552
|
propertyPaths.add("synonym.name");
|
553
|
|
554
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
555
|
orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));
|
556
|
|
557
|
List<SynonymRelationship> synonyms = taxonDao.getSynonyms(taxon, null, null, null,orderHints,propertyPaths);
|
558
|
|
559
|
assertNotNull("getSynonyms should return a List",synonyms);
|
560
|
assertEquals("getSynonyms should return 5 SynonymRelationship entities",synonyms.size(),5);
|
561
|
assertTrue("getSynonyms should return SynonymRelationship objects with the synonym initialized",Hibernate.isInitialized(synonyms.get(0).getSynonym()));
|
562
|
}
|
563
|
|
564
|
@Test
|
565
|
@DataSet
|
566
|
public void testCountSynonymRelationshipsByType() {
|
567
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
|
568
|
assert taxon != null : "taxon must exist";
|
569
|
|
570
|
int numberOfTaxonomicSynonyms = taxonDao.countSynonyms(taxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
571
|
assertEquals("countSynonyms should return 4",numberOfTaxonomicSynonyms, 4);
|
572
|
}
|
573
|
|
574
|
@Test
|
575
|
@DataSet
|
576
|
public void testSynonymRelationshipsByType() {
|
577
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
|
578
|
assert taxon != null : "taxon must exist";
|
579
|
|
580
|
List<SynonymRelationship> synonyms = taxonDao.getSynonyms(taxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null,null,null);
|
581
|
|
582
|
assertNotNull("getSynonyms should return a List",synonyms);
|
583
|
assertEquals("getSynonyms should return 4 SynonymRelationship entities",synonyms.size(),4);
|
584
|
}
|
585
|
|
586
|
@Test
|
587
|
@DataSet
|
588
|
public void testPageSynonymRelationships(){
|
589
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
|
590
|
assert taxon != null : "taxon must exist";
|
591
|
|
592
|
List<SynonymRelationship> firstPage = taxonDao.getSynonyms(taxon, null, 4, 0,null,null);
|
593
|
List<SynonymRelationship> secondPage = taxonDao.getSynonyms(taxon, null, 4, 1,null,null);
|
594
|
|
595
|
assertNotNull("getSynonyms: 4, 0 should return a List",firstPage);
|
596
|
assertEquals("getSynonyms: 4, 0 should return 4 SynonymRelationships", firstPage.size(),4);
|
597
|
assertNotNull("getSynonyms: 4, 1 should return a List",secondPage);
|
598
|
assertEquals("getSynonyms: 4, 1 should return 1 SynonymRelationship",secondPage.size(),1);
|
599
|
}
|
600
|
|
601
|
@Test
|
602
|
@DataSet
|
603
|
public void testGetTaxonMatchingUninomial() {
|
604
|
List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class, "Smerinthus", "*", "*", "*",null,null,null);
|
605
|
|
606
|
assertNotNull("findTaxaByName should return a List", result);
|
607
|
assertEquals("findTaxaByName should return two Taxa",2,result.size());
|
608
|
assertEquals("findTaxaByName should return a Taxon with id 5",5,result.get(0).getId());
|
609
|
}
|
610
|
|
611
|
@Test
|
612
|
@DataSet
|
613
|
public void testGetTaxonMatchingSpeciesBinomial() {
|
614
|
List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Smerinthus", null, "kindermannii", null,null,null,null);
|
615
|
|
616
|
assertNotNull("findTaxaByName should return a List", result);
|
617
|
assertEquals("findTaxaByName should return one Taxon",1,result.size());
|
618
|
assertEquals("findTaxaByName should return a Taxon with id 8",8,result.get(0).getId());
|
619
|
}
|
620
|
|
621
|
@Test
|
622
|
@DataSet
|
623
|
public void testGetTaxonMatchingTrinomial() {
|
624
|
List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Cryptocoryne", null,"purpurea","borneoensis",null,null,null);
|
625
|
|
626
|
assertNotNull("findTaxaByName should return a List", result);
|
627
|
assertEquals("findTaxaByName should return one Taxon",1,result.size());
|
628
|
assertEquals("findTaxaByName should return a Taxon with id 38",38,result.get(0).getId());
|
629
|
}
|
630
|
|
631
|
@Test
|
632
|
@DataSet
|
633
|
public void testNegativeMatch() {
|
634
|
List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Acherontia", null,"atropos","dehli",null,null,null);
|
635
|
|
636
|
assertNotNull("findTaxaByName should return a List", result);
|
637
|
assertTrue("findTaxaByName should return an empty List",result.isEmpty());
|
638
|
}
|
639
|
|
640
|
@Test
|
641
|
@DataSet
|
642
|
public void testCountAllTaxa() {
|
643
|
int numberOfTaxa = taxonDao.count(Taxon.class);
|
644
|
assertEquals("count should return 36 taxa",36, numberOfTaxa);
|
645
|
}
|
646
|
|
647
|
@Test
|
648
|
@DataSet
|
649
|
public void testListAllTaxa() {
|
650
|
List<TaxonBase> taxa = taxonDao.list(Taxon.class,100, 0);
|
651
|
assertNotNull("list should return a List",taxa);
|
652
|
assertEquals("list should return 36 taxa",36, taxa.size());
|
653
|
}
|
654
|
|
655
|
@Test
|
656
|
@DataSet
|
657
|
@ExpectedDataSet
|
658
|
public void testDelete() {
|
659
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
|
660
|
assert taxon != null : "taxon must exist";
|
661
|
taxonDao.delete(taxon);
|
662
|
setComplete();
|
663
|
endTransaction();
|
664
|
try {printDataSet(new FileOutputStream("test.xml"));} catch(Exception e) { }
|
665
|
}
|
666
|
|
667
|
@Test
|
668
|
@DataSet
|
669
|
public void testDeleteWithChildren() {
|
670
|
Taxon taxonWithChildren = (Taxon)taxonDao.findByUuid(mimas);
|
671
|
assert taxonWithChildren != null : "taxon must exist";
|
672
|
assertEquals(taxonWithChildren.getTaxonomicChildrenCount(), 2);
|
673
|
Taxon parent = (Taxon)taxonDao.findByUuid(sphingidae);
|
674
|
assertSame(taxonWithChildren.getTaxonomicParent(), parent);
|
675
|
assertEquals(parent.getTaxonomicChildrenCount(), 204);
|
676
|
taxonDao.delete(taxonWithChildren);
|
677
|
assertEquals(parent.getTaxonomicChildrenCount(), 203);
|
678
|
}
|
679
|
|
680
|
@Test
|
681
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
682
|
public void testFindDeleted() {
|
683
|
TaxonBase taxon = taxonDao.findByUuid(acherontia);
|
684
|
assertNull("findByUuid should return null in this view", taxon);
|
685
|
assertFalse("exist should return false in this view",taxonDao.exists(acherontia));
|
686
|
}
|
687
|
|
688
|
@Test
|
689
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
690
|
public void testFindDeletedInPreviousView() {
|
691
|
AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
|
692
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontia);
|
693
|
assertNotNull("findByUuid should return a taxon in this view",taxon);
|
694
|
assertTrue("exists should return true in this view", taxonDao.exists(acherontia));
|
695
|
|
696
|
try{
|
697
|
assertEquals("There should be 3 relations to this taxon in this view",3,taxon.getRelationsToThisTaxon().size());
|
698
|
} catch(Exception e) {
|
699
|
fail("We should not experience any problems initializing proxies with envers");
|
700
|
}
|
701
|
}
|
702
|
|
703
|
@Test
|
704
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
705
|
public void testGetAuditEvents() {
|
706
|
TaxonBase taxon = taxonDao.findByUuid(sphingidae);
|
707
|
assert taxon != null : "taxon cannot be null";
|
708
|
|
709
|
List<String> propertyPaths = new ArrayList<String>();
|
710
|
propertyPaths.add("name");
|
711
|
propertyPaths.add("createdBy");
|
712
|
propertyPaths.add("updatedBy");
|
713
|
|
714
|
List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(taxon, null,null,null,propertyPaths);
|
715
|
assertNotNull("getAuditEvents should return a list",auditEvents);
|
716
|
assertFalse("the list should not be empty",auditEvents.isEmpty());
|
717
|
assertEquals("There should be two AuditEventRecords in the list",2, auditEvents.size());
|
718
|
}
|
719
|
|
720
|
@Test
|
721
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
722
|
public void testGetAuditEventsFromNow() {
|
723
|
AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
|
724
|
TaxonBase taxon = taxonDao.findByUuid(sphingidae);
|
725
|
assert taxon != null : "taxon cannot be null";
|
726
|
|
727
|
List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(taxon, null,null,AuditEventSort.FORWARDS,null);
|
728
|
assertNotNull("getAuditEvents should return a list",auditEvents);
|
729
|
assertFalse("the list should not be empty",auditEvents.isEmpty());
|
730
|
assertEquals("There should be one audit event in the list",1,auditEvents.size());
|
731
|
}
|
732
|
|
733
|
@Test
|
734
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
735
|
public void testCountAuditEvents() {
|
736
|
TaxonBase taxon = taxonDao.findByUuid(sphingidae);
|
737
|
assert taxon != null : "taxon cannot be null";
|
738
|
|
739
|
int numberOfAuditEvents = taxonDao.countAuditEvents(taxon,null);
|
740
|
assertEquals("countAuditEvents should return 2",numberOfAuditEvents,2);
|
741
|
}
|
742
|
|
743
|
@Test
|
744
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
745
|
public void getPreviousAuditEvent() {
|
746
|
TaxonBase taxon = taxonDao.findByUuid(sphingidae);
|
747
|
assert taxon != null : "taxon cannot be null";
|
748
|
|
749
|
AuditEventRecord<TaxonBase> auditEvent = taxonDao.getPreviousAuditEvent(taxon);
|
750
|
assertNotNull("getPreviousAuditEvent should not return null as there is at least one audit event prior to the current one",auditEvent);
|
751
|
}
|
752
|
|
753
|
@Test
|
754
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
755
|
public void getPreviousAuditEventAtBeginning() {
|
756
|
AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
|
757
|
TaxonBase taxon = taxonDao.findByUuid(sphingidae);
|
758
|
assert taxon != null : "taxon cannot be null";
|
759
|
|
760
|
AuditEventRecord<TaxonBase> auditEvent = taxonDao.getPreviousAuditEvent(taxon);
|
761
|
assertNull("getPreviousAuditEvent should return null if we're at the first audit event anyway",auditEvent);
|
762
|
}
|
763
|
|
764
|
@Test
|
765
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
766
|
public void getNextAuditEvent() {
|
767
|
AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
|
768
|
TaxonBase taxon = taxonDao.findByUuid(sphingidae);
|
769
|
assert taxon != null : "taxon cannot be null";
|
770
|
|
771
|
AuditEventRecord<TaxonBase> auditEvent = taxonDao.getNextAuditEvent(taxon);
|
772
|
assertNotNull("getNextAuditEvent should not return null as there is at least one audit event after the current one",auditEvent);
|
773
|
}
|
774
|
|
775
|
@Test
|
776
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
777
|
public void getNextAuditEventAtEnd() {
|
778
|
AuditEventContextHolder.getContext().setAuditEvent(mostRecentAuditEvent);
|
779
|
TaxonBase taxon = taxonDao.findByUuid(sphingidae);
|
780
|
assert taxon != null : "taxon cannot be null";
|
781
|
|
782
|
AuditEventRecord<TaxonBase> auditEvent = taxonDao.getNextAuditEvent(taxon);
|
783
|
assertNull("getNextAuditEvent should return null as there no more audit events after the current one",auditEvent);
|
784
|
}
|
785
|
|
786
|
@Test
|
787
|
@DataSet
|
788
|
@ExpectedDataSet
|
789
|
@Ignore
|
790
|
public void testAddChild() throws Exception {
|
791
|
Taxon parent = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
|
792
|
assert parent != null : "taxon cannot be null";
|
793
|
Taxon child = Taxon.NewInstance(null, null);
|
794
|
child.setTitleCache("Acherontia lachesis diehli Eitschberger, 2003", true);
|
795
|
child.addTaxonRelation(parent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),null, null);
|
796
|
taxonDao.save(child);
|
797
|
setComplete();
|
798
|
endTransaction();
|
799
|
}
|
800
|
|
801
|
@Test
|
802
|
@DataSet("TaxonDaoHibernateImplTest.testFind.xml")
|
803
|
public void testFind() {
|
804
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
|
805
|
assert taxon != null : "taxon cannot be null";
|
806
|
|
807
|
assertEquals("getTaxonomicChildrenCount should return 1 in this view",1,taxon.getTaxonomicChildrenCount());
|
808
|
assertEquals("getRelationsToThisTaxon should contain 1 TaxonRelationship in this view",1,taxon.getRelationsToThisTaxon().size());
|
809
|
}
|
810
|
|
811
|
@Test
|
812
|
@DataSet("TaxonDaoHibernateImplTest.testFind.xml")
|
813
|
public void testFindInPreviousView() {
|
814
|
AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
|
815
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
|
816
|
assert taxon != null : "taxon cannot be null";
|
817
|
|
818
|
assertEquals("getTaxonomicChildrenCount should return 0 in this view",0,taxon.getTaxonomicChildrenCount());
|
819
|
assertTrue("getRelationsToThisTaxon should contain 0 TaxonRelationship in this view",taxon.getRelationsToThisTaxon().isEmpty());
|
820
|
}
|
821
|
|
822
|
@Test
|
823
|
@DataSet("TaxonDaoHibernateImplTest.testFind.xml")
|
824
|
public void testGetRelations() {
|
825
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
|
826
|
assert taxon != null : "taxon cannot be null";
|
827
|
|
828
|
List<String> propertyPaths = new ArrayList<String>();
|
829
|
propertyPaths.add("fromTaxon");
|
830
|
propertyPaths.add("fromTaxon.name");
|
831
|
|
832
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
833
|
orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));
|
834
|
|
835
|
List<TaxonRelationship> taxonRelations = taxonDao.getTaxonRelationships(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null,orderHints,propertyPaths, TaxonRelationship.Direction.relatedFrom);
|
836
|
assertNotNull("getRelatedTaxa should return a list", taxonRelations);
|
837
|
assertEquals("there should be one TaxonRelationship in the list in the current view",1,taxonRelations.size());
|
838
|
assertTrue("TaxonRelationship.relatedFrom should be initialized",Hibernate.isInitialized(taxonRelations.get(0).getFromTaxon()));
|
839
|
assertTrue("TaxonRelationship.relatedFrom.name should be initialized",Hibernate.isInitialized(taxonRelations.get(0).getFromTaxon().getName()));
|
840
|
}
|
841
|
|
842
|
@Test
|
843
|
@DataSet("TaxonDaoHibernateImplTest.testFind.xml")
|
844
|
public void testCountRelations() {
|
845
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
|
846
|
assert taxon != null : "taxon cannot be null";
|
847
|
assertEquals("countRelatedTaxa should return 1 in the current view",1, taxonDao.countTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), TaxonRelationship.Direction.relatedTo));
|
848
|
}
|
849
|
|
850
|
@Test
|
851
|
@DataSet("TaxonDaoHibernateImplTest.testFind.xml")
|
852
|
public void testGetRelationsInPreviousView() {
|
853
|
AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
|
854
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
|
855
|
assert taxon != null : "taxon cannot be null";
|
856
|
|
857
|
List<String> propertyPaths = new ArrayList<String>();
|
858
|
propertyPaths.add("relatedFrom");
|
859
|
propertyPaths.add("relatedFrom.name");
|
860
|
|
861
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
862
|
orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));
|
863
|
|
864
|
List<TaxonRelationship> taxonRelations = taxonDao.getTaxonRelationships(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null,orderHints,propertyPaths, TaxonRelationship.Direction.relatedFrom);
|
865
|
assertNotNull("getRelatedTaxa should return a list",taxonRelations);
|
866
|
assertTrue("there should be no TaxonRelationships in the list in the prior view",taxonRelations.isEmpty());
|
867
|
}
|
868
|
|
869
|
@Test
|
870
|
@DataSet("TaxonDaoHibernateImplTest.testFind.xml")
|
871
|
public void testCountRelationsInPreviousView() {
|
872
|
AuditEventContextHolder.getContext().setAuditEvent(previousAuditEvent);
|
873
|
Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
|
874
|
assert taxon != null : "taxon cannot be null";
|
875
|
assertEquals("countRelatedTaxa should return 0 in the current view",0, taxonDao.countTaxonRelationships(taxon,TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), TaxonRelationship.Direction.relatedTo));
|
876
|
}
|
877
|
|
878
|
@Test
|
879
|
@DataSet
|
880
|
public void testGroupTaxa() {
|
881
|
List<Grouping> groups = new ArrayList<Grouping>();
|
882
|
groups.add(new GroupByCount("count",SortOrder.DESCENDING));
|
883
|
groups.add(new Grouping("name.genusOrUninomial", "genus", "n", SortOrder.ASCENDING));
|
884
|
List<Object[]> results = taxonDao.group(null, null, null, groups,null);
|
885
|
System.out.println("count\tname.genuOrUninomial");
|
886
|
for(Object[] result : results) {
|
887
|
System.out.println(result[0] + "\t" + result[1]);
|
888
|
}
|
889
|
}
|
890
|
|
891
|
@Test
|
892
|
@DataSet
|
893
|
public void testGroupTaxaByClass() {
|
894
|
List<Grouping> groups = new ArrayList<Grouping>();
|
895
|
groups.add(new GroupByCount("count",SortOrder.DESCENDING));
|
896
|
groups.add(new Grouping("class", "class",null, SortOrder.ASCENDING));
|
897
|
List<Object[]> results = taxonDao.group(null, null, null, groups,null);
|
898
|
System.out.println("count\tclass");
|
899
|
for(Object[] result : results) {
|
900
|
System.out.println(result[0] + "\t" + result[1]);
|
901
|
}
|
902
|
}
|
903
|
|
904
|
@Test
|
905
|
@DataSet
|
906
|
public void testNativeSQLOrder() {
|
907
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
908
|
orderHints.add(new NativeSqlOrderHint("case when {alias}.titleCache like 'C%' then 0 else 1 end",SortOrder.ASCENDING));
|
909
|
|
910
|
List<TaxonBase> results = taxonDao.list(null, null, orderHints);
|
911
|
System.out.println("native SQL order");
|
912
|
for(TaxonBase result : results) {
|
913
|
System.out.println(result.getTitleCache());
|
914
|
}
|
915
|
}
|
916
|
|
917
|
@Test
|
918
|
@DataSet
|
919
|
public void testGroupByDateTaxa() {
|
920
|
List<Grouping> groups = new ArrayList<Grouping>();
|
921
|
groups.add(new GroupByCount("count",null));
|
922
|
groups.add(new GroupByDate("created", "dateGroup", SortOrder.ASCENDING, GroupByDate.Resolution.MONTH));
|
923
|
List<Object[]> results = taxonDao.group(null, null, null, groups,null);
|
924
|
System.out.println("count\tyear\tmonth");
|
925
|
for(Object[] result : results) {
|
926
|
System.out.println(result[0] + "\t" + result[1] + "\t" + result[2]);
|
927
|
}
|
928
|
}
|
929
|
|
930
|
@Test
|
931
|
@DataSet
|
932
|
public final void testGetTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(){
|
933
|
Classification classification = classificationDao.findByUuid(classificationUuid);
|
934
|
assertNotNull(taxonDao.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(classification));
|
935
|
}
|
936
|
|
937
|
@Test
|
938
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
939
|
public void testGetAuditEventsByType() {
|
940
|
|
941
|
List<String> propertyPaths = new ArrayList<String>();
|
942
|
propertyPaths.add("name");
|
943
|
propertyPaths.add("createdBy");
|
944
|
propertyPaths.add("updatedBy");
|
945
|
|
946
|
List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(TaxonBase.class, previousAuditEvent, mostRecentAuditEvent, null,null, null, AuditEventSort.FORWARDS, propertyPaths);
|
947
|
assertNotNull("getAuditEvents should return a list",auditEvents);
|
948
|
assertFalse("the list should not be empty",auditEvents.isEmpty());
|
949
|
assertEquals("There should be thirty eight AuditEventRecords in the list",38, auditEvents.size());
|
950
|
}
|
951
|
|
952
|
@Test
|
953
|
@Ignore
|
954
|
@DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
|
955
|
public void testGetAuditEventsByTypeWithRestrictions() {
|
956
|
|
957
|
List<String> propertyPaths = new ArrayList<String>();
|
958
|
propertyPaths.add("name");
|
959
|
propertyPaths.add("createdBy");
|
960
|
propertyPaths.add("updatedBy");
|
961
|
|
962
|
List<AuditCriterion> criteria = new ArrayList<AuditCriterion>();
|
963
|
criteria.add(AuditEntity.property("lsid_lsid").isNotNull());
|
964
|
|
965
|
List<AuditEventRecord<TaxonBase>> auditEvents = taxonDao.getAuditEvents(TaxonBase.class, previousAuditEvent, mostRecentAuditEvent, criteria,null, null, AuditEventSort.FORWARDS, propertyPaths);
|
966
|
assertNotNull("getAuditEvents should return a list",auditEvents);
|
967
|
assertFalse("the list should not be empty",auditEvents.isEmpty());
|
968
|
assertEquals("There should be one AuditEventRecord in the list",1, auditEvents.size());
|
969
|
}
|
970
|
@Test
|
971
|
@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
|
972
|
public void testGetCommonName(){
|
973
|
|
974
|
|
975
|
List textData = taxonDao.getTaxaByCommonName("common%", null,
|
976
|
MatchMode.BEGINNING, null, null, null, null);
|
977
|
|
978
|
assertNotNull("getTaxaByCommonName should return a list", textData);
|
979
|
assertFalse("the list should not be empty", textData.isEmpty());
|
980
|
assertEquals("There should be one Taxon with common name", 1,textData.size());
|
981
|
// System.err.println("Number of common names: " +textData.size());
|
982
|
|
983
|
}
|
984
|
|
985
|
@Test
|
986
|
@DataSet("TaxonNodeDaoHibernateImplTest.xml")
|
987
|
@Ignore
|
988
|
public void testCreateInferredSynonymy(){
|
989
|
Classification tree = this.classificationDao.findById(1);
|
990
|
Taxon taxon = (Taxon)taxonDao.findByUuid(UUID.fromString("bc09aca6-06fd-4905-b1e7-cbf7cc65d783"));
|
991
|
List <Synonym> synonyms = taxonDao.getAllSynonyms(null, null);
|
992
|
assertEquals("Number of synonyms should be 2",2,synonyms.size());
|
993
|
|
994
|
//synonyms = taxonDao.getAllSynonyms(null, null);
|
995
|
//assertEquals("Number of synonyms should be 2",2,synonyms.size());
|
996
|
List<Synonym> inferredSynonyms = taxonDao.createInferredSynonyms(taxon, tree, SynonymRelationshipType.INFERRED_EPITHET_OF());
|
997
|
assertNotNull("there should be a new synonym ", inferredSynonyms);
|
998
|
System.err.println(inferredSynonyms.get(0).getTitleCache());
|
999
|
assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms.get(0).getTitleCache(), "SynGenus lachesis sec. ???");
|
1000
|
inferredSynonyms = taxonDao.createInferredSynonyms(taxon, tree, SynonymRelationshipType.INFERRED_GENUS_OF());
|
1001
|
assertNotNull("there should be a new synonym ", inferredSynonyms);
|
1002
|
System.err.println(inferredSynonyms.get(0).getTitleCache());
|
1003
|
assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms.get(0).getTitleCache(), "Acherontia ciprosus sec. ???");
|
1004
|
inferredSynonyms = taxonDao.createInferredSynonyms(taxon, tree, SynonymRelationshipType.POTENTIAL_COMBINATION_OF());
|
1005
|
assertNotNull("there should be a new synonym ", inferredSynonyms);
|
1006
|
assertEquals ("the name of inferred epithet should be SynGenus lachesis", inferredSynonyms.get(0).getTitleCache(), "SynGenus ciprosus sec. ???");
|
1007
|
|
1008
|
//assertTrue("set of synonyms should contain an inferred Synonym ", synonyms.contains(arg0))
|
1009
|
}
|
1010
|
|
1011
|
|
1012
|
|
1013
|
}
|