import java.util.Iterator;\r
import java.util.List;\r
import java.util.Set;\r
-\r
-import junit.framework.Assert;\r
+import java.util.UUID;\r
\r
import org.apache.log4j.Logger;\r
+import org.junit.Assert;\r
import org.junit.Before;\r
-import org.junit.Ignore;\r
import org.junit.Test;\r
import org.unitils.dbunit.annotation.DataSet;\r
import org.unitils.spring.annotation.SpringBeanByName;\r
import org.unitils.spring.annotation.SpringBeanByType;\r
\r
+import eu.etaxonomy.cdm.api.service.IClassificationService;\r
import eu.etaxonomy.cdm.api.service.INameService;\r
import eu.etaxonomy.cdm.api.service.ITaxonService;\r
-import eu.etaxonomy.cdm.api.service.ITaxonTreeService;\r
+import eu.etaxonomy.cdm.api.service.ITermService;\r
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;\r
import eu.etaxonomy.cdm.io.common.IImportConfigurator;\r
+import eu.etaxonomy.cdm.model.common.CdmBase;\r
+import eu.etaxonomy.cdm.model.common.DescriptionElementSource;\r
+import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.common.LanguageString;\r
import eu.etaxonomy.cdm.model.description.CommonTaxonName;\r
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
+import eu.etaxonomy.cdm.model.description.Feature;\r
import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
+import eu.etaxonomy.cdm.model.description.TextData;\r
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;\r
import eu.etaxonomy.cdm.model.name.NonViralName;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
+import eu.etaxonomy.cdm.model.reference.Reference;\r
+import eu.etaxonomy.cdm.model.taxon.Classification;\r
import eu.etaxonomy.cdm.model.taxon.Synonym;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;\r
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;\r
\r
/**\r
private static final Logger logger = Logger.getLogger(NormalExplicitImportTest.class);\r
\r
@SpringBeanByName\r
- CdmApplicationAwareDefaultImport defaultImport;\r
+ CdmApplicationAwareDefaultImport<?> defaultImport;\r
\r
@SpringBeanByType\r
INameService nameService;\r
ITaxonService taxonService;\r
\r
@SpringBeanByType\r
- ITaxonTreeService taxonTreeService;\r
+ ITermService termService;\r
+ \r
+ @SpringBeanByType\r
+ IClassificationService classificationService;\r
\r
private IImportConfigurator configurator;\r
+ private IImportConfigurator uuidConfigurator;\r
\r
@Before\r
public void setUp() throws URISyntaxException {\r
String inputFile = "/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImportTest-input.xls";\r
URL url = this.getClass().getResource(inputFile);\r
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);\r
- configurator = NormalExplicitImportConfigurator.NewInstance(url.toURI(), null, NomenclaturalCode.ICBN);\r
+ configurator = NormalExplicitImportConfigurator.NewInstance(url.toURI(), null, NomenclaturalCode.ICBN, null);\r
+ assertNotNull("Configurator could not be created", configurator);\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.ICBN, null);\r
assertNotNull("Configurator could not be created", configurator);\r
+ \r
}\r
\r
@Test\r
\r
@Test\r
@DataSet\r
- @Ignore //does run standalone, but not in suite (maven)\r
public void testDoInvoke() {\r
//printDataSet(System.out);\r
boolean result = defaultImport.invoke(configurator);\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<TaxonomicTree> treeList = taxonTreeService.list(null, null,null,null,null);\r
- assertEquals("Number of taxonomic trees should be 1", 1, treeList.size());\r
- TaxonomicTree tree = treeList.get(0);\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
Set<TaxonNode> rootNodes = tree.getChildNodes();\r
assertEquals("Number of root nodes should be 1", 1, rootNodes.size());\r
TaxonNode rootNode = rootNodes.iterator().next();\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
+ 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
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
+ //test data set\r
+ assertEquals("Number of taxon bases should be 2", 2, taxonService.count(null));\r
+ Taxon taxon = (Taxon)taxonService.find(taxonUuid);\r
+ assertNotNull("Taxon with given uuid should exist", taxon);\r
+ assertEquals("Taxon should have no description", 0, taxon.getDescriptions().size());\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
+ //import\r
+ boolean result = defaultImport.invoke(uuidConfigurator);\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("Number of taxa should be 2", 2, taxonService.count(null));\r
+ taxon = (Taxon)taxonService.find(taxonUuid);\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
+ String expectedText = "Description for the first taxon";\r
+ TextData textData = getTextElement(description, expectedText);\r
+ assertNotNull("The element should exists", textData);\r
+ Feature feature = textData.getFeature();\r
+ assertEquals("Unexpected feature", Feature.DESCRIPTION(), feature);\r
+ assertEquals("There should be exactly 1 language", 1,textData.getMultilanguageText().size());\r
+ Language language = textData.getMultilanguageText().keySet().iterator().next();\r
+ assertEquals("Language should be German", Language.GERMAN(), language);\r
+ String text = textData.getText(language);\r
+ assertEquals("Unexpected description text", expectedText, text);\r
+ assertEquals("Number of source elements should be 1", 1, textData.getSources().size());\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
+ 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
+ //synonym\r
+ expectedText = "A synonym description";\r
+ textData = getTextElement(description, expectedText);\r
+ assertNotNull("The element should exists", textData);\r
+ feature = textData.getFeature();\r
+ assertEquals("Unexpected feature", Feature.DESCRIPTION(), feature);\r
+ assertEquals("There should be exactly 1 language", 1,textData.getMultilanguageText().size());\r
+ language = textData.getMultilanguageText().keySet().iterator().next();\r
+ assertEquals("Language should be Spanish", Language.SPANISH_CASTILIAN(), language);\r
+ text = textData.getText(language);\r
+ assertEquals("Unexpected description text", expectedText, text);\r
+ assertEquals("Number of source elements should be 1", 1, textData.getSources().size());\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
+ 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
+ * Returns description element for record id 1\r
+ * @param description\r
+ * @return\r
+ */\r
+ private TextData getTextElement(TaxonDescription description, String descriptionText) {\r
+ for (DescriptionElementBase element : description.getElements()){\r
+ if (element.isInstanceOf(TextData.class)){\r
+ TextData textData = CdmBase.deproxy(element, TextData.class);\r
+ for (LanguageString ls :textData.getMultilanguageText().values()){\r
+ if (ls.getText().equals(descriptionText)){\r
+ return textData;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+}
\ No newline at end of file