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