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
.abcd206
.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
.Test
;
23 import org
.unitils
.dbunit
.annotation
.DataSet
;
24 import org
.unitils
.spring
.annotation
.SpringBeanByName
;
25 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
27 import eu
.etaxonomy
.cdm
.api
.service
.ICommonService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
31 import eu
.etaxonomy
.cdm
.io
.common
.CdmApplicationAwareDefaultImport
;
32 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
35 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
41 public class SpecimenImportConfiguratorTest
extends CdmTransactionalIntegrationTest
{
44 CdmApplicationAwareDefaultImport
<?
> defaultImport
;
47 INameService nameService
;
50 IOccurrenceService occurrenceService
;
53 ITermService termService
;
56 ICommonService commonService
;
59 private IImportConfigurator configurator
;
60 private IImportConfigurator configurator2
;
64 String inputFile
= "/eu/etaxonomy/cdm/io/specimen/abcd206/in/SpecimenImportConfiguratorTest-input.xml";
65 URL url
= this.getClass().getResource(inputFile
);
66 assertNotNull("URL for the test file '" + inputFile
+ "' does not exist", url
);
68 configurator
= Abcd206ImportConfigurator
.NewInstance(url
.toURI(), null,false);
69 } catch (URISyntaxException e
) {
73 assertNotNull("Configurator could not be created", configurator
);
75 inputFile
= "/eu/etaxonomy/cdm/io/specimen/abcd206/in/ABCDImportTestCalvumPart1.xml";
76 url
= this.getClass().getResource(inputFile
);
77 assertNotNull("URL for the test file '" + inputFile
+ "' does not exist", url
);
79 configurator2
= Abcd206ImportConfigurator
.NewInstance(url
.toURI(), null,false);
80 } catch (URISyntaxException e
) {
84 assertNotNull("Configurator2 could not be created", configurator2
);
86 // inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/ABCDImportTestCalvumPart2.xml";
87 // url = this.getClass().getResource(inputFile);
88 // assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
90 // configurator3 = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
91 // } catch (URISyntaxException e) {
92 // e.printStackTrace();
95 // assertNotNull("Configurator3 could not be created", configurator3);
100 public void testInit() {
101 System
.out
.println("TEST INIT");
102 assertNotNull("import instance should not be null", defaultImport
);
103 assertNotNull("nameService should not be null", nameService
);
104 assertNotNull("occurence service should not be null", occurrenceService
);
105 assertNotNull("term service should not be null", termService
);
106 assertNotNull("common service should not be null", commonService
);
110 // @DataSet( value="../../../BlankDataSet.xml") //loadStrategy=CleanSweepInsertLoadStrategy.class
111 // public void testDoInvoke() {
112 // boolean result = defaultImport.invoke(configurator);
113 // assertTrue("Return value for import.invoke should be true", result);
114 // assertEquals("Number of TaxonNames is incorrect", 2, nameService.count(TaxonNameBase.class));
115 // assertEquals("Number of specimen is incorrect", 10, occurrenceService.count(DerivedUnitBase.class));
119 @DataSet( value
="../../../BlankDataSet.xml") //loadStrategy=CleanSweepInsertLoadStrategy.class
120 public void testDoInvoke2() {
121 boolean result
= defaultImport
.invoke(configurator2
);
122 assertTrue("Return value for import.invoke should be true", result
);
123 assertEquals("Number of TaxonNames is incorrect", 2, nameService
.count(TaxonNameBase
.class));
125 assertEquals("Number of specimen and observation is incorrect", 10, occurrenceService.count(DerivedUnitBase.class));
127 writeDbUnitDataSetFile(new String[] {
128 "TAXONBASE", "TAXONNAMEBASE",
129 "REFERENCE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONBASE",
130 "AGENTBASE", "CLASSIFICATION", "CLASSIFICATION_TAXONNODE", "TAXONNODE",
131 "HOMOTYPICALGROUP", "LANGUAGESTRING","COLLECTION","SPECIMENOROBSERVATIONBASE",
132 "ORIGINALSOURCEBASE", "GATHERINGEVENT", "DETERMINATIONEVENT",
133 "DERIVATIONEVENT", "SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT","GATHERINGEVENT",
134 "HIBERNATE_SEQUENCES",
136 } catch (FileNotFoundException e) {
137 // TODO Auto-generated catch block
141 assertEquals("Number of specimen and observation is incorrect", 10, occurrenceService
.count(DerivedUnit
.class));
143 // writeDbUnitDataSetFile(new String[] {
144 // "TAXONBASE", "TAXONNAMEBASE",
145 // "REFERENCE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONBASE",
146 // "AGENTBASE", "CLASSIFICATION", "CLASSIFICATION_TAXONNODE", "TAXONNODE",
147 // "HOMOTYPICALGROUP", "LANGUAGESTRING","COLLECTION","SPECIMENOROBSERVATIONBASE",
148 // "ORIGINALSOURCEBASE", "GATHERINGEVENT", "DETERMINATIONEVENT",
149 // "DERIVATIONEVENT", "SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT",
150 // "HIBERNATE_SEQUENCES",
152 // } catch (FileNotFoundException e) {
153 // // TODO Auto-generated catch block
154 // e.printStackTrace();
156 // File file = new File("./ABCDPart1Dataset.xml");
157 // FileOutputStream fos;
159 // fos = new FileOutputStream(file);
160 // printDataSet(fos);
162 // } catch (FileNotFoundException e) {
163 // // TODO Auto-generated catch block
164 // e.printStackTrace();
165 // } catch (IOException e) {
166 // // TODO Auto-generated catch block
167 // e.printStackTrace();
170 assertEquals("Number of TaxonNames is incorrect", 2, nameService
.count(TaxonNameBase
.class));
171 assertEquals("Number of specimen is incorrect", 10, occurrenceService
.count(DerivedUnit
.class));