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.util.List;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.Ignore;
|
19
|
import org.junit.Test;
|
20
|
import org.unitils.dbunit.annotation.DataSet;
|
21
|
import org.unitils.spring.annotation.SpringBeanByType;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator;
|
24
|
import eu.etaxonomy.cdm.api.service.config.TaxonServiceConfiguratorImpl;
|
25
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
26
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
27
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
28
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
29
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
30
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
31
|
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
|
32
|
|
33
|
/**
|
34
|
* @author a.babadshanjan
|
35
|
* @created 04.02.2009
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class TaxonServiceSearchTest extends CdmIntegrationTest {
|
39
|
private static Logger logger = Logger.getLogger(TaxonServiceSearchTest.class);
|
40
|
|
41
|
@SpringBeanByType
|
42
|
private ITaxonService taxonService;
|
43
|
@SpringBeanByType
|
44
|
private INameService nameService;
|
45
|
|
46
|
|
47
|
@Test
|
48
|
public void testDbUnitUsageTest() throws Exception {
|
49
|
assertNotNull("taxonService should exist", taxonService);
|
50
|
assertNotNull("nameService should exist", nameService);
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator)}.
|
55
|
*/
|
56
|
@Ignore // TaxonServiceSearchTest.xml cannot be inserted - structure changed?
|
57
|
@Test
|
58
|
@DataSet
|
59
|
public final void testFindTaxaAndNames() {
|
60
|
|
61
|
ITaxonServiceConfigurator configurator = new TaxonServiceConfiguratorImpl();
|
62
|
configurator.setTitleSearchString("Abies*");
|
63
|
configurator.setMatchMode(MatchMode.BEGINNING);
|
64
|
configurator.setDoTaxa(true);
|
65
|
configurator.setDoSynonyms(true);
|
66
|
configurator.setDoNamesWithoutTaxa(true);
|
67
|
configurator.setDoTaxaByCommonNames(true);
|
68
|
Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(configurator);
|
69
|
List<IdentifiableEntity> list = pager.getRecords();
|
70
|
if (logger.isDebugEnabled()) {
|
71
|
for (int i = 0; i < list.size(); i++) {
|
72
|
String nameCache = "";
|
73
|
if (list.get(i) instanceof NonViralName) {
|
74
|
nameCache = ((NonViralName<?>)list.get(i)).getNameCache();
|
75
|
} else if (list.get(i) instanceof TaxonBase) {
|
76
|
TaxonNameBase taxonNameBase= ((TaxonBase)list.get(i)).getName();
|
77
|
nameCache = ((NonViralName)taxonNameBase).getNameCache();
|
78
|
} else {}
|
79
|
logger.debug(list.get(i).getClass() + "(" + i +")" +
|
80
|
": Name Cache = " + nameCache + ", Title Cache = " + list.get(i).getTitleCache());
|
81
|
}
|
82
|
}
|
83
|
assertEquals(list.get(1).getTitleCache(), "Abies mill. sec. ???");
|
84
|
assertEquals(list.get(4).getTitleCache(), "Abies alba Mill. sec. ???");
|
85
|
}
|
86
|
|
87
|
// @Test
|
88
|
// @DataSet
|
89
|
// public final void testPrintDataSet() {
|
90
|
// printDataSet(System.out);
|
91
|
// }
|
92
|
|
93
|
}
|