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
;
17 import java
.io
.FileNotFoundException
;
18 import java
.io
.FileOutputStream
;
19 import java
.net
.URISyntaxException
;
22 import org
.junit
.Assert
;
23 import org
.junit
.Before
;
24 import org
.junit
.Ignore
;
25 import org
.junit
.Test
;
26 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
27 import org
.unitils
.spring
.annotation
.SpringBeanByName
;
28 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
30 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
32 import eu
.etaxonomy
.cdm
.io
.common
.CdmApplicationAwareDefaultImport
;
33 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldObservation
;
36 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
43 //@Ignore //currently jenkins throws an exception
44 public class ExcelSpecimenImportExampleTest
extends CdmTransactionalIntegrationTest
{
47 CdmApplicationAwareDefaultImport
<?
> defaultImport
;
50 INameService nameService
;
53 IOccurrenceService occurrenceService
;
56 private IImportConfigurator configurator
;
60 String inputFile
= "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xls";
61 URL url
= this.getClass().getResource(inputFile
);
62 assertNotNull("URL for the test file '" + inputFile
+ "' does not exist", url
);
64 configurator
= SpecimenCdmExcelImportConfigurator
.NewInstance(url
.toURI(), null);
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
);
80 // public void testDoInvoke() {
81 // boolean result = defaultImport.invoke(configurator);
82 // assertTrue("Return value for import.invoke should be true", result);
83 // assertEquals("Number of specimen should be 3", 3, occurrenceService.count(DerivedUnitBase.class));
84 // assertEquals("Number of field observations should be 3", 3, occurrenceService.count(FieldObservation.class));
86 //// printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
92 public void testResultSet() {
93 boolean result
= defaultImport
.invoke(configurator
);
94 assertTrue("Return value for import.invoke should be true", result
);
95 assertEquals("Number of specimen should be 3", 3, occurrenceService
.count(DerivedUnitBase
.class));
96 assertEquals("Number of field observations should be 3", 3, occurrenceService
.count(FieldObservation
.class));
99 String filePath
= System
.getProperty("java.io.tmpdir")+File
.separator
+"excelSpecimenOutput.xml";
100 File file
= new File(filePath
);
101 FileOutputStream myOut
= new FileOutputStream(file
);
102 System
.out
.println(file
.getAbsolutePath());
103 printDataSet(myOut
, new String
[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
104 } catch (FileNotFoundException e
) {
105 // TODO Auto-generated catch block