1 |
239f5f52
|
Andreas Müller
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2007 EDIT
|
4 |
|
|
* European Distributed Institute of Taxonomy
|
5 |
|
|
* http://www.e-taxonomy.eu
|
6 |
|
|
*
|
7 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9 |
|
|
*/
|
10 |
|
|
|
11 |
|
|
package eu.etaxonomy.cdm.io.excel.taxa;
|
12 |
|
|
|
13 |
|
|
import static org.junit.Assert.assertEquals;
|
14 |
|
|
import static org.junit.Assert.assertNotNull;
|
15 |
|
|
import static org.junit.Assert.assertTrue;
|
16 |
|
|
|
17 |
d06ba760
|
Patric Plitzner
|
import java.io.FileNotFoundException;
|
18 |
ec12cc39
|
Andreas Müller
|
import java.net.URISyntaxException;
|
19 |
239f5f52
|
Andreas Müller
|
import java.net.URL;
|
20 |
|
|
import java.util.ArrayList;
|
21 |
|
|
import java.util.HashSet;
|
22 |
|
|
import java.util.Iterator;
|
23 |
|
|
import java.util.List;
|
24 |
|
|
import java.util.Set;
|
25 |
a3c03eaf
|
Andreas Müller
|
import java.util.UUID;
|
26 |
239f5f52
|
Andreas Müller
|
|
27 |
|
|
import org.apache.log4j.Logger;
|
28 |
a13c5f66
|
Andreas Müller
|
import org.junit.Assert;
|
29 |
239f5f52
|
Andreas Müller
|
import org.junit.Before;
|
30 |
|
|
import org.junit.Test;
|
31 |
|
|
import org.unitils.dbunit.annotation.DataSet;
|
32 |
|
|
import org.unitils.spring.annotation.SpringBeanByName;
|
33 |
|
|
import org.unitils.spring.annotation.SpringBeanByType;
|
34 |
|
|
|
35 |
d1b4be9a
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
36 |
239f5f52
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.INameService;
|
37 |
|
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
38 |
cec69672
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
39 |
239f5f52
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
|
40 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
41 |
b843bc50
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
42 |
a3c03eaf
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.Language;
|
43 |
b843bc50
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
44 |
239f5f52
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
45 |
|
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
46 |
289d49ad
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
47 |
a3c03eaf
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.Feature;
|
48 |
239f5f52
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
49 |
a3c03eaf
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.TextData;
|
50 |
239f5f52
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
51 |
|
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
52 |
5316cc5a
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
53 |
bf1f7581
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
54 |
d1b4be9a
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
55 |
239f5f52
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
56 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
57 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
58 |
|
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* @author a.mueller
|
62 |
|
|
* @created 26.08.2009
|
63 |
|
|
* @version 1.0
|
64 |
|
|
*/
|
65 |
|
|
public class NormalExplicitImportTest extends CdmTransactionalIntegrationTest{
|
66 |
|
|
@SuppressWarnings("unused")
|
67 |
|
|
private static final Logger logger = Logger.getLogger(NormalExplicitImportTest.class);
|
68 |
|
|
|
69 |
|
|
@SpringBeanByName
|
70 |
a13c5f66
|
Andreas Müller
|
CdmApplicationAwareDefaultImport<?> defaultImport;
|
71 |
239f5f52
|
Andreas Müller
|
|
72 |
|
|
@SpringBeanByType
|
73 |
|
|
INameService nameService;
|
74 |
|
|
|
75 |
|
|
@SpringBeanByType
|
76 |
|
|
ITaxonService taxonService;
|
77 |
01c21ead
|
n.hoffmann
|
|
78 |
cec69672
|
Andreas Müller
|
@SpringBeanByType
|
79 |
|
|
ITermService termService;
|
80 |
|
|
|
81 |
01c21ead
|
n.hoffmann
|
@SpringBeanByType
|
82 |
1d36aa54
|
Andreas Müller
|
IClassificationService classificationService;
|
83 |
239f5f52
|
Andreas Müller
|
|
84 |
|
|
private IImportConfigurator configurator;
|
85 |
a3c03eaf
|
Andreas Müller
|
private IImportConfigurator uuidConfigurator;
|
86 |
239f5f52
|
Andreas Müller
|
|
87 |
|
|
@Before
|
88 |
ec12cc39
|
Andreas Müller
|
public void setUp() throws URISyntaxException {
|
89 |
239f5f52
|
Andreas Müller
|
String inputFile = "/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImportTest-input.xls";
|
90 |
|
|
URL url = this.getClass().getResource(inputFile);
|
91 |
|
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
92 |
742459f7
|
Andreas Müller
|
configurator = NormalExplicitImportConfigurator.NewInstance(url.toURI(), null, NomenclaturalCode.ICNAFP, null);
|
93 |
239f5f52
|
Andreas Müller
|
assertNotNull("Configurator could not be created", configurator);
|
94 |
a3c03eaf
|
Andreas Müller
|
|
95 |
|
|
inputFile = "/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImportTest.testUuid-input.xls";
|
96 |
|
|
url = this.getClass().getResource(inputFile);
|
97 |
|
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
98 |
742459f7
|
Andreas Müller
|
uuidConfigurator = NormalExplicitImportConfigurator.NewInstance(url.toURI(), null, NomenclaturalCode.ICNAFP, null);
|
99 |
b68adb94
|
Andreas Müller
|
assertNotNull("Configurator could be created", configurator);
|
100 |
a3c03eaf
|
Andreas Müller
|
|
101 |
239f5f52
|
Andreas Müller
|
}
|
102 |
|
|
|
103 |
|
|
@Test
|
104 |
|
|
public void testInit() {
|
105 |
|
|
assertNotNull("normalExplicitImport should not be null", defaultImport);
|
106 |
|
|
assertNotNull("nameService should not be null", nameService);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
@Test
|
110 |
|
|
@DataSet
|
111 |
|
|
public void testDoInvoke() {
|
112 |
|
|
//printDataSet(System.out);
|
113 |
|
|
boolean result = defaultImport.invoke(configurator);
|
114 |
|
|
assertTrue("Return value for import.invoke should be true", result);
|
115 |
3b12e61e
|
ben.clark
|
assertEquals("Number of TaxonNames should be 9", 9, nameService.count(null));
|
116 |
1d36aa54
|
Andreas Müller
|
List<Classification> treeList = classificationService.list(null, null,null,null,null);
|
117 |
|
|
assertEquals("Number of classifications should be 1", 1, treeList.size());
|
118 |
|
|
Classification tree = treeList.get(0);
|
119 |
efdb6847
|
Andreas Müller
|
List<TaxonNode> rootNodes = tree.getChildNodes();
|
120 |
239f5f52
|
Andreas Müller
|
assertEquals("Number of root nodes should be 1", 1, rootNodes.size());
|
121 |
|
|
TaxonNode rootNode = rootNodes.iterator().next();
|
122 |
|
|
assertEquals("Root taxon name should be Animalia", "Animalia", rootNode.getTaxon().getName().getTitleCache());
|
123 |
|
|
TaxonNode arthropodaNode = rootNode.getChildNodes().iterator().next();
|
124 |
|
|
assertEquals("Arthropoda node taxon name should be Arthropoda", "Arthropoda", arthropodaNode.getTaxon().getName().getTitleCache());
|
125 |
|
|
TaxonNode insectaNode = arthropodaNode.getChildNodes().iterator().next();
|
126 |
|
|
TaxonNode lepidopteraNode = insectaNode.getChildNodes().iterator().next();
|
127 |
|
|
TaxonNode noctuidaeNode = lepidopteraNode.getChildNodes().iterator().next();
|
128 |
|
|
TaxonNode noctuaNode = noctuidaeNode.getChildNodes().iterator().next();
|
129 |
|
|
assertEquals("Number of child nodes of noctuca should be 2", 2, noctuaNode.getChildNodes().size());
|
130 |
|
|
|
131 |
|
|
Iterator<TaxonNode> it = noctuaNode.getChildNodes().iterator();
|
132 |
|
|
TaxonNode childNode1 = it.next();
|
133 |
|
|
TaxonNode childNode2 = it.next();
|
134 |
|
|
|
135 |
|
|
TaxonNode noctuaPronubaNode;
|
136 |
|
|
if (childNode1.getTaxon().getName().getTitleCache().startsWith("Noctua pronuba")){
|
137 |
|
|
noctuaPronubaNode = childNode1;
|
138 |
|
|
}else{
|
139 |
|
|
noctuaPronubaNode = childNode2;
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
assertEquals("Noctua pronuba taxon name should be ", "Noctua pronuba", noctuaPronubaNode.getTaxon().getName().getTitleCache());
|
143 |
|
|
Taxon noctuaPronubaTaxon = noctuaPronubaNode.getTaxon();
|
144 |
|
|
Set<Synonym> synonyms = noctuaPronubaTaxon.getSynonyms();
|
145 |
|
|
assertEquals("Number of synonyms should be 1", 1, synonyms.size());
|
146 |
|
|
Synonym synonym = synonyms.iterator().next();
|
147 |
a13c5f66
|
Andreas Müller
|
assertEquals("Synonym name should be ", "Noctua atlantica", ((NonViralName<?>)synonym.getName()).getNameCache());
|
148 |
239f5f52
|
Andreas Müller
|
Set<TaxonDescription> descriptions = noctuaPronubaTaxon.getDescriptions();
|
149 |
|
|
Assert.assertEquals("Number of descriptions should be 1", 1, descriptions.size());
|
150 |
|
|
TaxonDescription taxonDescription = descriptions.iterator().next();
|
151 |
|
|
Set<DescriptionElementBase> elements = taxonDescription.getElements();
|
152 |
|
|
List<CommonTaxonName> commonNames = new ArrayList<CommonTaxonName>();
|
153 |
|
|
for (DescriptionElementBase element : elements){
|
154 |
|
|
if (element.isInstanceOf(CommonTaxonName.class)){
|
155 |
|
|
commonNames.add((CommonTaxonName)element);
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
Assert.assertEquals("Number of common names should be 2", 2, commonNames.size());
|
159 |
|
|
Set<String> commonNameStrings = new HashSet<String>();
|
160 |
|
|
commonNameStrings.add(commonNames.get(0).getName());
|
161 |
|
|
commonNameStrings.add(commonNames.get(1).getName());
|
162 |
|
|
Assert.assertTrue("Common names must include Yellow Underwing", commonNameStrings.contains("Large Sunshine Underwing"));
|
163 |
|
|
Assert.assertTrue("Common names must include Yellow Underwing", commonNameStrings.contains("Yellow Underwing"));
|
164 |
|
|
}
|
165 |
d1b4be9a
|
Andreas Müller
|
|
166 |
|
|
@Test
|
167 |
a3c03eaf
|
Andreas Müller
|
@DataSet(value="NormalExplicitImportTest.testUuid.xml")
|
168 |
d1b4be9a
|
Andreas Müller
|
public void testUUID() throws URISyntaxException{
|
169 |
a3c03eaf
|
Andreas Müller
|
UUID taxonUuid = UUID.fromString("aafce7fe-0c5f-42ed-814b-4c7c2c715660");
|
170 |
cec69672
|
Andreas Müller
|
UUID synonymUuid = UUID.fromString("fc4a995b-37a9-4984-afe6-e352c6c04d92");
|
171 |
|
|
|
172 |
|
|
|
173 |
a3c03eaf
|
Andreas Müller
|
//test data set
|
174 |
cec69672
|
Andreas Müller
|
assertEquals("Number of taxon bases should be 2", 2, taxonService.count(null));
|
175 |
a3c03eaf
|
Andreas Müller
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid);
|
176 |
|
|
assertNotNull("Taxon with given uuid should exist", taxon);
|
177 |
|
|
assertEquals("Taxon should have no description", 0, taxon.getDescriptions().size());
|
178 |
cec69672
|
Andreas Müller
|
Synonym synonym = (Synonym)taxonService.find(synonymUuid);
|
179 |
|
|
assertNotNull("Synonym with given uuid should exist", synonym);
|
180 |
|
|
assertEquals("Synonym should have 1 accepted taxon", 1, synonym.getAcceptedTaxa().size());
|
181 |
|
|
|
182 |
a3c03eaf
|
Andreas Müller
|
//import
|
183 |
|
|
boolean result = defaultImport.invoke(uuidConfigurator);
|
184 |
|
|
//test result
|
185 |
d1b4be9a
|
Andreas Müller
|
assertTrue("Return value for import.invoke should be true", result);
|
186 |
cec69672
|
Andreas Müller
|
assertEquals("Number of taxon names should be 2", 2, nameService.count(null));
|
187 |
|
|
assertEquals("Number of taxa should be 2", 2, taxonService.count(null));
|
188 |
a3c03eaf
|
Andreas Müller
|
taxon = (Taxon)taxonService.find(taxonUuid);
|
189 |
|
|
assertEquals("Taxon should have 1 description", 1, taxon.getDescriptions().size());
|
190 |
|
|
TaxonDescription description = taxon.getDescriptions().iterator().next();
|
191 |
cec69672
|
Andreas Müller
|
assertEquals("Number of description elements should be 2", 2, description.getElements().size());
|
192 |
3b8a0b9a
|
Andreas Müller
|
|
193 |
b843bc50
|
Andreas Müller
|
String expectedText = "Description for the first taxon";
|
194 |
|
|
TextData textData = getTextElement(description, expectedText);
|
195 |
|
|
assertNotNull("The element should exists", textData);
|
196 |
a3c03eaf
|
Andreas Müller
|
Feature feature = textData.getFeature();
|
197 |
|
|
assertEquals("Unexpected feature", Feature.DESCRIPTION(), feature);
|
198 |
b843bc50
|
Andreas Müller
|
assertEquals("There should be exactly 1 language", 1,textData.getMultilanguageText().size());
|
199 |
|
|
Language language = textData.getMultilanguageText().keySet().iterator().next();
|
200 |
|
|
assertEquals("Language should be German", Language.GERMAN(), language);
|
201 |
|
|
String text = textData.getText(language);
|
202 |
|
|
assertEquals("Unexpected description text", expectedText, text);
|
203 |
bf1f7581
|
Andreas Müller
|
assertEquals("Number of source elements should be 1", 1, textData.getSources().size());
|
204 |
|
|
DescriptionElementSource source = textData.getSources().iterator().next();
|
205 |
a13c5f66
|
Andreas Müller
|
Reference<?> ref = source.getCitation();
|
206 |
bf1f7581
|
Andreas Müller
|
assertNotNull("Citation should not be null", ref);
|
207 |
9fda2b40
|
Andreas Müller
|
assertNotNull("Authorship should not be null", ref.getAuthorship());
|
208 |
f89911d1
|
Andreas Müller
|
assertEquals("Source author should be 'Meyer et. al.'", "Meyer et. al.",ref.getAuthorship().getTitleCache());
|
209 |
b843bc50
|
Andreas Müller
|
assertEquals("Publication title should be 'My first book'", "My first book", ref.getTitle());
|
210 |
bf1f7581
|
Andreas Müller
|
assertEquals("Publication year should be '1987'", "1987", ref.getYear());
|
211 |
a13c5f66
|
Andreas Müller
|
TaxonNameBase<?,?> nameUsedInSource = source.getNameUsedInSource();
|
212 |
5316cc5a
|
Andreas Müller
|
assertNotNull("Name used in source should not be null", nameUsedInSource);
|
213 |
|
|
assertEquals("Name used in source title should be ", "Abies", nameUsedInSource.getTitleCache());
|
214 |
|
|
|
215 |
|
|
|
216 |
cec69672
|
Andreas Müller
|
//synonym
|
217 |
b843bc50
|
Andreas Müller
|
expectedText = "A synonym description";
|
218 |
|
|
textData = getTextElement(description, expectedText);
|
219 |
|
|
assertNotNull("The element should exists", textData);
|
220 |
|
|
feature = textData.getFeature();
|
221 |
|
|
assertEquals("Unexpected feature", Feature.DESCRIPTION(), feature);
|
222 |
|
|
assertEquals("There should be exactly 1 language", 1,textData.getMultilanguageText().size());
|
223 |
|
|
language = textData.getMultilanguageText().keySet().iterator().next();
|
224 |
f6b17945
|
Andreas Kohlbecker
|
assertEquals("Language should be Spanish", Language.SPANISH_CASTILIAN(), language);
|
225 |
b843bc50
|
Andreas Müller
|
text = textData.getText(language);
|
226 |
|
|
assertEquals("Unexpected description text", expectedText, text);
|
227 |
|
|
assertEquals("Number of source elements should be 1", 1, textData.getSources().size());
|
228 |
|
|
source = textData.getSources().iterator().next();
|
229 |
|
|
ref = source.getCitation();
|
230 |
|
|
assertNotNull("Citation should not be null", ref);
|
231 |
9fda2b40
|
Andreas Müller
|
assertNotNull("Authorship should not be null", ref.getAuthorship());
|
232 |
f89911d1
|
Andreas Müller
|
assertEquals("Source author should be 'Theys, A.'", "Theys, A.",ref.getAuthorship().getTitleCache());
|
233 |
b843bc50
|
Andreas Müller
|
assertEquals("Publication title should be 'The ultimate book'", "The ultimate book", ref.getTitle());
|
234 |
|
|
assertEquals("Publication year should be '2011'", "2011", ref.getYear());
|
235 |
5316cc5a
|
Andreas Müller
|
nameUsedInSource = source.getNameUsedInSource();
|
236 |
|
|
assertNotNull("Name used in source should not be null", nameUsedInSource);
|
237 |
|
|
assertEquals("Name used in source title should be Pinus", "Pinus", nameUsedInSource.getTitleCache());
|
238 |
a3c03eaf
|
Andreas Müller
|
|
239 |
d1b4be9a
|
Andreas Müller
|
}
|
240 |
cec69672
|
Andreas Müller
|
|
241 |
|
|
/**
|
242 |
|
|
* Returns description element for record id 1
|
243 |
|
|
* @param description
|
244 |
|
|
* @return
|
245 |
|
|
*/
|
246 |
b843bc50
|
Andreas Müller
|
private TextData getTextElement(TaxonDescription description, String descriptionText) {
|
247 |
|
|
for (DescriptionElementBase element : description.getElements()){
|
248 |
|
|
if (element.isInstanceOf(TextData.class)){
|
249 |
|
|
TextData textData = CdmBase.deproxy(element, TextData.class);
|
250 |
|
|
for (LanguageString ls :textData.getMultilanguageText().values()){
|
251 |
|
|
if (ls.getText().equals(descriptionText)){
|
252 |
|
|
return textData;
|
253 |
|
|
}
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
}
|
257 |
cec69672
|
Andreas Müller
|
return null;
|
258 |
|
|
}
|
259 |
|
|
|
260 |
d06ba760
|
Patric Plitzner
|
/* (non-Javadoc)
|
261 |
|
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
262 |
|
|
*/
|
263 |
|
|
@Override
|
264 |
68ee041d
|
Patric Plitzner
|
public void createTestDataSet() throws FileNotFoundException {
|
265 |
d06ba760
|
Patric Plitzner
|
// TODO Auto-generated method stub
|
266 |
|
|
|
267 |
|
|
}
|
268 |
|
|
|
269 |
cec69672
|
Andreas Müller
|
}
|