Refactored import return type from boolean to ImportResult
[cdmlib.git] / cdmlib-io / src / test / java / eu / etaxonomy / cdm / io / specimen / excel / in / ExcelSpecimenImportExampleTest.java
index 05b9972bf18982946a6fb3b8578e79abe551e294..208d3bf082845ae526722712e3f81c72132eba11 100644 (file)
@@ -1,11 +1,11 @@
 /**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\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
+ * Copyright (C) 2007 EDIT\r
+ * European Distributed Institute of Taxonomy\r
+ * http://www.e-taxonomy.eu\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
 \r
 package eu.etaxonomy.cdm.io.specimen.excel.in;\r
 \r
@@ -13,11 +13,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;\r
 import static org.junit.Assert.assertTrue;\r
 \r
-import java.io.File;\r
 import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.OutputStreamWriter;\r
-import java.io.UnsupportedEncodingException;\r
 import java.net.URISyntaxException;\r
 import java.net.URL;\r
 \r
@@ -25,6 +21,8 @@ import org.junit.Assert;
 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.dbunit.annotation.DataSets;\r
 import org.unitils.dbunit.annotation.ExpectedDataSet;\r
 import org.unitils.spring.annotation.SpringBeanByName;\r
 import org.unitils.spring.annotation.SpringBeanByType;\r
@@ -33,18 +31,19 @@ import eu.etaxonomy.cdm.api.service.INameService;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
 import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;\r
 import eu.etaxonomy.cdm.io.common.IImportConfigurator;\r
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;\r
-import eu.etaxonomy.cdm.model.occurrence.FieldObservation;\r
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;\r
 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;\r
+import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;\r
 \r
 /**\r
  * @author a.mueller\r
  * @created 10.05.2011\r
- * @version 1.0\r
  */\r
-//@Ignore\r
-public class ExcelSpecimenImportExampleTest extends CdmTransactionalIntegrationTest {\r
-       \r
+public class ExcelSpecimenImportExampleTest extends\r
+               CdmTransactionalIntegrationTest {\r
+\r
        @SpringBeanByName\r
        CdmApplicationAwareDefaultImport<?> defaultImport;\r
 \r
@@ -54,60 +53,124 @@ public class ExcelSpecimenImportExampleTest extends CdmTransactionalIntegrationT
        @SpringBeanByType\r
        IOccurrenceService occurrenceService;\r
 \r
-       \r
        private IImportConfigurator configurator;\r
-       \r
+       private IImportConfigurator configuratorXslx;\r
+\r
        @Before\r
        public void setUp() {\r
-               String inputFile = "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xls";\r
-               URL url = this.getClass().getResource(inputFile);\r
-               assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);\r
+               //xsl\r
+               try {\r
+                       String inputFile = "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xls";\r
+                       URL url = this.getClass().getResource(inputFile);\r
+                       assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);\r
+                       configurator = SpecimenCdmExcelImportConfigurator.NewInstance(url.toURI(), null,false);\r
+                       configurator.setNomenclaturalCode(NomenclaturalCode.ICNAFP);\r
+                       assertNotNull("Configurator could not be created", configurator);\r
+               } catch (URISyntaxException e) {\r
+                       e.printStackTrace();\r
+                       Assert.fail("xsl configurator could not be created");\r
+               }\r
+\r
+               //xslx\r
                try {\r
-                       configurator = SpecimenCdmExcelImportConfigurator.NewInstance(url.toURI(), null);\r
+                       String inputFile = "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xlsx";\r
+                       URL url = this.getClass().getResource(inputFile);\r
+                       assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);\r
+                       configuratorXslx = SpecimenCdmExcelImportConfigurator.NewInstance(url.toURI(), null,false);\r
+                       configuratorXslx.setNomenclaturalCode(NomenclaturalCode.ICNAFP);\r
+                       assertNotNull("Configurator could not be created", configurator);\r
                } catch (URISyntaxException e) {\r
                        e.printStackTrace();\r
-                       Assert.fail();\r
+                       Assert.fail("Xslx configurator could not be created");\r
                }\r
-               assertNotNull("Configurator could not be created", configurator);\r
+\r
+\r
+\r
+\r
+\r
        }\r
-       \r
+\r
        @Test\r
        public void testInit() {\r
                assertNotNull("import instance should not be null", defaultImport);\r
                assertNotNull("nameService should not be null", nameService);\r
                assertNotNull("occurence service should not be null", occurrenceService);\r
        }\r
-//     \r
-//     @Test\r
-//     public void testDoInvoke() {\r
-//             boolean result = defaultImport.invoke(configurator);\r
-//             assertTrue("Return value for import.invoke should be true", result);\r
-//             assertEquals("Number of specimen should be 3", 3, occurrenceService.count(DerivedUnitBase.class));\r
-//             assertEquals("Number of field observations should be 3", 3, occurrenceService.count(FieldObservation.class));\r
-//                     \r
-////           printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});\r
-//             \r
-//     }\r
-       \r
+\r
+\r
+        @Test\r
+//      @Ignore  //does not run together with testResultSet or others\r
+        @DataSets({\r
+            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="../../../ClearDB_with_Terms_DataSet.xml"),\r
+            @DataSet("../../../TermsDataSet-with_auditing_info.xml")\r
+        })\r
+        public void testDoInvoke() {\r
+                boolean result = defaultImport.invoke(configurator).isSuccess();\r
+                assertTrue("Return value for import.invoke should be true", result);\r
+                assertEquals("Number of specimen should be 3", 3,\r
+                occurrenceService.count(DerivedUnit.class));\r
+                assertEquals("Number of field units should be 3", 3,\r
+                occurrenceService.count(FieldUnit.class));\r
+\r
+//              printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});\r
+        }\r
+\r
+        @Test\r
+//      @Ignore //does not run together with testResultSet or others\r
+        @DataSets({\r
+            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="../../../ClearDB_with_Terms_DataSet.xml"),\r
+            @DataSet("../../../TermsDataSet-with_auditing_info.xml")\r
+        })\r
+        public void testDoInvokeXslx() {\r
+                boolean result = defaultImport.invoke(configurator).isSuccess();\r
+                assertTrue("Return value for import.invoke should be true", result);\r
+                assertEquals("Number of specimen should be 3", 3,\r
+                occurrenceService.count(DerivedUnit.class));\r
+                assertEquals("Number of field units should be 3", 3,\r
+                occurrenceService.count(FieldUnit.class));\r
+                this.rollback();\r
+\r
+//              printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});\r
+        }\r
+\r
        @Test\r
+       @DataSet\r
        @ExpectedDataSet\r
+       @Ignore\r
        public void testResultSet() {\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 specimen should be 3", 3, occurrenceService.count(DerivedUnitBase.class));\r
-               assertEquals("Number of field observations should be 3", 3, occurrenceService.count(FieldObservation.class));\r
-               \r
-               try {\r
-                       String filePath = System.getProperty("java.io.tmpdir")+File.separator+"excelSpecimenOutput.xml";\r
-                       File file = new File(filePath);\r
-                       FileOutputStream myOut = new FileOutputStream(file);\r
-                       System.out.println(file.getAbsolutePath());\r
-                       printDataSet(myOut, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});\r
-               } catch (FileNotFoundException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               }\r
-               \r
+               assertEquals("Number of specimen should be 3", 3, occurrenceService.count(DerivedUnit.class));\r
+               assertEquals("Number of field units should be 3", 3, occurrenceService.count(FieldUnit.class));\r
+\r
+//             printDataSet(System.out, new String[]{"SpecimenOrObservationBase","DESCRIPTIONELEMENTBASE","DEFINEDTERMBASE"});\r
+//\r
+\r
+//             try {\r
+//                     String filePath = System.getProperty("java.io.tmpdir")\r
+//                                     + File.separator + "excelSpecimenOutput.xml";\r
+//                     File file = new File(filePath);\r
+//                     FileOutputStream myOut = new FileOutputStream(file);\r
+//                     System.out.println(file.getAbsolutePath());\r
+//                     printDataSet(myOut, new String[] { "AgentBase", "Collection",\r
+//                                     "DerivationEvent", "DeterminationEvent",\r
+//                                     "DescriptionElementBase", "DescriptionBase", "Extension",\r
+//                                     "GatheringEvent", "GatheringEvent_DefinedTermBase",\r
+//                                     "LanguageString", "OriginalSourceBase", "Reference",\r
+//                                     "TaxonBase", "TaxonNameBase", "TypeDesignationBase",\r
+//                                     "TaxonNameBase_TypeDesignationBase",\r
+//                                     "SpecimenOrObservationBase", "DefinedTermBase",\r
+//                                     "TermVocabulary", "Representation" });\r
+//                     // printDataSet(myOut);\r
+//             } catch (FileNotFoundException e) {\r
+//                     Assert.fail(e.getLocalizedMessage());\r
+//             }\r
+\r
        }\r
 \r
+    @Override\r
+    public void createTestDataSet() throws FileNotFoundException {\r
+        // TODO Auto-generated method stub\r
+    }\r
+\r
 }\r