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.excel.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.Ignore;
|
23
|
import org.junit.Test;
|
24
|
import org.unitils.dbunit.annotation.DataSet;
|
25
|
import org.unitils.dbunit.annotation.DataSets;
|
26
|
import org.unitils.dbunit.annotation.ExpectedDataSet;
|
27
|
import org.unitils.spring.annotation.SpringBeanByName;
|
28
|
import org.unitils.spring.annotation.SpringBeanByType;
|
29
|
|
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.name.NomenclaturalCode;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
36
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
37
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
38
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
39
|
|
40
|
/**
|
41
|
* @author a.mueller
|
42
|
* @since 10.05.2011
|
43
|
*/
|
44
|
public class ExcelSpecimenImportExampleTest extends
|
45
|
CdmTransactionalIntegrationTest {
|
46
|
|
47
|
@SpringBeanByName
|
48
|
CdmApplicationAwareDefaultImport<?> defaultImport;
|
49
|
|
50
|
@SpringBeanByType
|
51
|
INameService nameService;
|
52
|
|
53
|
@SpringBeanByType
|
54
|
IOccurrenceService occurrenceService;
|
55
|
|
56
|
private IImportConfigurator configurator;
|
57
|
private IImportConfigurator configuratorXslx;
|
58
|
|
59
|
@Before
|
60
|
public void setUp() {
|
61
|
//xsl
|
62
|
try {
|
63
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xls";
|
64
|
URL url = this.getClass().getResource(inputFile);
|
65
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
66
|
configurator = SpecimenCdmExcelImportConfigurator.NewInstance(url.toURI(), null,false);
|
67
|
configurator.setNomenclaturalCode(NomenclaturalCode.ICNAFP);
|
68
|
assertNotNull("Configurator could not be created", configurator);
|
69
|
} catch (URISyntaxException e) {
|
70
|
e.printStackTrace();
|
71
|
Assert.fail("xsl configurator could not be created");
|
72
|
}
|
73
|
|
74
|
//xslx
|
75
|
try {
|
76
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xlsx";
|
77
|
URL url = this.getClass().getResource(inputFile);
|
78
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
79
|
configuratorXslx = SpecimenCdmExcelImportConfigurator.NewInstance(url.toURI(), null,false);
|
80
|
configuratorXslx.setNomenclaturalCode(NomenclaturalCode.ICNAFP);
|
81
|
assertNotNull("Configurator could not be created", configurator);
|
82
|
} catch (URISyntaxException e) {
|
83
|
e.printStackTrace();
|
84
|
Assert.fail("Xslx configurator could not be created");
|
85
|
}
|
86
|
|
87
|
|
88
|
|
89
|
|
90
|
|
91
|
}
|
92
|
|
93
|
@Test
|
94
|
public void testInit() {
|
95
|
assertNotNull("import instance should not be null", defaultImport);
|
96
|
assertNotNull("nameService should not be null", nameService);
|
97
|
assertNotNull("occurence service should not be null", occurrenceService);
|
98
|
}
|
99
|
|
100
|
|
101
|
@Test
|
102
|
// @Ignore //does not run together with testResultSet or others
|
103
|
@DataSets({
|
104
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
105
|
@DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
106
|
})
|
107
|
public void testDoInvoke() {
|
108
|
boolean result = defaultImport.invoke(configurator).isSuccess();
|
109
|
assertTrue("Return value for import.invoke should be true", result);
|
110
|
assertEquals("Number of specimen should be 3", 3,
|
111
|
occurrenceService.count(DerivedUnit.class));
|
112
|
assertEquals("Number of field units should be 3", 3,
|
113
|
occurrenceService.count(FieldUnit.class));
|
114
|
|
115
|
// printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
|
116
|
}
|
117
|
|
118
|
@Test
|
119
|
// @Ignore //does not run together with testResultSet or others
|
120
|
@DataSets({
|
121
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
122
|
@DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
123
|
})
|
124
|
public void testDoInvokeXslx() {
|
125
|
boolean result = defaultImport.invoke(configurator).isSuccess();
|
126
|
assertTrue("Return value for import.invoke should be true", result);
|
127
|
assertEquals("Number of specimen should be 3", 3,
|
128
|
occurrenceService.count(DerivedUnit.class));
|
129
|
assertEquals("Number of field units should be 3", 3,
|
130
|
occurrenceService.count(FieldUnit.class));
|
131
|
this.rollback();
|
132
|
|
133
|
// printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
|
134
|
}
|
135
|
|
136
|
@Test
|
137
|
@DataSet
|
138
|
@ExpectedDataSet
|
139
|
@Ignore
|
140
|
public void testResultSet() {
|
141
|
boolean result = defaultImport.invoke(configurator).isSuccess();
|
142
|
assertTrue("Return value for import.invoke should be true", result);
|
143
|
assertEquals("Number of specimen should be 3", 3, occurrenceService.count(DerivedUnit.class));
|
144
|
assertEquals("Number of field units should be 3", 3, occurrenceService.count(FieldUnit.class));
|
145
|
|
146
|
// printDataSet(System.out, new String[]{"SpecimenOrObservationBase","DESCRIPTIONELEMENTBASE","DEFINEDTERMBASE"});
|
147
|
//
|
148
|
|
149
|
// try {
|
150
|
// String filePath = System.getProperty("java.io.tmpdir")
|
151
|
// + File.separator + "excelSpecimenOutput.xml";
|
152
|
// File file = new File(filePath);
|
153
|
// FileOutputStream myOut = new FileOutputStream(file);
|
154
|
// System.out.println(file.getAbsolutePath());
|
155
|
// printDataSet(myOut, new String[] { "AgentBase", "Collection",
|
156
|
// "DerivationEvent", "DeterminationEvent",
|
157
|
// "DescriptionElementBase", "DescriptionBase", "Extension",
|
158
|
// "GatheringEvent", "GatheringEvent_DefinedTermBase",
|
159
|
// "LanguageString", "OriginalSourceBase", "Reference",
|
160
|
// "TaxonBase", "TaxonName", "TypeDesignationBase",
|
161
|
// "TaxonName_TypeDesignationBase",
|
162
|
// "SpecimenOrObservationBase", "DefinedTermBase",
|
163
|
// "TermVocabulary", "Representation" });
|
164
|
// // printDataSet(myOut);
|
165
|
// } catch (FileNotFoundException e) {
|
166
|
// Assert.fail(e.getLocalizedMessage());
|
167
|
// }
|
168
|
|
169
|
}
|
170
|
|
171
|
@Override
|
172
|
public void createTestDataSet() throws FileNotFoundException {
|
173
|
// TODO Auto-generated method stub
|
174
|
}
|
175
|
|
176
|
}
|