2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
15 import java
.io
.FileNotFoundException
;
16 import java
.util
.List
;
17 import java
.util
.UUID
;
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
;
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
.NonViralName
;
43 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
44 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
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
;
59 * @author a.kohlbecker
62 public class TaxonServiceSearchTaxaAndNamesTest
extends CdmTransactionalIntegrationTest
{
64 private static Logger logger
= Logger
.getLogger(TaxonServiceSearchTaxaAndNamesTest
.class);
66 private static final String ABIES_BALSAMEA_UUID
= "f65d47bd-4f49-4ab1-bc4a-bc4551eaa1a8";
68 private static final String ABIES_ALBA_UUID
= "7dbd5810-a3e5-44b6-b563-25152b8867f4";
70 private static final String CLASSIFICATION_UUID
= "2a5ceebb-4830-4524-b330-78461bf8cb6b";
72 private static final String CLASSIFICATION_ALT_UUID
= "d7c741e3-ae9e-4a7d-a566-9e3a7a0b51ce";
74 private static final String D_ABIES_BALSAMEA_UUID
= "900108d8-e6ce-495e-b32e-7aad3099135e";
76 private static final String D_ABIES_ALBA_UUID
= "ec8bba03-d993-4c85-8472-18b14942464b";
78 private static final String D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID
= "e9d8c2fd-6409-46d5-9c2e-14a2bbb1b2b1";
81 private ITaxonService taxonService
;
83 private ITermService termService
;
85 private IClassificationService classificationService
;
87 private IReferenceService referenceService
;
89 private IDescriptionService descriptionService
;
91 private INameService nameService
;
93 private ICdmMassIndexer indexer
;
96 private ITaxonNodeService nodeService
;
99 private NamedArea germany
;
100 private NamedArea france
;
101 private NamedArea russia
;
102 private NamedArea canada
;
105 * @throws java.lang.Exception
108 public void setUp() throws Exception
{
110 germany
= Country
.GERMANY();
111 france
= Country
.FRANCEFRENCHREPUBLIC();
112 russia
= Country
.RUSSIANFEDERATION();
113 canada
= Country
.CANADA();
117 public void testDbUnitUsageTest() throws Exception
{
119 assertNotNull("taxonService should exist", taxonService
);
120 assertNotNull("nameService should exist", nameService
);
125 * {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)}
129 * This test permutes through all search mode combinations.
133 * 1 misapplied which is also in the set of accepted
134 * 2 Names without taxa
139 public final void testFindTaxaAndNames() {
141 IFindTaxaAndNamesConfigurator
<?
> conf
= new FindTaxaAndNamesConfiguratorImpl();
142 conf
.setTitleSearchString("Abies*");
143 conf
.setMatchMode(MatchMode
.BEGINNING
);
145 // ---------------------------------------------------------
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());
152 setTaxaAndNamesModes(conf
, false, true, true, true, true);
153 pager
= taxonService
.findTaxaAndNames(conf
);
154 assertEquals(4, pager
.getRecords().size());
156 setTaxaAndNamesModes(conf
, true, false, true, true, true);
157 pager
= taxonService
.findTaxaAndNames(conf
);
158 assertEquals(9, pager
.getRecords().size());
160 setTaxaAndNamesModes(conf
, false, false, true, true, true);
161 pager
= taxonService
.findTaxaAndNames(conf
);
162 //logSearchResults(pager, Level.DEBUG);
163 assertEquals(3, pager
.getRecords().size());
165 // ---------------------------------------------------------
167 setTaxaAndNamesModes(conf
, true, true, false, true, true);
168 pager
= taxonService
.findTaxaAndNames(conf
);
169 logSearchResults(pager
, Level
.DEBUG
);
170 assertEquals(10, pager
.getRecords().size());
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());
176 setTaxaAndNamesModes(conf
, true, false, false, true, true);
177 pager
= taxonService
.findTaxaAndNames(conf
);
178 assertEquals(9, pager
.getRecords().size());
180 setTaxaAndNamesModes(conf
, false, false, false, true, true);
181 pager
= taxonService
.findTaxaAndNames(conf
);
182 assertEquals(3, pager
.getRecords().size());
184 // =========================================================
186 setTaxaAndNamesModes(conf
, true, true, true, false, true);
187 pager
= taxonService
.findTaxaAndNames(conf
);
188 // logSearchResults(pager, Level.DEBUG);
189 assertEquals(10, pager
.getRecords().size());
191 setTaxaAndNamesModes(conf
, false, true, true, false, true);
192 pager
= taxonService
.findTaxaAndNames(conf
);
193 logSearchResults(pager
, Level
.DEBUG
);
194 assertEquals(3, pager
.getRecords().size());
196 setTaxaAndNamesModes(conf
, true, false, true, false, true);
197 pager
= taxonService
.findTaxaAndNames(conf
);
198 logSearchResults(pager
, Level
.DEBUG
);
199 assertEquals(9, pager
.getRecords().size());
201 setTaxaAndNamesModes(conf
, false, false, true, false, true);
202 pager
= taxonService
.findTaxaAndNames(conf
);
203 logSearchResults(pager
, Level
.DEBUG
);
204 assertEquals(2, pager
.getRecords().size());
206 // ---------------------------------------------------------
208 setTaxaAndNamesModes(conf
, true, true, false, false, true);
209 pager
= taxonService
.findTaxaAndNames(conf
);
210 logSearchResults(pager
, Level
.DEBUG
);
211 assertEquals(10, pager
.getRecords().size());
213 setTaxaAndNamesModes(conf
, false, true, false, false, true);
214 pager
= taxonService
.findTaxaAndNames(conf
);
215 logSearchResults(pager
, Level
.DEBUG
);
216 assertEquals(3, pager
.getRecords().size());
218 setTaxaAndNamesModes(conf
, true, false, false, false, true);
219 pager
= taxonService
.findTaxaAndNames(conf
);
220 logSearchResults(pager
, Level
.DEBUG
);
221 assertEquals(9, pager
.getRecords().size());
223 // only names without taxa
224 // - Abies borisii-regis
226 setTaxaAndNamesModes(conf
, false, false, false, false, true);
227 pager
= taxonService
.findTaxaAndNames(conf
);
228 logSearchResults(pager
, Level
.DEBUG
);
229 assertEquals(2, pager
.getRecords().size());
231 // =========================================================
233 setTaxaAndNamesModes(conf
, true, true, true, true, false);
234 pager
= taxonService
.findTaxaAndNames(conf
);
235 logSearchResults(pager
, Level
.DEBUG
);
236 assertEquals(8, pager
.getRecords().size());
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());
243 setTaxaAndNamesModes(conf
, true, false, true, true, false);
244 pager
= taxonService
.findTaxaAndNames(conf
);
245 logSearchResults(pager
, Level
.DEBUG
);
246 assertEquals(7, pager
.getRecords().size());
248 setTaxaAndNamesModes(conf
, false, false, true, true, false);
249 pager
= taxonService
.findTaxaAndNames(conf
);
250 logSearchResults(pager
, Level
.DEBUG
);
251 assertEquals(1, pager
.getRecords().size());
253 // ---------------------------------------------------------
255 setTaxaAndNamesModes(conf
, true, true, false, true, false);
256 pager
= taxonService
.findTaxaAndNames(conf
);
257 logSearchResults(pager
, Level
.DEBUG
);
258 assertEquals(8, pager
.getRecords().size());
260 setTaxaAndNamesModes(conf
, false, true, false, true, false);
261 pager
= taxonService
.findTaxaAndNames(conf
);
262 logSearchResults(pager
, Level
.DEBUG
);
263 assertEquals(2, pager
.getRecords().size());
265 setTaxaAndNamesModes(conf
, true, false, false, true, false);
266 pager
= taxonService
.findTaxaAndNames(conf
);
267 logSearchResults(pager
, Level
.DEBUG
);
268 assertEquals(7, pager
.getRecords().size());
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());
277 // =========================================================
279 setTaxaAndNamesModes(conf
, true, true, true, false, false);
280 pager
= taxonService
.findTaxaAndNames(conf
);
281 logSearchResults(pager
, Level
.DEBUG
);
282 assertEquals(8, pager
.getRecords().size());
285 setTaxaAndNamesModes(conf
, false, true, true, false, false);
286 pager
= taxonService
.findTaxaAndNames(conf
);
287 logSearchResults(pager
, Level
.DEBUG
);
288 assertEquals(1, pager
.getRecords().size());
290 setTaxaAndNamesModes(conf
, true, false, true, false, false);
291 pager
= taxonService
.findTaxaAndNames(conf
);
292 logSearchResults(pager
, Level
.DEBUG
);
293 assertEquals(7, pager
.getRecords().size());
295 setTaxaAndNamesModes(conf
, false, false, true, false, false);
296 pager
= taxonService
.findTaxaAndNames(conf
);
297 logSearchResults(pager
, Level
.DEBUG
);
298 assertEquals(0, pager
.getRecords().size());
300 // ---------------------------------------------------------
302 setTaxaAndNamesModes(conf
, true, true, false, false, false);
303 pager
= taxonService
.findTaxaAndNames(conf
);
304 logSearchResults(pager
, Level
.DEBUG
);
305 assertEquals(8, pager
.getRecords().size());
307 setTaxaAndNamesModes(conf
, false, true, false, false, false);
308 pager
= taxonService
.findTaxaAndNames(conf
);
309 logSearchResults(pager
, Level
.DEBUG
);
310 assertEquals(1, pager
.getRecords().size());
312 setTaxaAndNamesModes(conf
, true, false, false, false, false);
313 pager
= taxonService
.findTaxaAndNames(conf
);
314 logSearchResults(pager
, Level
.DEBUG
);
315 assertEquals(7, pager
.getRecords().size());
317 setTaxaAndNamesModes(conf
, false, false, false, false, false);
318 pager
= taxonService
.findTaxaAndNames(conf
);
319 logSearchResults(pager
, Level
.DEBUG
);
320 assertEquals(0, pager
.getRecords().size());
326 * {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)}
330 * This test permutes through all search mode combinations with classification filter
335 * 2 names without taxa
340 public final void testFindTaxaAndNames_with_classification() {
342 IFindTaxaAndNamesConfigurator
<?
> conf
= new FindTaxaAndNamesConfiguratorImpl();
343 conf
.setTitleSearchString("Abies*");
344 conf
.setClassification(classificationService
.load(UUID
.fromString(CLASSIFICATION_UUID
)));
345 conf
.setMatchMode(MatchMode
.BEGINNING
);
347 // ---------------------------------------------------------
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());
355 setTaxaAndNamesModes(conf
, false, true, true, true, true);
356 pager
= taxonService
.findTaxaAndNames(conf
);
357 logSearchResults(pager
, Level
.DEBUG
);
358 assertEquals(4, pager
.getRecords().size());
360 setTaxaAndNamesModes(conf
, true, false, true, true, true);
361 pager
= taxonService
.findTaxaAndNames(conf
);
362 assertEquals(4, pager
.getRecords().size());
364 setTaxaAndNamesModes(conf
, false, false, true, true, true);
365 pager
= taxonService
.findTaxaAndNames(conf
);
366 //logSearchResults(pager, Level.DEBUG);
367 assertEquals(3, pager
.getRecords().size());
369 // ---------------------------------------------------------
371 setTaxaAndNamesModes(conf
, true, true, false, true, true);
372 pager
= taxonService
.findTaxaAndNames(conf
);
373 assertEquals(5, pager
.getRecords().size());
375 setTaxaAndNamesModes(conf
, false, true, false, true, true);
376 pager
= taxonService
.findTaxaAndNames(conf
);
377 assertEquals(4, pager
.getRecords().size());
379 setTaxaAndNamesModes(conf
, true, false, false, true, true);
380 pager
= taxonService
.findTaxaAndNames(conf
);
381 assertEquals(4, pager
.getRecords().size());
383 setTaxaAndNamesModes(conf
, false, false, false, true, true);
384 pager
= taxonService
.findTaxaAndNames(conf
);
385 assertEquals(3, pager
.getRecords().size());
387 // =========================================================
389 setTaxaAndNamesModes(conf
, true, true, true, false, true);
390 pager
= taxonService
.findTaxaAndNames(conf
);
391 // logSearchResults(pager, Level.DEBUG);
392 assertEquals(4, pager
.getRecords().size());
395 setTaxaAndNamesModes(conf
, false, true, true, false, true);
396 pager
= taxonService
.findTaxaAndNames(conf
);
397 logSearchResults(pager
, Level
.DEBUG
);
398 assertEquals(3, pager
.getRecords().size());
400 setTaxaAndNamesModes(conf
, true, false, true, false, true);
401 pager
= taxonService
.findTaxaAndNames(conf
);
402 logSearchResults(pager
, Level
.DEBUG
);
403 assertEquals(3, pager
.getRecords().size());
405 setTaxaAndNamesModes(conf
, false, false, true, false, true);
406 pager
= taxonService
.findTaxaAndNames(conf
);
407 logSearchResults(pager
, Level
.DEBUG
);
408 assertEquals(2, pager
.getRecords().size());
410 // ---------------------------------------------------------
412 setTaxaAndNamesModes(conf
, true, true, false, false, true);
413 pager
= taxonService
.findTaxaAndNames(conf
);
414 logSearchResults(pager
, Level
.DEBUG
);
415 assertEquals(4, pager
.getRecords().size());
417 setTaxaAndNamesModes(conf
, false, true, false, false, true);
418 pager
= taxonService
.findTaxaAndNames(conf
);
419 logSearchResults(pager
, Level
.DEBUG
);
420 assertEquals(3, pager
.getRecords().size());
422 setTaxaAndNamesModes(conf
, true, false, false, false, true);
423 pager
= taxonService
.findTaxaAndNames(conf
);
424 logSearchResults(pager
, Level
.DEBUG
);
425 assertEquals(3, pager
.getRecords().size());
427 // only names without taxa
428 // - Abies borisii-regis
430 setTaxaAndNamesModes(conf
, false, false, false, false, true);
431 pager
= taxonService
.findTaxaAndNames(conf
);
432 logSearchResults(pager
, Level
.DEBUG
);
433 assertEquals(2, pager
.getRecords().size());
435 // =========================================================
437 setTaxaAndNamesModes(conf
, true, true, true, true, false);
438 pager
= taxonService
.findTaxaAndNames(conf
);
439 logSearchResults(pager
, Level
.DEBUG
);
440 assertEquals(3, pager
.getRecords().size());
443 setTaxaAndNamesModes(conf
, false, true, true, true, false);
444 pager
= taxonService
.findTaxaAndNames(conf
);
445 logSearchResults(pager
, Level
.DEBUG
);
446 assertEquals(2, pager
.getRecords().size());
448 setTaxaAndNamesModes(conf
, true, false, true, true, false);
449 pager
= taxonService
.findTaxaAndNames(conf
);
450 logSearchResults(pager
, Level
.DEBUG
);
451 assertEquals(2, pager
.getRecords().size());
453 setTaxaAndNamesModes(conf
, false, false, true, true, false);
454 pager
= taxonService
.findTaxaAndNames(conf
);
455 logSearchResults(pager
, Level
.DEBUG
);
456 assertEquals(1, pager
.getRecords().size());
458 // ---------------------------------------------------------
460 setTaxaAndNamesModes(conf
, true, true, false, true, false);
461 pager
= taxonService
.findTaxaAndNames(conf
);
462 logSearchResults(pager
, Level
.DEBUG
);
463 assertEquals(3, pager
.getRecords().size());
465 setTaxaAndNamesModes(conf
, false, true, false, true, false);
466 pager
= taxonService
.findTaxaAndNames(conf
);
467 logSearchResults(pager
, Level
.DEBUG
);
468 assertEquals(2, pager
.getRecords().size());
470 setTaxaAndNamesModes(conf
, true, false, false, true, false);
471 pager
= taxonService
.findTaxaAndNames(conf
);
472 logSearchResults(pager
, Level
.DEBUG
);
473 assertEquals(2, pager
.getRecords().size());
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());
482 // =========================================================
484 setTaxaAndNamesModes(conf
, true, true, true, false, false);
485 pager
= taxonService
.findTaxaAndNames(conf
);
486 logSearchResults(pager
, Level
.DEBUG
);
487 assertEquals(2, pager
.getRecords().size());
490 setTaxaAndNamesModes(conf
, false, true, true, false, false);
491 pager
= taxonService
.findTaxaAndNames(conf
);
492 logSearchResults(pager
, Level
.DEBUG
);
493 assertEquals(1, pager
.getRecords().size());
495 setTaxaAndNamesModes(conf
, true, false, true, false, false);
496 pager
= taxonService
.findTaxaAndNames(conf
);
497 logSearchResults(pager
, Level
.DEBUG
);
498 assertEquals(1, pager
.getRecords().size());
500 setTaxaAndNamesModes(conf
, false, false, true, false, false);
501 pager
= taxonService
.findTaxaAndNames(conf
);
502 logSearchResults(pager
, Level
.DEBUG
);
503 assertEquals(0, pager
.getRecords().size());
505 // ---------------------------------------------------------
507 setTaxaAndNamesModes(conf
, true, true, false, false, false);
508 pager
= taxonService
.findTaxaAndNames(conf
);
509 logSearchResults(pager
, Level
.DEBUG
);
510 assertEquals(2, pager
.getRecords().size());
512 setTaxaAndNamesModes(conf
, false, true, false, false, false);
513 pager
= taxonService
.findTaxaAndNames(conf
);
514 logSearchResults(pager
, Level
.DEBUG
);
515 assertEquals(1, pager
.getRecords().size());
517 setTaxaAndNamesModes(conf
, true, false, false, false, false);
518 pager
= taxonService
.findTaxaAndNames(conf
);
519 logSearchResults(pager
, Level
.DEBUG
);
520 assertEquals(1, pager
.getRecords().size());
522 setTaxaAndNamesModes(conf
, false, false, false, false, false);
523 pager
= taxonService
.findTaxaAndNames(conf
);
524 logSearchResults(pager
, Level
.DEBUG
);
525 assertEquals(0, pager
.getRecords().size());
530 * {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)}
535 public final void testFindTaxaAndNames_CommonName() {
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");
545 Pager
<IdentifiableEntity
> pager
= taxonService
.findTaxaAndNames(configurator
);
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());
564 * {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)}
568 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class)
569 public final void testFindTaxaAndNamesWithHybridFormula() {
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);
580 Pager
<IdentifiableEntity
> pager
= taxonService
.findTaxaAndNames(configurator
);
581 // Assert.assertEquals("Expecting one taxon",1,pager.getRecords().size());
582 List
<IdentifiableEntity
> list
= pager
.getRecords();
587 * {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#searchTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}
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);
601 List
<UuidAndTitleCache
<IdentifiableEntity
>> list
= taxonService
.findTaxaAndNamesForEditor(configurator
);
603 Assert
.assertEquals("Expecting one entity", 1, list
.size());
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);
612 list
= taxonService
.findTaxaAndNamesForEditor(configurator
);
614 Assert
.assertEquals("Expecting one entity", 1, list
.size());
624 * @param doCommonNames
625 * @param doMisappliedNames
626 * @param doNamesWithoutTaxa
629 protected IFindTaxaAndNamesConfigurator
<?
> setTaxaAndNamesModes(
630 IFindTaxaAndNamesConfigurator
<?
> conf
,
633 boolean doCommonNames
,
634 boolean doMisappliedNames
,
635 boolean doNamesWithoutTaxa
){
637 conf
.setDoTaxa(doTaxa
);
638 conf
.setDoSynonyms(doSynonyms
);
639 conf
.setDoTaxaByCommonNames(doCommonNames
);
640 conf
.setDoMisappliedNames(doMisappliedNames
);
641 conf
.setDoNamesWithoutTaxa(doNamesWithoutTaxa
);
649 protected void logSearchResults(Pager
<IdentifiableEntity
> pager
, Level level
) {
650 List
<IdentifiableEntity
> list
= pager
.getRecords();
651 logger
.debug("number of taxa: " + list
.size());
653 if (logger
.isDebugEnabled()) {
654 for (int i
= 0; i
< list
.size(); i
++) {
655 String nameCache
= "";
656 if (list
.get(i
) instanceof NonViralName
) {
657 nameCache
= ((NonViralName
<?
>) list
.get(i
)).getNameCache();
658 } else if (list
.get(i
) instanceof TaxonBase
) {
659 TaxonNameBase
<?
,?
> taxonNameBase
= ((TaxonBase
) list
.get(i
)).getName();
660 nameCache
= taxonNameBase
.getNameCache();
663 logger
.log(level
, list
.get(i
).getClass() + "(" + i
+ ")" + ": Name Cache = " + nameCache
+ ", Title Cache = "
664 + list
.get(i
).getTitleCache());
670 * uncomment @Test annotation to create the dataset for this test
674 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="BlankDataSet.xml")
675 public final void createTestDataSet() throws FileNotFoundException
{
677 Classification europeanAbiesClassification
= Classification
.NewInstance("European Abies");
678 europeanAbiesClassification
.setUuid(UUID
.fromString(CLASSIFICATION_UUID
));
679 classificationService
.save(europeanAbiesClassification
);
681 Classification alternativeClassification
= Classification
.NewInstance("Abies alternative");
682 alternativeClassification
.setUuid(UUID
.fromString(CLASSIFICATION_ALT_UUID
));
683 classificationService
.save(alternativeClassification
);
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
);
692 BotanicalName n_abies
= TaxonNameBase
.NewBotanicalInstance(Rank
.GENUS());
693 n_abies
.setNameCache("Abies", true);
694 Taxon t_abies
= Taxon
.NewInstance(n_abies
, sec
);
695 taxonService
.save(t_abies
);
697 BotanicalName n_abies_alba
= TaxonNameBase
.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
);
703 BotanicalName n_abies_subalpina
= TaxonNameBase
.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
);
708 BotanicalName n_abies_balsamea
= TaxonNameBase
.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
);
715 BotanicalName n_abies_grandis
= TaxonNameBase
.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
);
720 BotanicalName n_abies_kawakamii
= TaxonNameBase
.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
);
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
);
735 BotanicalName n_abies_lasiocarpa
= TaxonNameBase
.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
);
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
);
747 // 2 Names without taxa
749 BotanicalName n_abies_borisiiregis
= TaxonNameBase
.NewBotanicalInstance(Rank
.SPECIES());
750 n_abies_borisiiregis
.setNameCache("Abies borisii-regis", true);
751 nameService
.save(n_abies_borisiiregis
);
753 BotanicalName n_abies_lasio
= TaxonNameBase
.NewBotanicalInstance(Rank
.SPECIES());
754 n_abies_lasio
.setNameCache("Abies lasio", true);
755 nameService
.save(n_abies_lasio
);
757 // A hybrid name not from Abies
758 BotanicalName n_abies_millefolium_x_Achillea_nobilis
= TaxonNameBase
.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
);
766 TaxonDescription d_abies_alba
= TaxonDescription
.NewInstance(t_abies_alba
);
767 TaxonDescription d_abies_balsamea
= TaxonDescription
.NewInstance(t_abies_balsamea
);
769 d_abies_alba
.setUuid(UUID
.fromString(D_ABIES_ALBA_UUID
));
770 d_abies_balsamea
.setUuid(UUID
.fromString(D_ABIES_BALSAMEA_UUID
));
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
779 PresenceAbsenceTerm
.NATIVE()));
780 d_abies_alba
.addElement(Distribution
783 PresenceAbsenceTerm
.ABSENT()));
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));
792 .addElement(CommonTaxonName
795 Language
.GERMAN(), null));
798 .addElement(Distribution
801 PresenceAbsenceTerm
.PRESENT()));
804 .addElement(Distribution
807 PresenceAbsenceTerm
.NATIVE()));
812 TaxonServiceSearchTestUtf8Constants
.RUSSIAN_ABIES_ALBA_LONG
,
813 Language
.RUSSIAN(), null));
815 .addElement(CommonTaxonName
817 TaxonServiceSearchTestUtf8Constants
.RUSSIAN_ABIES_ALBA_SHORT
,
818 Language
.RUSSIAN(), null));
819 descriptionService
.saveOrUpdate(d_abies_balsamea
);
825 writeDbUnitDataSetFile(new String
[] {
826 "TAXONBASE", "TAXONNAMEBASE",
828 "REFERENCE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONBASE",
829 "AGENTBASE", "HOMOTYPICALGROUP",
830 "CLASSIFICATION", "TAXONNODE",
831 "LANGUAGESTRING", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING",
832 "HIBERNATE_SEQUENCES" // IMPORTANT!!!