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
.net
.URISyntaxException
;
19 import org
.junit
.Assert
;
20 import org
.junit
.Before
;
21 import org
.junit
.Ignore
;
22 import org
.junit
.Test
;
23 import org
.unitils
.dbunit
.annotation
.DataSet
;
24 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
25 import org
.unitils
.spring
.annotation
.SpringBeanByName
;
26 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
28 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
30 import eu
.etaxonomy
.cdm
.io
.common
.CdmApplicationAwareDefaultImport
;
31 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
32 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
33 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldObservation
;
35 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
;
58 String inputFile
= "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xls";
59 URL url
= this.getClass().getResource(inputFile
);
60 assertNotNull("URL for the test file '" + inputFile
61 + "' does not exist", url
);
63 configurator
= SpecimenCdmExcelImportConfigurator
.NewInstance(url
.toURI(), null);
64 configurator
.setNomenclaturalCode(NomenclaturalCode
.ICBN
);
65 } catch (URISyntaxException e
) {
69 assertNotNull("Configurator could not be created", configurator
);
73 public void testInit() {
74 assertNotNull("import instance should not be null", defaultImport
);
75 assertNotNull("nameService should not be null", nameService
);
76 assertNotNull("occurence service should not be null", occurrenceService
);
82 public void testDoInvoke() {
83 boolean result
= defaultImport
.invoke(configurator
);
84 assertTrue("Return value for import.invoke should be true", result
);
85 assertEquals("Number of specimen should be 3", 3,
86 occurrenceService
.count(DerivedUnitBase
.class));
87 assertEquals("Number of field observations should be 3", 3,
88 occurrenceService
.count(FieldObservation
.class));
90 printDataSet(System
.out
, new String
[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
98 public void testResultSet() {
99 boolean result
= defaultImport
.invoke(configurator
);
100 assertTrue("Return value for import.invoke should be true", result
);
101 assertEquals("Number of specimen should be 3", 3, occurrenceService
.count(DerivedUnitBase
.class));
102 assertEquals("Number of field observations should be 3", 3, occurrenceService
.count(FieldObservation
.class));
105 // String filePath = System.getProperty("java.io.tmpdir")
106 // + File.separator + "excelSpecimenOutput.xml";
107 // File file = new File(filePath);
108 // FileOutputStream myOut = new FileOutputStream(file);
109 // System.out.println(file.getAbsolutePath());
110 // printDataSet(myOut, new String[] { "AgentBase", "Collection",
111 // "DerivationEvent", "DeterminationEvent",
112 // "DescriptionElementBase", "DescriptionBase", "Extension",
113 // "GatheringEvent", "GatheringEvent_DefinedTermBase",
114 // "LanguageString", "OriginalSourceBase", "Reference",
115 // "TaxonBase", "TaxonNameBase", "TypeDesignationBase",
116 // "TaxonNameBase_TypeDesignationBase",
117 // "SpecimenOrObservationBase", "DefinedTermBase",
118 // "TermVocabulary", "Representation" });
119 // // printDataSet(myOut);
120 // } catch (FileNotFoundException e) {
121 // Assert.fail(e.getLocalizedMessage());