reintegrate branch patricia into trunk
[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.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;
36
37 /**
38 * @author a.mueller
39 * @created 29.01.2009
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 @SpringBeanByType
56 ICommonService commonService;
57
58
59 private IImportConfigurator configurator;
60 private IImportConfigurator configurator2;
61
62 @Before
63 public void setUp() {
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);
67 try {
68 configurator = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
69 } catch (URISyntaxException e) {
70 e.printStackTrace();
71 Assert.fail();
72 }
73 assertNotNull("Configurator could not be created", configurator);
74
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);
78 try {
79 configurator2 = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
80 } catch (URISyntaxException e) {
81 e.printStackTrace();
82 Assert.fail();
83 }
84 assertNotNull("Configurator2 could not be created", configurator2);
85
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);
89 // try {
90 // configurator3 = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
91 // } catch (URISyntaxException e) {
92 // e.printStackTrace();
93 // Assert.fail();
94 // }
95 // assertNotNull("Configurator3 could not be created", configurator3);
96
97 }
98
99 @Test
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);
107 }
108
109 // @Test
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));
116 // }
117
118 @Test
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));
124 /*<<<<<<< .courant
125 assertEquals("Number of specimen and observation is incorrect", 10, occurrenceService.count(DerivedUnitBase.class));
126 try {
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",
135 });
136 } catch (FileNotFoundException e) {
137 // TODO Auto-generated catch block
138 e.printStackTrace();
139 }
140 =======*/
141 assertEquals("Number of specimen and observation is incorrect", 10, occurrenceService.count(DerivedUnit.class));
142 // try {
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",
151 // });
152 // } catch (FileNotFoundException e) {
153 // // TODO Auto-generated catch block
154 // e.printStackTrace();
155 // }
156 // File file = new File("./ABCDPart1Dataset.xml");
157 // FileOutputStream fos;
158 // try {
159 // fos = new FileOutputStream(file);
160 // printDataSet(fos);
161 // fos.close();
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();
168 // }
169
170 assertEquals("Number of TaxonNames is incorrect", 2, nameService.count(TaxonNameBase.class));
171 assertEquals("Number of specimen is incorrect", 10, occurrenceService.count(DerivedUnit.class));
172
173 }
174 }