Project

General

Profile

Download (6.53 KB) Statistics
| Branch: | Tag: | Revision:
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
package eu.etaxonomy.cdm.io.specimen.excel.in;
10

    
11
import static org.junit.Assert.assertEquals;
12
import static org.junit.Assert.assertNotNull;
13
import static org.junit.Assert.assertTrue;
14

    
15
import java.io.FileNotFoundException;
16
import java.net.URISyntaxException;
17
import java.net.URL;
18

    
19
import org.junit.Assert;
20
import org.junit.Before;
21
import org.junit.Ignore;
22
import org.junit.Test;
23
import org.unitils.dbunit.annotation.DataSet;
24
import org.unitils.dbunit.annotation.DataSets;
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.common.URI;
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
	private CdmApplicationAwareDefaultImport<?> defaultImport;
49

    
50
	@SpringBeanByType
51
	private INameService nameService;
52

    
53
	@SpringBeanByType
54
	private 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(URI.fromUrl(url), 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(URI.fromUrl(url), 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
	@Test
89
	public void testInit() {
90
		assertNotNull("import instance should not be null", defaultImport);
91
		assertNotNull("nameService should not be null", nameService);
92
		assertNotNull("occurence service should not be null", occurrenceService);
93
	}
94

    
95
	 @Test
96
//	 @Ignore  //does not run together with testResultSet or others
97
	 @DataSets({
98
	     @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
99
	     @DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
100
	 })
101
	 public void testDoInvoke() {
102
		 boolean result = defaultImport.invoke(configurator).isSuccess();
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
	 @DataSets({
115
	     @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
116
	     @DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
117
	 })
118
	 public void testDoInvokeXslx() {
119
		 boolean result = defaultImport.invoke(configurator).isSuccess();
120
		 assertTrue("Return value for import.invoke should be true", result);
121
		 assertEquals("Number of specimen should be 3", 3,
122
		 occurrenceService.count(DerivedUnit.class));
123
		 assertEquals("Number of field units should be 3", 3,
124
		 occurrenceService.count(FieldUnit.class));
125
		 this.rollback();
126

    
127
//		 printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
128
	 }
129

    
130
	@Test
131
	@DataSet
132
	@ExpectedDataSet
133
	@Ignore
134
	public void testResultSet() {
135
		boolean result = defaultImport.invoke(configurator).isSuccess();
136
		assertTrue("Return value for import.invoke should be true", result);
137
		assertEquals("Number of specimen should be 3", 3, occurrenceService.count(DerivedUnit.class));
138
		assertEquals("Number of field units should be 3", 3, occurrenceService.count(FieldUnit.class));
139

    
140
//		printDataSet(System.out, new String[]{"SpecimenOrObservationBase","DESCRIPTIONELEMENTBASE","DEFINEDTERMBASE"});
141
//
142

    
143
//		try {
144
//			String filePath = System.getProperty("java.io.tmpdir")
145
//					+ File.separator + "excelSpecimenOutput.xml";
146
//			File file = new File(filePath);
147
//			FileOutputStream myOut = new FileOutputStream(file);
148
//			System.out.println(file.getAbsolutePath());
149
//			printDataSet(myOut, new String[] { "AgentBase", "Collection",
150
//					"DerivationEvent", "DeterminationEvent",
151
//					"DescriptionElementBase", "DescriptionBase", "Extension",
152
//					"GatheringEvent", "GatheringEvent_DefinedTermBase",
153
//					"LanguageString", "OriginalSourceBase", "Reference",
154
//					"TaxonBase", "TaxonName", "TypeDesignationBase",
155
//					"TaxonName_TypeDesignationBase",
156
//					"SpecimenOrObservationBase", "DefinedTermBase",
157
//					"TermVocabulary", "Representation" });
158
//			// printDataSet(myOut);
159
//		} catch (FileNotFoundException e) {
160
//			Assert.fail(e.getLocalizedMessage());
161
//		}
162
	}
163

    
164
    @Override
165
    public void createTestDataSet() throws FileNotFoundException {}
166
}
(2-2/2)