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