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