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