2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.specimen
.excel
.in
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertTrue
;
16 import java
.io
.FileNotFoundException
;
17 import java
.net
.URISyntaxException
;
20 import org
.junit
.Assert
;
21 import org
.junit
.Before
;
22 import org
.junit
.Ignore
;
23 import org
.junit
.Test
;
24 import org
.unitils
.dbunit
.annotation
.DataSet
;
25 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
26 import org
.unitils
.spring
.annotation
.SpringBeanByName
;
27 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
29 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
31 import eu
.etaxonomy
.cdm
.io
.common
.CdmApplicationAwareDefaultImport
;
32 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
33 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
36 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
42 public class ExcelSpecimenImportExampleTest
extends
43 CdmTransactionalIntegrationTest
{
46 CdmApplicationAwareDefaultImport
<?
> defaultImport
;
49 INameService nameService
;
52 IOccurrenceService occurrenceService
;
54 private IImportConfigurator configurator
;
55 private IImportConfigurator configuratorXslx
;
61 String inputFile
= "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xls";
62 URL url
= this.getClass().getResource(inputFile
);
63 assertNotNull("URL for the test file '" + inputFile
+ "' does not exist", url
);
64 configurator
= SpecimenCdmExcelImportConfigurator
.NewInstance(url
.toURI(), null,false);
65 configurator
.setNomenclaturalCode(NomenclaturalCode
.ICNAFP
);
66 assertNotNull("Configurator could not be created", configurator
);
67 } catch (URISyntaxException e
) {
69 Assert
.fail("xsl configurator could not be created");
74 String inputFile
= "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xlsx";
75 URL url
= this.getClass().getResource(inputFile
);
76 assertNotNull("URL for the test file '" + inputFile
+ "' does not exist", url
);
77 configuratorXslx
= SpecimenCdmExcelImportConfigurator
.NewInstance(url
.toURI(), null,false);
78 configuratorXslx
.setNomenclaturalCode(NomenclaturalCode
.ICNAFP
);
79 assertNotNull("Configurator could not be created", configurator
);
80 } catch (URISyntaxException e
) {
82 Assert
.fail("Xslx configurator could not be created");
92 public void testInit() {
93 assertNotNull("import instance should not be null", defaultImport
);
94 assertNotNull("nameService should not be null", nameService
);
95 assertNotNull("occurence service should not be null", occurrenceService
);
100 @Ignore //does not run together with testResultSet or others
101 public void testDoInvoke() {
102 boolean result
= defaultImport
.invoke(configurator
);
103 assertTrue("Return value for import.invoke should be true", result
);
104 assertEquals("Number of specimen should be 3", 3,
105 occurrenceService
.count(DerivedUnit
.class));
106 assertEquals("Number of field units should be 3", 3,
107 occurrenceService
.count(FieldUnit
.class));
109 // printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
113 @Ignore //does not run together with testResultSet or others
114 public void testDoInvokeXslx() {
115 boolean result
= defaultImport
.invoke(configurator
);
116 assertTrue("Return value for import.invoke should be true", result
);
117 assertEquals("Number of specimen should be 3", 3,
118 occurrenceService
.count(DerivedUnit
.class));
119 assertEquals("Number of field units should be 3", 3,
120 occurrenceService
.count(FieldUnit
.class));
123 // printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
130 public void testResultSet() {
131 boolean result
= defaultImport
.invoke(configurator
);
132 assertTrue("Return value for import.invoke should be true", result
);
133 assertEquals("Number of specimen should be 3", 3, occurrenceService
.count(DerivedUnit
.class));
134 assertEquals("Number of field units should be 3", 3, occurrenceService
.count(FieldUnit
.class));
137 // String filePath = System.getProperty("java.io.tmpdir")
138 // + File.separator + "excelSpecimenOutput.xml";
139 // File file = new File(filePath);
140 // FileOutputStream myOut = new FileOutputStream(file);
141 // System.out.println(file.getAbsolutePath());
142 // printDataSet(myOut, new String[] { "AgentBase", "Collection",
143 // "DerivationEvent", "DeterminationEvent",
144 // "DescriptionElementBase", "DescriptionBase", "Extension",
145 // "GatheringEvent", "GatheringEvent_DefinedTermBase",
146 // "LanguageString", "OriginalSourceBase", "Reference",
147 // "TaxonBase", "TaxonNameBase", "TypeDesignationBase",
148 // "TaxonNameBase_TypeDesignationBase",
149 // "SpecimenOrObservationBase", "DefinedTermBase",
150 // "TermVocabulary", "Representation" });
151 // // printDataSet(myOut);
152 // } catch (FileNotFoundException e) {
153 // Assert.fail(e.getLocalizedMessage());
159 public void createTestDataSet() throws FileNotFoundException
{
160 // TODO Auto-generated method stub