Merged the latest changes from the trunk into the branch ui-gwt
[cdmlib.git] / cdmlib-io / src / test / java / eu / etaxonomy / cdm / io / specimen / abcd206 / in / SpecimenImportConfiguratorTest.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.cdm.io.specimen.abcd206.in;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16 import java.io.FileNotFoundException;
17 import java.net.URISyntaxException;
18 import java.net.URL;
19
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;
26
27 import eu.etaxonomy.cdm.api.service.INameService;
28 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
29 import eu.etaxonomy.cdm.api.service.ITermService;
30 import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
31 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
32 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
33 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
34 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
35
36 /**
37 * @author a.mueller
38 * @created 29.01.2009
39 * @version 1.0
40 */
41 public class SpecimenImportConfiguratorTest extends CdmTransactionalIntegrationTest {
42
43 @SpringBeanByName
44 CdmApplicationAwareDefaultImport<?> defaultImport;
45
46 @SpringBeanByType
47 INameService nameService;
48
49 @SpringBeanByType
50 IOccurrenceService occurrenceService;
51
52 @SpringBeanByType
53 ITermService termService;
54
55
56 private IImportConfigurator configurator;
57 private IImportConfigurator configurator2;
58 private IImportConfigurator configurator3;
59
60 @Before
61 public void setUp() {
62 String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/SpecimenImportConfiguratorTest-input.xml";
63 URL url = this.getClass().getResource(inputFile);
64 assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
65 try {
66 configurator = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
67 } catch (URISyntaxException e) {
68 e.printStackTrace();
69 Assert.fail();
70 }
71 assertNotNull("Configurator could not be created", configurator);
72
73 inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/ABCDImportTestCalvumPart1.xml";
74 url = this.getClass().getResource(inputFile);
75 assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
76 try {
77 configurator2 = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
78 } catch (URISyntaxException e) {
79 e.printStackTrace();
80 Assert.fail();
81 }
82 assertNotNull("Configurator2 could not be created", configurator2);
83
84 // inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/ABCDImportTestCalvumPart2.xml";
85 // url = this.getClass().getResource(inputFile);
86 // assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
87 // try {
88 // configurator3 = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
89 // } catch (URISyntaxException e) {
90 // e.printStackTrace();
91 // Assert.fail();
92 // }
93 // assertNotNull("Configurator3 could not be created", configurator3);
94
95 }
96
97 @Test
98 public void testInit() {
99 assertNotNull("import instance should not be null", defaultImport);
100 assertNotNull("nameService should not be null", nameService);
101 assertNotNull("occurence service should not be null", occurrenceService);
102 assertNotNull("term service should not be null", termService);
103 }
104
105 // @Test
106 // @DataSet( value="../../../BlankDataSet.xml") //loadStrategy=CleanSweepInsertLoadStrategy.class
107 // public void testDoInvoke() {
108 // boolean result = defaultImport.invoke(configurator);
109 // assertTrue("Return value for import.invoke should be true", result);
110 // assertEquals("Number of TaxonNames is incorrect", 2, nameService.count(TaxonNameBase.class));
111 // assertEquals("Number of specimen is incorrect", 10, occurrenceService.count(DerivedUnitBase.class));
112 // }
113
114 @Test
115 @DataSet( value="../../../BlankDataSet.xml") //loadStrategy=CleanSweepInsertLoadStrategy.class
116 public void testDoInvoke2() {
117 boolean result = defaultImport.invoke(configurator2);
118 assertTrue("Return value for import.invoke should be true", result);
119 assertEquals("Number of TaxonNames is incorrect", 2, nameService.count(TaxonNameBase.class));
120 assertEquals("Number of specimen and observation is incorrect", 10, occurrenceService.count(DerivedUnitBase.class));
121 try {
122 writeDbUnitDataSetFile(new String[] {
123 "TAXONBASE", "TAXONNAMEBASE",
124 "REFERENCE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONBASE",
125 "AGENTBASE", "CLASSIFICATION", "CLASSIFICATION_TAXONNODE", "TAXONNODE",
126 "HOMOTYPICALGROUP", "LANGUAGESTRING","COLLECTION","SPECIMENOROBSERVATIONBASE",
127 "ORIGINALSOURCEBASE", "GATHERINGEVENT", "DETERMINATIONEVENT",
128 "DERIVATIONEVENT", "SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT",
129 "HIBERNATE_SEQUENCES",
130 });
131 } catch (FileNotFoundException e) {
132 // TODO Auto-generated catch block
133 e.printStackTrace();
134 }
135 // File file = new File("./ABCDPart1Dataset.xml");
136 // FileOutputStream fos;
137 // try {
138 // fos = new FileOutputStream(file);
139 // printDataSet(fos);
140 // fos.close();
141 // } catch (FileNotFoundException e) {
142 // // TODO Auto-generated catch block
143 // e.printStackTrace();
144 // } catch (IOException e) {
145 // // TODO Auto-generated catch block
146 // e.printStackTrace();
147 // }
148
149
150 }
151 }