// $Id$\r
/**\r
* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
* http://www.e-taxonomy.eu\r
-* \r
+*\r
* The contents of this file are subject to the Mozilla Public License Version 1.1\r
* See LICENSE.TXT at the top of this package for the full license terms.\r
*/\r
import static org.junit.Assert.assertNotNull;\r
import static org.junit.Assert.assertTrue;\r
\r
+import java.io.FileNotFoundException;\r
import java.net.URISyntaxException;\r
import java.net.URL;\r
import java.util.ArrayList;\r
\r
@SpringBeanByType\r
INameService nameService;\r
- \r
+\r
@SpringBeanByType\r
ITaxonService taxonService;\r
- \r
+\r
@SpringBeanByType\r
ITermService termService;\r
- \r
+\r
@SpringBeanByType\r
IClassificationService classificationService;\r
\r
private IImportConfigurator configurator;\r
private IImportConfigurator uuidConfigurator;\r
- \r
+ private IImportConfigurator configuratorXslx;\r
+\r
@Before\r
public void setUp() throws URISyntaxException {\r
String inputFile = "/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImportTest-input.xls";\r
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);\r
configurator = NormalExplicitImportConfigurator.NewInstance(url.toURI(), null, NomenclaturalCode.ICNAFP, null);\r
assertNotNull("Configurator could not be created", configurator);\r
- \r
+\r
inputFile = "/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImportTest.testUuid-input.xls";\r
url = this.getClass().getResource(inputFile);\r
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);\r
uuidConfigurator = NormalExplicitImportConfigurator.NewInstance(url.toURI(), null, NomenclaturalCode.ICNAFP, null);\r
assertNotNull("Configurator could be created", configurator);\r
- \r
+\r
+ String inputFileXslx = "/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImportTest-input.xlsx";\r
+ url = this.getClass().getResource(inputFileXslx);\r
+ assertNotNull("URL for the test file '" + inputFileXslx + "' does not exist", url);\r
+ configuratorXslx = NormalExplicitImportConfigurator.NewInstance(url.toURI(), null, NomenclaturalCode.ICNAFP, null);\r
+ assertNotNull("Configurator could not be created", configuratorXslx);\r
+\r
+\r
}\r
- \r
+\r
@Test\r
public void testInit() {\r
assertNotNull("normalExplicitImport should not be null", defaultImport);\r
assertNotNull("nameService should not be null", nameService);\r
}\r
- \r
+\r
@Test\r
@DataSet\r
public void testDoInvoke() {\r
//printDataSet(System.out);\r
- boolean result = defaultImport.invoke(configurator);\r
+ boolean result = defaultImport.invoke(configurator).isSuccess();\r
+ assertTrue("Return value for import.invoke should be true", result);\r
+ assertEquals("Number of TaxonNames should be 9", 9, nameService.count(null));\r
+ List<Classification> treeList = classificationService.list(null, null,null,null,null);\r
+ assertEquals("Number of classifications should be 1", 1, treeList.size());\r
+ Classification tree = treeList.get(0);\r
+ List<TaxonNode> rootNodes = tree.getChildNodes();\r
+ assertEquals("Number of root nodes should be 1", 1, rootNodes.size());\r
+ TaxonNode rootNode = rootNodes.iterator().next();\r
+ assertEquals("Root taxon name should be Animalia", "Animalia", rootNode.getTaxon().getName().getTitleCache());\r
+ TaxonNode arthropodaNode = rootNode.getChildNodes().iterator().next();\r
+ assertEquals("Arthropoda node taxon name should be Arthropoda", "Arthropoda", arthropodaNode.getTaxon().getName().getTitleCache());\r
+ TaxonNode insectaNode = arthropodaNode.getChildNodes().iterator().next();\r
+ TaxonNode lepidopteraNode = insectaNode.getChildNodes().iterator().next();\r
+ TaxonNode noctuidaeNode = lepidopteraNode.getChildNodes().iterator().next();\r
+ TaxonNode noctuaNode = noctuidaeNode.getChildNodes().iterator().next();\r
+ assertEquals("Number of child nodes of noctuca should be 2", 2, noctuaNode.getChildNodes().size());\r
+\r
+ Iterator<TaxonNode> it = noctuaNode.getChildNodes().iterator();\r
+ TaxonNode childNode1 = it.next();\r
+ TaxonNode childNode2 = it.next();\r
+\r
+ TaxonNode noctuaPronubaNode;\r
+ if (childNode1.getTaxon().getName().getTitleCache().startsWith("Noctua pronuba")){\r
+ noctuaPronubaNode = childNode1;\r
+ }else{\r
+ noctuaPronubaNode = childNode2;\r
+ }\r
+\r
+ assertEquals("Noctua pronuba taxon name should be ", "Noctua pronuba", noctuaPronubaNode.getTaxon().getName().getTitleCache());\r
+ Taxon noctuaPronubaTaxon = noctuaPronubaNode.getTaxon();\r
+ Set<Synonym> synonyms = noctuaPronubaTaxon.getSynonyms();\r
+ assertEquals("Number of synonyms should be 1", 1, synonyms.size());\r
+ Synonym synonym = synonyms.iterator().next();\r
+ assertEquals("Synonym name should be ", "Noctua atlantica", ((NonViralName<?>)synonym.getName()).getNameCache());\r
+ Set<TaxonDescription> descriptions = noctuaPronubaTaxon.getDescriptions();\r
+ Assert.assertEquals("Number of descriptions should be 1", 1, descriptions.size());\r
+ TaxonDescription taxonDescription = descriptions.iterator().next();\r
+ Set<DescriptionElementBase> elements = taxonDescription.getElements();\r
+ List<CommonTaxonName> commonNames = new ArrayList<CommonTaxonName>();\r
+ for (DescriptionElementBase element : elements){\r
+ if (element.isInstanceOf(CommonTaxonName.class)){\r
+ commonNames.add((CommonTaxonName)element);\r
+ }\r
+ }\r
+ Assert.assertEquals("Number of common names should be 2", 2, commonNames.size());\r
+ Set<String> commonNameStrings = new HashSet<String>();\r
+ commonNameStrings.add(commonNames.get(0).getName());\r
+ commonNameStrings.add(commonNames.get(1).getName());\r
+ Assert.assertTrue("Common names must include Yellow Underwing", commonNameStrings.contains("Large Sunshine Underwing"));\r
+ Assert.assertTrue("Common names must include Yellow Underwing", commonNameStrings.contains("Yellow Underwing"));\r
+ }\r
+\r
+ @Test\r
+ @DataSet\r
+ public void testDoInvokeXslx() {\r
+ //printDataSet(System.out);\r
+ boolean result = defaultImport.invoke(configuratorXslx).isSuccess();\r
assertTrue("Return value for import.invoke should be true", result);\r
assertEquals("Number of TaxonNames should be 9", 9, nameService.count(null));\r
List<Classification> treeList = classificationService.list(null, null,null,null,null);\r
TaxonNode noctuidaeNode = lepidopteraNode.getChildNodes().iterator().next();\r
TaxonNode noctuaNode = noctuidaeNode.getChildNodes().iterator().next();\r
assertEquals("Number of child nodes of noctuca should be 2", 2, noctuaNode.getChildNodes().size());\r
- \r
+\r
Iterator<TaxonNode> it = noctuaNode.getChildNodes().iterator();\r
TaxonNode childNode1 = it.next();\r
TaxonNode childNode2 = it.next();\r
- \r
+\r
TaxonNode noctuaPronubaNode;\r
if (childNode1.getTaxon().getName().getTitleCache().startsWith("Noctua pronuba")){\r
noctuaPronubaNode = childNode1;\r
}else{\r
noctuaPronubaNode = childNode2;\r
}\r
- \r
+\r
assertEquals("Noctua pronuba taxon name should be ", "Noctua pronuba", noctuaPronubaNode.getTaxon().getName().getTitleCache());\r
Taxon noctuaPronubaTaxon = noctuaPronubaNode.getTaxon();\r
Set<Synonym> synonyms = noctuaPronubaTaxon.getSynonyms();\r
Assert.assertTrue("Common names must include Yellow Underwing", commonNameStrings.contains("Large Sunshine Underwing"));\r
Assert.assertTrue("Common names must include Yellow Underwing", commonNameStrings.contains("Yellow Underwing"));\r
}\r
- \r
+\r
@Test\r
@DataSet(value="NormalExplicitImportTest.testUuid.xml")\r
public void testUUID() throws URISyntaxException{\r
UUID taxonUuid = UUID.fromString("aafce7fe-0c5f-42ed-814b-4c7c2c715660");\r
UUID synonymUuid = UUID.fromString("fc4a995b-37a9-4984-afe6-e352c6c04d92");\r
- \r
- \r
+\r
+\r
//test data set\r
assertEquals("Number of taxon bases should be 2", 2, taxonService.count(null));\r
Taxon taxon = (Taxon)taxonService.find(taxonUuid);\r
Synonym synonym = (Synonym)taxonService.find(synonymUuid);\r
assertNotNull("Synonym with given uuid should exist", synonym);\r
assertEquals("Synonym should have 1 accepted taxon", 1, synonym.getAcceptedTaxa().size());\r
- \r
+\r
//import\r
- boolean result = defaultImport.invoke(uuidConfigurator);\r
+ boolean result = defaultImport.invoke(uuidConfigurator).isSuccess();\r
//test result\r
assertTrue("Return value for import.invoke should be true", result);\r
assertEquals("Number of taxon names should be 2", 2, nameService.count(null));\r
assertEquals("Taxon should have 1 description", 1, taxon.getDescriptions().size());\r
TaxonDescription description = taxon.getDescriptions().iterator().next();\r
assertEquals("Number of description elements should be 2", 2, description.getElements().size());\r
- \r
+\r
String expectedText = "Description for the first taxon";\r
TextData textData = getTextElement(description, expectedText);\r
assertNotNull("The element should exists", textData);\r
DescriptionElementSource source = textData.getSources().iterator().next();\r
Reference<?> ref = source.getCitation();\r
assertNotNull("Citation should not be null", ref);\r
- assertNotNull("AuthorTeam should not be null", ref.getAuthorTeam());\r
- assertEquals("Source author should be 'Meyer et. al.'", "Meyer et. al.",ref.getAuthorTeam().getTitleCache());\r
+ assertNotNull("Authorship should not be null", ref.getAuthorship());\r
+ assertEquals("Source author should be 'Meyer et. al.'", "Meyer et. al.",ref.getAuthorship().getTitleCache());\r
assertEquals("Publication title should be 'My first book'", "My first book", ref.getTitle());\r
assertEquals("Publication year should be '1987'", "1987", ref.getYear());\r
TaxonNameBase<?,?> nameUsedInSource = source.getNameUsedInSource();\r
assertNotNull("Name used in source should not be null", nameUsedInSource);\r
assertEquals("Name used in source title should be ", "Abies", nameUsedInSource.getTitleCache());\r
- \r
- \r
+\r
+\r
//synonym\r
expectedText = "A synonym description";\r
textData = getTextElement(description, expectedText);\r
source = textData.getSources().iterator().next();\r
ref = source.getCitation();\r
assertNotNull("Citation should not be null", ref);\r
- assertNotNull("AuthorTeam should not be null", ref.getAuthorTeam());\r
- assertEquals("Source author should be 'Theys, A.'", "Theys, A.",ref.getAuthorTeam().getTitleCache());\r
+ assertNotNull("Authorship should not be null", ref.getAuthorship());\r
+ assertEquals("Source author should be 'Theys, A.'", "Theys, A.",ref.getAuthorship().getTitleCache());\r
assertEquals("Publication title should be 'The ultimate book'", "The ultimate book", ref.getTitle());\r
assertEquals("Publication year should be '2011'", "2011", ref.getYear());\r
nameUsedInSource = source.getNameUsedInSource();\r
assertNotNull("Name used in source should not be null", nameUsedInSource);\r
assertEquals("Name used in source title should be Pinus", "Pinus", nameUsedInSource.getTitleCache());\r
- \r
+\r
}\r
\r
/**\r
return null;\r
}\r
\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()\r
+ */\r
+ @Override\r
+ public void createTestDataSet() throws FileNotFoundException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
}
\ No newline at end of file