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.api.service;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
|
15
|
import java.io.FileNotFoundException;
|
16
|
import java.util.List;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.log4j.Level;
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.junit.Assert;
|
22
|
import org.junit.Before;
|
23
|
import org.junit.Test;
|
24
|
import org.unitils.dbunit.annotation.DataSet;
|
25
|
import org.unitils.spring.annotation.SpringBeanByType;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
|
28
|
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
|
29
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
30
|
import eu.etaxonomy.cdm.api.service.search.ICdmMassIndexer;
|
31
|
import eu.etaxonomy.cdm.common.UTF8;
|
32
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
33
|
import eu.etaxonomy.cdm.model.common.Language;
|
34
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
35
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
36
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
37
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
38
|
import eu.etaxonomy.cdm.model.description.TextData;
|
39
|
import eu.etaxonomy.cdm.model.location.Country;
|
40
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
41
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
42
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
43
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
44
|
import eu.etaxonomy.cdm.model.name.Rank;
|
45
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
46
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
47
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
48
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
49
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
50
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
51
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
52
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
53
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
54
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
55
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
56
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
57
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
58
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
59
|
|
60
|
/**
|
61
|
* @author a.kohlbecker
|
62
|
* @created 04.02.2009
|
63
|
*/
|
64
|
public class TaxonServiceSearchTaxaAndNamesTest extends CdmTransactionalIntegrationTest {
|
65
|
|
66
|
private static Logger logger = Logger.getLogger(TaxonServiceSearchTaxaAndNamesTest.class);
|
67
|
|
68
|
private static final String ABIES_BALSAMEA_UUID = "f65d47bd-4f49-4ab1-bc4a-bc4551eaa1a8";
|
69
|
|
70
|
private static final String ABIES_ALBA_UUID = "7dbd5810-a3e5-44b6-b563-25152b8867f4";
|
71
|
|
72
|
private static final String CLASSIFICATION_UUID = "2a5ceebb-4830-4524-b330-78461bf8cb6b";
|
73
|
|
74
|
private static final String CLASSIFICATION_ALT_UUID = "d7c741e3-ae9e-4a7d-a566-9e3a7a0b51ce";
|
75
|
|
76
|
private static final String D_ABIES_BALSAMEA_UUID = "900108d8-e6ce-495e-b32e-7aad3099135e";
|
77
|
|
78
|
private static final String D_ABIES_ALBA_UUID = "ec8bba03-d993-4c85-8472-18b14942464b";
|
79
|
|
80
|
private static final String D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID = "e9d8c2fd-6409-46d5-9c2e-14a2bbb1b2b1";
|
81
|
|
82
|
@SpringBeanByType
|
83
|
private ITaxonService taxonService;
|
84
|
@SpringBeanByType
|
85
|
private ITermService termService;
|
86
|
@SpringBeanByType
|
87
|
private IClassificationService classificationService;
|
88
|
@SpringBeanByType
|
89
|
private IReferenceService referenceService;
|
90
|
@SpringBeanByType
|
91
|
private IDescriptionService descriptionService;
|
92
|
@SpringBeanByType
|
93
|
private INameService nameService;
|
94
|
@SpringBeanByType
|
95
|
private ICdmMassIndexer indexer;
|
96
|
|
97
|
@SpringBeanByType
|
98
|
private ITaxonNodeService nodeService;
|
99
|
|
100
|
|
101
|
private NamedArea germany;
|
102
|
private NamedArea france ;
|
103
|
private NamedArea russia ;
|
104
|
private NamedArea canada ;
|
105
|
|
106
|
/**
|
107
|
* @throws java.lang.Exception
|
108
|
*/
|
109
|
@Before
|
110
|
public void setUp() throws Exception {
|
111
|
|
112
|
germany = Country.GERMANY();
|
113
|
france = Country.FRANCEFRENCHREPUBLIC();
|
114
|
russia = Country.RUSSIANFEDERATION();
|
115
|
canada = Country.CANADA();
|
116
|
}
|
117
|
|
118
|
@Test
|
119
|
public void testDbUnitUsageTest() throws Exception {
|
120
|
|
121
|
assertNotNull("taxonService should exist", taxonService);
|
122
|
assertNotNull("nameService should exist", nameService);
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* Test method for
|
127
|
* {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)}
|
128
|
* .
|
129
|
*/
|
130
|
/**
|
131
|
* This test permutes through all search mode combinations.
|
132
|
*
|
133
|
* 7 Accepted Taxa
|
134
|
* 1 Synonym
|
135
|
* 1 misapplied which is also in the set of accepted
|
136
|
* 2 Names without taxa
|
137
|
*
|
138
|
*/
|
139
|
@Test
|
140
|
@DataSet
|
141
|
public final void testFindTaxaAndNames() {
|
142
|
|
143
|
IFindTaxaAndNamesConfigurator<?> conf = new FindTaxaAndNamesConfiguratorImpl();
|
144
|
conf.setTitleSearchString("Abies*");
|
145
|
conf.setMatchMode(MatchMode.BEGINNING);
|
146
|
|
147
|
// ---------------------------------------------------------
|
148
|
|
149
|
setTaxaAndNamesModes(conf, true, true, true, true, true);
|
150
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(conf);
|
151
|
logSearchResults(pager, Level.DEBUG);
|
152
|
assertEquals(10, pager.getRecords().size());
|
153
|
|
154
|
setTaxaAndNamesModes(conf, false, true, true, true, true);
|
155
|
pager = taxonService.findTaxaAndNames(conf);
|
156
|
assertEquals(4, pager.getRecords().size());
|
157
|
|
158
|
setTaxaAndNamesModes(conf, true, false, true, true, true);
|
159
|
pager = taxonService.findTaxaAndNames(conf);
|
160
|
assertEquals(9, pager.getRecords().size());
|
161
|
|
162
|
setTaxaAndNamesModes(conf, false, false, true, true, true);
|
163
|
pager = taxonService.findTaxaAndNames(conf);
|
164
|
//logSearchResults(pager, Level.DEBUG);
|
165
|
assertEquals(3, pager.getRecords().size());
|
166
|
|
167
|
// ---------------------------------------------------------
|
168
|
|
169
|
setTaxaAndNamesModes(conf, true, true, false, true, true);
|
170
|
pager = taxonService.findTaxaAndNames(conf);
|
171
|
logSearchResults(pager, Level.DEBUG);
|
172
|
assertEquals(10, pager.getRecords().size());
|
173
|
|
174
|
setTaxaAndNamesModes(conf, false, true, false, true, true);
|
175
|
pager = taxonService.findTaxaAndNames(conf);
|
176
|
assertEquals("one synonym, two names without taxa and a misapplied name", 4, pager.getRecords().size());
|
177
|
|
178
|
setTaxaAndNamesModes(conf, true, false, false, true, true);
|
179
|
pager = taxonService.findTaxaAndNames(conf);
|
180
|
assertEquals(9, pager.getRecords().size());
|
181
|
|
182
|
setTaxaAndNamesModes(conf, false, false, false, true, true);
|
183
|
pager = taxonService.findTaxaAndNames(conf);
|
184
|
assertEquals(3, pager.getRecords().size());
|
185
|
|
186
|
// =========================================================
|
187
|
|
188
|
setTaxaAndNamesModes(conf, true, true, true, false, true);
|
189
|
pager = taxonService.findTaxaAndNames(conf);
|
190
|
// logSearchResults(pager, Level.DEBUG);
|
191
|
assertEquals(10, pager.getRecords().size());
|
192
|
|
193
|
setTaxaAndNamesModes(conf, false, true, true, false, true);
|
194
|
pager = taxonService.findTaxaAndNames(conf);
|
195
|
logSearchResults(pager, Level.DEBUG);
|
196
|
assertEquals(3, pager.getRecords().size());
|
197
|
|
198
|
setTaxaAndNamesModes(conf, true, false, true, false, true);
|
199
|
pager = taxonService.findTaxaAndNames(conf);
|
200
|
logSearchResults(pager, Level.DEBUG);
|
201
|
assertEquals(9, pager.getRecords().size());
|
202
|
|
203
|
setTaxaAndNamesModes(conf, false, false, true, false, true);
|
204
|
pager = taxonService.findTaxaAndNames(conf);
|
205
|
logSearchResults(pager, Level.DEBUG);
|
206
|
assertEquals(2, pager.getRecords().size());
|
207
|
|
208
|
// ---------------------------------------------------------
|
209
|
|
210
|
setTaxaAndNamesModes(conf, true, true, false, false, true);
|
211
|
pager = taxonService.findTaxaAndNames(conf);
|
212
|
logSearchResults(pager, Level.DEBUG);
|
213
|
assertEquals(10, pager.getRecords().size());
|
214
|
|
215
|
setTaxaAndNamesModes(conf, false, true, false, false, true);
|
216
|
pager = taxonService.findTaxaAndNames(conf);
|
217
|
logSearchResults(pager, Level.DEBUG);
|
218
|
assertEquals(3, pager.getRecords().size());
|
219
|
|
220
|
setTaxaAndNamesModes(conf, true, false, false, false, true);
|
221
|
pager = taxonService.findTaxaAndNames(conf);
|
222
|
logSearchResults(pager, Level.DEBUG);
|
223
|
assertEquals(9, pager.getRecords().size());
|
224
|
|
225
|
// only names without taxa
|
226
|
// - Abies borisii-regis
|
227
|
// - Abies lasio
|
228
|
setTaxaAndNamesModes(conf, false, false, false, false, true);
|
229
|
pager = taxonService.findTaxaAndNames(conf);
|
230
|
logSearchResults(pager, Level.DEBUG);
|
231
|
assertEquals(2, pager.getRecords().size());
|
232
|
|
233
|
// =========================================================
|
234
|
|
235
|
setTaxaAndNamesModes(conf, true, true, true, true, false);
|
236
|
pager = taxonService.findTaxaAndNames(conf);
|
237
|
logSearchResults(pager, Level.DEBUG);
|
238
|
assertEquals(8, pager.getRecords().size());
|
239
|
|
240
|
setTaxaAndNamesModes(conf, false, true, true, true, false);
|
241
|
pager = taxonService.findTaxaAndNames(conf);
|
242
|
logSearchResults(pager, Level.DEBUG);
|
243
|
assertEquals("one synonym and a misapplied name", 2, pager.getRecords().size());
|
244
|
|
245
|
setTaxaAndNamesModes(conf, true, false, true, true, false);
|
246
|
pager = taxonService.findTaxaAndNames(conf);
|
247
|
logSearchResults(pager, Level.DEBUG);
|
248
|
assertEquals(7, pager.getRecords().size());
|
249
|
|
250
|
setTaxaAndNamesModes(conf, false, false, true, true, false);
|
251
|
pager = taxonService.findTaxaAndNames(conf);
|
252
|
logSearchResults(pager, Level.DEBUG);
|
253
|
assertEquals(1, pager.getRecords().size());
|
254
|
|
255
|
// ---------------------------------------------------------
|
256
|
|
257
|
setTaxaAndNamesModes(conf, true, true, false, true, false);
|
258
|
pager = taxonService.findTaxaAndNames(conf);
|
259
|
logSearchResults(pager, Level.DEBUG);
|
260
|
assertEquals(8, pager.getRecords().size());
|
261
|
|
262
|
setTaxaAndNamesModes(conf, false, true, false, true, false);
|
263
|
pager = taxonService.findTaxaAndNames(conf);
|
264
|
logSearchResults(pager, Level.DEBUG);
|
265
|
assertEquals(2, pager.getRecords().size());
|
266
|
|
267
|
setTaxaAndNamesModes(conf, true, false, false, true, false);
|
268
|
pager = taxonService.findTaxaAndNames(conf);
|
269
|
logSearchResults(pager, Level.DEBUG);
|
270
|
assertEquals(7, pager.getRecords().size());
|
271
|
|
272
|
// only misapplied names
|
273
|
// - Abies kawakamii sec. Komarov, V. L., Flora SSSR 29
|
274
|
setTaxaAndNamesModes(conf, false, false, false, true, false);
|
275
|
pager = taxonService.findTaxaAndNames(conf);
|
276
|
logSearchResults(pager, Level.DEBUG);
|
277
|
assertEquals(1, pager.getRecords().size());
|
278
|
|
279
|
// =========================================================
|
280
|
|
281
|
setTaxaAndNamesModes(conf, true, true, true, false, false);
|
282
|
pager = taxonService.findTaxaAndNames(conf);
|
283
|
logSearchResults(pager, Level.DEBUG);
|
284
|
assertEquals(8, pager.getRecords().size());
|
285
|
|
286
|
|
287
|
setTaxaAndNamesModes(conf, false, true, true, false, false);
|
288
|
pager = taxonService.findTaxaAndNames(conf);
|
289
|
logSearchResults(pager, Level.DEBUG);
|
290
|
assertEquals(1, pager.getRecords().size());
|
291
|
|
292
|
setTaxaAndNamesModes(conf, true, false, true, false, false);
|
293
|
pager = taxonService.findTaxaAndNames(conf);
|
294
|
logSearchResults(pager, Level.DEBUG);
|
295
|
assertEquals(7, pager.getRecords().size());
|
296
|
|
297
|
setTaxaAndNamesModes(conf, false, false, true, false, false);
|
298
|
pager = taxonService.findTaxaAndNames(conf);
|
299
|
logSearchResults(pager, Level.DEBUG);
|
300
|
assertEquals(0, pager.getRecords().size());
|
301
|
|
302
|
// ---------------------------------------------------------
|
303
|
|
304
|
setTaxaAndNamesModes(conf, true, true, false, false, false);
|
305
|
pager = taxonService.findTaxaAndNames(conf);
|
306
|
logSearchResults(pager, Level.DEBUG);
|
307
|
assertEquals(8, pager.getRecords().size());
|
308
|
|
309
|
setTaxaAndNamesModes(conf, false, true, false, false, false);
|
310
|
pager = taxonService.findTaxaAndNames(conf);
|
311
|
logSearchResults(pager, Level.DEBUG);
|
312
|
assertEquals(1, pager.getRecords().size());
|
313
|
|
314
|
setTaxaAndNamesModes(conf, true, false, false, false, false);
|
315
|
pager = taxonService.findTaxaAndNames(conf);
|
316
|
logSearchResults(pager, Level.DEBUG);
|
317
|
assertEquals(7, pager.getRecords().size());
|
318
|
|
319
|
setTaxaAndNamesModes(conf, false, false, false, false, false);
|
320
|
pager = taxonService.findTaxaAndNames(conf);
|
321
|
logSearchResults(pager, Level.DEBUG);
|
322
|
assertEquals(0, pager.getRecords().size());
|
323
|
}
|
324
|
|
325
|
|
326
|
/**
|
327
|
* Test method for
|
328
|
* {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)}
|
329
|
* .
|
330
|
*/
|
331
|
/**
|
332
|
* This test permutes through all search mode combinations with classification filter
|
333
|
*
|
334
|
* 1 accepted taxon
|
335
|
* 1 Synonym
|
336
|
* 1 misapplied
|
337
|
* 2 names without taxa
|
338
|
*
|
339
|
*/
|
340
|
@Test
|
341
|
@DataSet
|
342
|
public final void testFindTaxaAndNames_with_classification() {
|
343
|
|
344
|
IFindTaxaAndNamesConfigurator<?> conf = new FindTaxaAndNamesConfiguratorImpl();
|
345
|
conf.setTitleSearchString("Abies*");
|
346
|
conf.setClassification(classificationService.load(UUID.fromString(CLASSIFICATION_UUID)));
|
347
|
conf.setMatchMode(MatchMode.BEGINNING);
|
348
|
|
349
|
// ---------------------------------------------------------
|
350
|
|
351
|
setTaxaAndNamesModes(conf, true, true, true, true, true);
|
352
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(conf);
|
353
|
logSearchResults(pager, Level.DEBUG);
|
354
|
assertEquals(5, pager.getRecords().size());
|
355
|
|
356
|
|
357
|
setTaxaAndNamesModes(conf, false, true, true, true, true);
|
358
|
pager = taxonService.findTaxaAndNames(conf);
|
359
|
logSearchResults(pager, Level.DEBUG);
|
360
|
assertEquals(4, pager.getRecords().size());
|
361
|
|
362
|
setTaxaAndNamesModes(conf, true, false, true, true, true);
|
363
|
pager = taxonService.findTaxaAndNames(conf);
|
364
|
assertEquals(4, pager.getRecords().size());
|
365
|
|
366
|
setTaxaAndNamesModes(conf, false, false, true, true, true);
|
367
|
pager = taxonService.findTaxaAndNames(conf);
|
368
|
//logSearchResults(pager, Level.DEBUG);
|
369
|
assertEquals(3, pager.getRecords().size());
|
370
|
|
371
|
// ---------------------------------------------------------
|
372
|
|
373
|
setTaxaAndNamesModes(conf, true, true, false, true, true);
|
374
|
pager = taxonService.findTaxaAndNames(conf);
|
375
|
assertEquals(5, pager.getRecords().size());
|
376
|
|
377
|
setTaxaAndNamesModes(conf, false, true, false, true, true);
|
378
|
pager = taxonService.findTaxaAndNames(conf);
|
379
|
assertEquals(4, pager.getRecords().size());
|
380
|
|
381
|
setTaxaAndNamesModes(conf, true, false, false, true, true);
|
382
|
pager = taxonService.findTaxaAndNames(conf);
|
383
|
assertEquals(4, pager.getRecords().size());
|
384
|
|
385
|
setTaxaAndNamesModes(conf, false, false, false, true, true);
|
386
|
pager = taxonService.findTaxaAndNames(conf);
|
387
|
assertEquals(3, pager.getRecords().size());
|
388
|
|
389
|
// =========================================================
|
390
|
|
391
|
setTaxaAndNamesModes(conf, true, true, true, false, true);
|
392
|
pager = taxonService.findTaxaAndNames(conf);
|
393
|
// logSearchResults(pager, Level.DEBUG);
|
394
|
assertEquals(4, pager.getRecords().size());
|
395
|
|
396
|
|
397
|
setTaxaAndNamesModes(conf, false, true, true, false, true);
|
398
|
pager = taxonService.findTaxaAndNames(conf);
|
399
|
logSearchResults(pager, Level.DEBUG);
|
400
|
assertEquals(3, pager.getRecords().size());
|
401
|
|
402
|
setTaxaAndNamesModes(conf, true, false, true, false, true);
|
403
|
pager = taxonService.findTaxaAndNames(conf);
|
404
|
logSearchResults(pager, Level.DEBUG);
|
405
|
assertEquals(3, pager.getRecords().size());
|
406
|
|
407
|
setTaxaAndNamesModes(conf, false, false, true, false, true);
|
408
|
pager = taxonService.findTaxaAndNames(conf);
|
409
|
logSearchResults(pager, Level.DEBUG);
|
410
|
assertEquals(2, pager.getRecords().size());
|
411
|
|
412
|
// ---------------------------------------------------------
|
413
|
|
414
|
setTaxaAndNamesModes(conf, true, true, false, false, true);
|
415
|
pager = taxonService.findTaxaAndNames(conf);
|
416
|
logSearchResults(pager, Level.DEBUG);
|
417
|
assertEquals(4, pager.getRecords().size());
|
418
|
|
419
|
setTaxaAndNamesModes(conf, false, true, false, false, true);
|
420
|
pager = taxonService.findTaxaAndNames(conf);
|
421
|
logSearchResults(pager, Level.DEBUG);
|
422
|
assertEquals(3, pager.getRecords().size());
|
423
|
|
424
|
setTaxaAndNamesModes(conf, true, false, false, false, true);
|
425
|
pager = taxonService.findTaxaAndNames(conf);
|
426
|
logSearchResults(pager, Level.DEBUG);
|
427
|
assertEquals(3, pager.getRecords().size());
|
428
|
|
429
|
// only names without taxa
|
430
|
// - Abies borisii-regis
|
431
|
// - Abies lasio
|
432
|
setTaxaAndNamesModes(conf, false, false, false, false, true);
|
433
|
pager = taxonService.findTaxaAndNames(conf);
|
434
|
logSearchResults(pager, Level.DEBUG);
|
435
|
assertEquals(2, pager.getRecords().size());
|
436
|
|
437
|
// =========================================================
|
438
|
|
439
|
setTaxaAndNamesModes(conf, true, true, true, true, false);
|
440
|
pager = taxonService.findTaxaAndNames(conf);
|
441
|
logSearchResults(pager, Level.DEBUG);
|
442
|
assertEquals(3, pager.getRecords().size());
|
443
|
|
444
|
|
445
|
setTaxaAndNamesModes(conf, false, true, true, true, false);
|
446
|
pager = taxonService.findTaxaAndNames(conf);
|
447
|
logSearchResults(pager, Level.DEBUG);
|
448
|
assertEquals(2, pager.getRecords().size());
|
449
|
|
450
|
setTaxaAndNamesModes(conf, true, false, true, true, false);
|
451
|
pager = taxonService.findTaxaAndNames(conf);
|
452
|
logSearchResults(pager, Level.DEBUG);
|
453
|
assertEquals(2, pager.getRecords().size());
|
454
|
|
455
|
setTaxaAndNamesModes(conf, false, false, true, true, false);
|
456
|
pager = taxonService.findTaxaAndNames(conf);
|
457
|
logSearchResults(pager, Level.DEBUG);
|
458
|
assertEquals(1, pager.getRecords().size());
|
459
|
|
460
|
// ---------------------------------------------------------
|
461
|
|
462
|
setTaxaAndNamesModes(conf, true, true, false, true, false);
|
463
|
pager = taxonService.findTaxaAndNames(conf);
|
464
|
logSearchResults(pager, Level.DEBUG);
|
465
|
assertEquals(3, pager.getRecords().size());
|
466
|
|
467
|
setTaxaAndNamesModes(conf, false, true, false, true, false);
|
468
|
pager = taxonService.findTaxaAndNames(conf);
|
469
|
logSearchResults(pager, Level.DEBUG);
|
470
|
assertEquals(2, pager.getRecords().size());
|
471
|
|
472
|
setTaxaAndNamesModes(conf, true, false, false, true, false);
|
473
|
pager = taxonService.findTaxaAndNames(conf);
|
474
|
logSearchResults(pager, Level.DEBUG);
|
475
|
assertEquals(2, pager.getRecords().size());
|
476
|
|
477
|
// only misapplied names
|
478
|
// - Abies kawakamii sec. Komarov, V. L., Flora SSSR 29
|
479
|
setTaxaAndNamesModes(conf, false, false, false, true, false);
|
480
|
pager = taxonService.findTaxaAndNames(conf);
|
481
|
logSearchResults(pager, Level.DEBUG);
|
482
|
assertEquals(1, pager.getRecords().size());
|
483
|
|
484
|
// =========================================================
|
485
|
|
486
|
setTaxaAndNamesModes(conf, true, true, true, false, false);
|
487
|
pager = taxonService.findTaxaAndNames(conf);
|
488
|
logSearchResults(pager, Level.DEBUG);
|
489
|
assertEquals(2, pager.getRecords().size());
|
490
|
|
491
|
|
492
|
setTaxaAndNamesModes(conf, false, true, true, false, false);
|
493
|
pager = taxonService.findTaxaAndNames(conf);
|
494
|
logSearchResults(pager, Level.DEBUG);
|
495
|
assertEquals(1, pager.getRecords().size());
|
496
|
|
497
|
setTaxaAndNamesModes(conf, true, false, true, false, false);
|
498
|
pager = taxonService.findTaxaAndNames(conf);
|
499
|
logSearchResults(pager, Level.DEBUG);
|
500
|
assertEquals(1, pager.getRecords().size());
|
501
|
|
502
|
setTaxaAndNamesModes(conf, false, false, true, false, false);
|
503
|
pager = taxonService.findTaxaAndNames(conf);
|
504
|
logSearchResults(pager, Level.DEBUG);
|
505
|
assertEquals(0, pager.getRecords().size());
|
506
|
|
507
|
// ---------------------------------------------------------
|
508
|
|
509
|
setTaxaAndNamesModes(conf, true, true, false, false, false);
|
510
|
pager = taxonService.findTaxaAndNames(conf);
|
511
|
logSearchResults(pager, Level.DEBUG);
|
512
|
assertEquals(2, pager.getRecords().size());
|
513
|
|
514
|
setTaxaAndNamesModes(conf, false, true, false, false, false);
|
515
|
pager = taxonService.findTaxaAndNames(conf);
|
516
|
logSearchResults(pager, Level.DEBUG);
|
517
|
assertEquals(1, pager.getRecords().size());
|
518
|
|
519
|
setTaxaAndNamesModes(conf, true, false, false, false, false);
|
520
|
pager = taxonService.findTaxaAndNames(conf);
|
521
|
logSearchResults(pager, Level.DEBUG);
|
522
|
assertEquals(1, pager.getRecords().size());
|
523
|
|
524
|
setTaxaAndNamesModes(conf, false, false, false, false, false);
|
525
|
pager = taxonService.findTaxaAndNames(conf);
|
526
|
logSearchResults(pager, Level.DEBUG);
|
527
|
assertEquals(0, pager.getRecords().size());
|
528
|
}
|
529
|
|
530
|
/**
|
531
|
* Test method for
|
532
|
* {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)}
|
533
|
* .
|
534
|
*/
|
535
|
@Test
|
536
|
@DataSet
|
537
|
public final void testFindTaxaAndNames_CommonName() {
|
538
|
// pass 1
|
539
|
IFindTaxaAndNamesConfigurator<?> configurator = new FindTaxaAndNamesConfiguratorImpl();
|
540
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
541
|
configurator.setDoTaxa(true);
|
542
|
configurator.setDoSynonyms(true);
|
543
|
configurator.setDoNamesWithoutTaxa(true);
|
544
|
configurator.setDoTaxaByCommonNames(true);
|
545
|
configurator.setTitleSearchString("Balsam-Tanne");
|
546
|
|
547
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(configurator);
|
548
|
|
549
|
List<IdentifiableEntity> list = pager.getRecords();
|
550
|
assertEquals(1, list.size());
|
551
|
configurator.setTitleSearchString("Abies*");
|
552
|
configurator.setDoTaxa(false);
|
553
|
configurator.setDoSynonyms(false);
|
554
|
configurator.setDoNamesWithoutTaxa(false);
|
555
|
configurator.setDoTaxaByCommonNames(true);
|
556
|
configurator.setDoMisappliedNames(true);
|
557
|
configurator.setClassification(classificationService.load(UUID.fromString(CLASSIFICATION_UUID)));
|
558
|
pager = taxonService.findTaxaAndNames(configurator);
|
559
|
list = pager.getRecords();
|
560
|
assertEquals(1, list.size());
|
561
|
|
562
|
}
|
563
|
|
564
|
/**
|
565
|
* Test method for
|
566
|
* {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)}
|
567
|
* .
|
568
|
*/
|
569
|
@Test
|
570
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
571
|
public final void testFindTaxaAndNamesWithHybridFormula() {
|
572
|
|
573
|
// pass 1
|
574
|
IFindTaxaAndNamesConfigurator<?> configurator = new FindTaxaAndNamesConfiguratorImpl();
|
575
|
configurator.setTitleSearchString("Achillea*");
|
576
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
577
|
configurator.setDoTaxa(true);
|
578
|
configurator.setDoSynonyms(true);
|
579
|
configurator.setDoNamesWithoutTaxa(true);
|
580
|
configurator.setDoTaxaByCommonNames(true);
|
581
|
|
582
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(configurator);
|
583
|
// Assert.assertEquals("Expecting one taxon",1,pager.getRecords().size());
|
584
|
List<IdentifiableEntity> list = pager.getRecords();
|
585
|
}
|
586
|
|
587
|
/**
|
588
|
* Test method for
|
589
|
* {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#searchTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}
|
590
|
* .
|
591
|
*/
|
592
|
@Test
|
593
|
@DataSet
|
594
|
public final void testfindTaxaAndNamesForEditor() {
|
595
|
IFindTaxaAndNamesConfigurator<?> configurator = new FindTaxaAndNamesConfiguratorImpl();
|
596
|
configurator.setTitleSearchString("Abies bor*");
|
597
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
598
|
configurator.setDoTaxa(true);
|
599
|
configurator.setDoSynonyms(false);
|
600
|
configurator.setDoNamesWithoutTaxa(true);
|
601
|
configurator.setDoTaxaByCommonNames(false);
|
602
|
|
603
|
List<UuidAndTitleCache<IdentifiableEntity>> list = taxonService.findTaxaAndNamesForEditor(configurator);
|
604
|
|
605
|
Assert.assertEquals("Expecting one entity", 1, list.size());
|
606
|
|
607
|
configurator.setTitleSearchString("silver fir");
|
608
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
609
|
configurator.setDoTaxa(false);
|
610
|
configurator.setDoSynonyms(false);
|
611
|
configurator.setDoNamesWithoutTaxa(true);
|
612
|
configurator.setDoTaxaByCommonNames(true);
|
613
|
|
614
|
list = taxonService.findTaxaAndNamesForEditor(configurator);
|
615
|
|
616
|
Assert.assertEquals("Expecting one entity", 1, list.size());
|
617
|
|
618
|
}
|
619
|
|
620
|
|
621
|
/**
|
622
|
*
|
623
|
* @param conf
|
624
|
* @param doTaxa
|
625
|
* @param doSynonyms
|
626
|
* @param doCommonNames
|
627
|
* @param doMisappliedNames
|
628
|
* @param doNamesWithoutTaxa
|
629
|
* @return
|
630
|
*/
|
631
|
protected IFindTaxaAndNamesConfigurator<?> setTaxaAndNamesModes(
|
632
|
IFindTaxaAndNamesConfigurator<?> conf,
|
633
|
boolean doTaxa,
|
634
|
boolean doSynonyms,
|
635
|
boolean doCommonNames,
|
636
|
boolean doMisappliedNames,
|
637
|
boolean doNamesWithoutTaxa){
|
638
|
|
639
|
conf.setDoTaxa(doTaxa);
|
640
|
conf.setDoSynonyms(doSynonyms);
|
641
|
conf.setDoTaxaByCommonNames(doCommonNames);
|
642
|
conf.setDoMisappliedNames(doMisappliedNames);
|
643
|
conf.setDoNamesWithoutTaxa(doNamesWithoutTaxa);
|
644
|
|
645
|
return conf;
|
646
|
}
|
647
|
|
648
|
/**
|
649
|
* @param pager
|
650
|
*/
|
651
|
protected void logSearchResults(Pager<IdentifiableEntity> pager, Level level) {
|
652
|
List<IdentifiableEntity> list = pager.getRecords();
|
653
|
logger.debug("number of taxa: " + list.size());
|
654
|
|
655
|
if (logger.isDebugEnabled()) {
|
656
|
for (int i = 0; i < list.size(); i++) {
|
657
|
String nameCache = "";
|
658
|
if (list.get(i) instanceof NonViralName) {
|
659
|
nameCache = ((INonViralName) list.get(i)).getNameCache();
|
660
|
} else if (list.get(i) instanceof TaxonBase) {
|
661
|
TaxonNameBase<?,?> taxonNameBase = ((TaxonBase) list.get(i)).getName();
|
662
|
nameCache = taxonNameBase.getNameCache();
|
663
|
} else {
|
664
|
}
|
665
|
logger.log(level, list.get(i).getClass() + "(" + i + ")" + ": Name Cache = " + nameCache + ", Title Cache = "
|
666
|
+ list.get(i).getTitleCache());
|
667
|
}
|
668
|
}
|
669
|
}
|
670
|
|
671
|
/**
|
672
|
* uncomment @Test annotation to create the dataset for this test
|
673
|
*/
|
674
|
@Override
|
675
|
// @Test
|
676
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="BlankDataSet.xml")
|
677
|
public final void createTestDataSet() throws FileNotFoundException {
|
678
|
|
679
|
Classification europeanAbiesClassification = Classification.NewInstance("European Abies");
|
680
|
europeanAbiesClassification.setUuid(UUID.fromString(CLASSIFICATION_UUID));
|
681
|
classificationService.save(europeanAbiesClassification);
|
682
|
|
683
|
Classification alternativeClassification = Classification.NewInstance("Abies alternative");
|
684
|
alternativeClassification.setUuid(UUID.fromString(CLASSIFICATION_ALT_UUID));
|
685
|
classificationService.save(alternativeClassification);
|
686
|
|
687
|
Reference sec = ReferenceFactory.newBook();
|
688
|
sec.setTitleCache("Kohlbecker, A., Testcase standart views, 2013", true);
|
689
|
Reference sec_sensu = ReferenceFactory.newBook();
|
690
|
sec_sensu.setTitleCache("Komarov, V. L., Flora SSSR 29", true);
|
691
|
referenceService.save(sec);
|
692
|
referenceService.save(sec_sensu);
|
693
|
|
694
|
BotanicalName n_abies = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
695
|
n_abies.setNameCache("Abies", true);
|
696
|
Taxon t_abies = Taxon.NewInstance(n_abies, sec);
|
697
|
taxonService.save(t_abies);
|
698
|
|
699
|
BotanicalName n_abies_alba = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
700
|
n_abies_alba.setNameCache("Abies alba", true);
|
701
|
Taxon t_abies_alba = Taxon.NewInstance(n_abies_alba, sec);
|
702
|
t_abies_alba.setUuid(UUID.fromString(ABIES_ALBA_UUID));
|
703
|
taxonService.save(t_abies_alba);
|
704
|
|
705
|
BotanicalName n_abies_subalpina = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
706
|
n_abies_subalpina.setNameCache("Abies subalpina", true);
|
707
|
Synonym s_abies_subalpina = Synonym.NewInstance(n_abies_subalpina, sec);
|
708
|
taxonService.save(s_abies_subalpina);
|
709
|
|
710
|
BotanicalName n_abies_balsamea = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
711
|
n_abies_balsamea.setNameCache("Abies balsamea", true);
|
712
|
Taxon t_abies_balsamea = Taxon.NewInstance(n_abies_balsamea, sec);
|
713
|
t_abies_balsamea.setUuid(UUID.fromString(ABIES_BALSAMEA_UUID));
|
714
|
t_abies_balsamea.addSynonym(s_abies_subalpina, SynonymType.SYNONYM_OF());
|
715
|
taxonService.save(t_abies_balsamea);
|
716
|
|
717
|
BotanicalName n_abies_grandis = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
718
|
n_abies_grandis.setNameCache("Abies grandis", true);
|
719
|
Taxon t_abies_grandis = Taxon.NewInstance(n_abies_grandis, sec);
|
720
|
taxonService.save(t_abies_grandis);
|
721
|
|
722
|
BotanicalName n_abies_kawakamii = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
723
|
n_abies_kawakamii.setNameCache("Abies kawakamii", true);
|
724
|
Taxon t_abies_kawakamii = Taxon.NewInstance(n_abies_kawakamii, sec);
|
725
|
t_abies_kawakamii.getTitleCache();
|
726
|
taxonService.save(t_abies_kawakamii);
|
727
|
|
728
|
//
|
729
|
// 1 Misapplied Name
|
730
|
//
|
731
|
// abies_kawakamii_sensu_komarov as missapplied name for t_abies_balsamea
|
732
|
Taxon t_abies_kawakamii_sensu_komarov = Taxon.NewInstance(n_abies_kawakamii, sec_sensu);
|
733
|
taxonService.save(t_abies_kawakamii_sensu_komarov);
|
734
|
t_abies_kawakamii_sensu_komarov.addTaxonRelation(t_abies_balsamea, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null);
|
735
|
taxonService.saveOrUpdate(t_abies_kawakamii_sensu_komarov);
|
736
|
|
737
|
BotanicalName n_abies_lasiocarpa = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
738
|
n_abies_lasiocarpa.setNameCache("Abies lasiocarpa", true);
|
739
|
Taxon t_abies_lasiocarpa = Taxon.NewInstance(n_abies_lasiocarpa, sec);
|
740
|
taxonService.save(t_abies_lasiocarpa);
|
741
|
|
742
|
// add 3 taxa to classifications
|
743
|
europeanAbiesClassification.addChildTaxon(t_abies_balsamea, null, null);
|
744
|
alternativeClassification.addChildTaxon(t_abies_lasiocarpa, null, null);
|
745
|
classificationService.saveOrUpdate(europeanAbiesClassification);
|
746
|
classificationService.saveOrUpdate(alternativeClassification);
|
747
|
|
748
|
//
|
749
|
// 2 Names without taxa
|
750
|
//
|
751
|
BotanicalName n_abies_borisiiregis = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
752
|
n_abies_borisiiregis.setNameCache("Abies borisii-regis", true);
|
753
|
nameService.save(n_abies_borisiiregis);
|
754
|
|
755
|
BotanicalName n_abies_lasio = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
756
|
n_abies_lasio.setNameCache("Abies lasio", true);
|
757
|
nameService.save(n_abies_lasio);
|
758
|
|
759
|
// A hybrid name not from Abies
|
760
|
BotanicalName n_abies_millefolium_x_Achillea_nobilis = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
761
|
n_abies_millefolium_x_Achillea_nobilis.setNameCache("Achillea millefolium × Achillea nobilis", true);
|
762
|
Taxon t_abies_millefolium_x_Achillea_nobilis = Taxon.NewInstance(n_abies_millefolium_x_Achillea_nobilis, sec);
|
763
|
taxonService.save(t_abies_millefolium_x_Achillea_nobilis);
|
764
|
|
765
|
//
|
766
|
// Description
|
767
|
//
|
768
|
TaxonDescription d_abies_alba = TaxonDescription.NewInstance(t_abies_alba);
|
769
|
TaxonDescription d_abies_balsamea = TaxonDescription.NewInstance(t_abies_balsamea);
|
770
|
|
771
|
d_abies_alba.setUuid(UUID.fromString(D_ABIES_ALBA_UUID));
|
772
|
d_abies_balsamea.setUuid(UUID.fromString(D_ABIES_BALSAMEA_UUID));
|
773
|
|
774
|
|
775
|
// CommonTaxonName
|
776
|
d_abies_alba.addElement(CommonTaxonName.NewInstance("Wei"+UTF8.SHARP_S+"tanne", Language.GERMAN()));
|
777
|
d_abies_alba.addElement(CommonTaxonName.NewInstance("silver fir", Language.ENGLISH()));
|
778
|
d_abies_alba.addElement(Distribution
|
779
|
.NewInstance(
|
780
|
germany,
|
781
|
PresenceAbsenceTerm.NATIVE()));
|
782
|
d_abies_alba.addElement(Distribution
|
783
|
.NewInstance(
|
784
|
russia,
|
785
|
PresenceAbsenceTerm.ABSENT()));
|
786
|
|
787
|
// TextData
|
788
|
d_abies_balsamea
|
789
|
.addElement(TextData
|
790
|
.NewInstance(
|
791
|
"Die Balsam-Tanne (Abies balsamea) ist eine Pflanzenart aus der Gattung der Tannen (Abies). Sie wächst im nordöstlichen Nordamerika, wo sie sowohl Tief- als auch Bergland besiedelt. Sie gilt als relativ anspruchslos gegenüber dem Standort und ist frosthart. In vielen Teilen des natürlichen Verbreitungsgebietes stellt sie die Klimaxbaumart dar.",
|
792
|
Language.GERMAN(), null));
|
793
|
d_abies_balsamea
|
794
|
.addElement(CommonTaxonName
|
795
|
.NewInstance(
|
796
|
"Balsam-Tanne",
|
797
|
Language.GERMAN(), null));
|
798
|
|
799
|
d_abies_balsamea
|
800
|
.addElement(Distribution
|
801
|
.NewInstance(
|
802
|
canada,
|
803
|
PresenceAbsenceTerm.PRESENT()));
|
804
|
|
805
|
d_abies_balsamea
|
806
|
.addElement(Distribution
|
807
|
.NewInstance(
|
808
|
germany,
|
809
|
PresenceAbsenceTerm.NATIVE()));
|
810
|
|
811
|
d_abies_balsamea
|
812
|
.addElement(TextData
|
813
|
.NewInstance(
|
814
|
TaxonServiceSearchTestUtf8Constants.RUSSIAN_ABIES_ALBA_LONG,
|
815
|
Language.RUSSIAN(), null));
|
816
|
d_abies_balsamea
|
817
|
.addElement(CommonTaxonName
|
818
|
.NewInstance(
|
819
|
TaxonServiceSearchTestUtf8Constants.RUSSIAN_ABIES_ALBA_SHORT,
|
820
|
Language.RUSSIAN(), null));
|
821
|
descriptionService.saveOrUpdate(d_abies_balsamea);
|
822
|
|
823
|
setComplete();
|
824
|
endTransaction();
|
825
|
|
826
|
|
827
|
writeDbUnitDataSetFile(new String[] {
|
828
|
"TAXONBASE", "TAXONNAMEBASE",
|
829
|
"TAXONRELATIONSHIP",
|
830
|
"REFERENCE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONBASE",
|
831
|
"AGENTBASE", "HOMOTYPICALGROUP",
|
832
|
"CLASSIFICATION", "TAXONNODE",
|
833
|
"LANGUAGESTRING", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING",
|
834
|
"HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
835
|
});
|
836
|
|
837
|
}
|
838
|
|
839
|
}
|