merged with trunk
[cdmlib.git] / cdmlib-io / src / test / java / eu / etaxonomy / cdm / io / specimen / excel / in / ExcelSpecimenImportExampleTest.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.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.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.ExpectedDataSet;
25 import org.unitils.spring.annotation.SpringBeanByName;
26 import org.unitils.spring.annotation.SpringBeanByType;
27
28 import eu.etaxonomy.cdm.api.service.INameService;
29 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
30 import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
31 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
32 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
33 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
34 import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
35 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
36
37 /**
38 * @author a.mueller
39 * @created 10.05.2011
40 * @version 1.0
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
56 @Before
57 public void setUp() {
58 String inputFile = "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xls";
59 URL url = this.getClass().getResource(inputFile);
60 assertNotNull("URL for the test file '" + inputFile
61 + "' does not exist", url);
62 try {
63 configurator = SpecimenCdmExcelImportConfigurator.NewInstance(url.toURI(), null,false);
64 configurator.setNomenclaturalCode(NomenclaturalCode.ICBN);
65 } catch (URISyntaxException e) {
66 e.printStackTrace();
67 Assert.fail();
68 }
69 assertNotNull("Configurator could not be created", configurator);
70 }
71
72 @Test
73 public void testInit() {
74 assertNotNull("import instance should not be null", defaultImport);
75 assertNotNull("nameService should not be null", nameService);
76 assertNotNull("occurence service should not be null", occurrenceService);
77 }
78
79
80 @Test
81 @Ignore
82 public void testDoInvoke() {
83 boolean result = defaultImport.invoke(configurator);
84 assertTrue("Return value for import.invoke should be true", result);
85 assertEquals("Number of specimen should be 3", 3,
86 occurrenceService.count(DerivedUnitBase.class));
87 assertEquals("Number of field observations should be 3", 3,
88 occurrenceService.count(FieldObservation.class));
89
90 printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
91
92 }
93
94 @Test
95 @DataSet
96 @ExpectedDataSet
97 // @Ignore
98 public void testResultSet() {
99 boolean result = defaultImport.invoke(configurator);
100 assertTrue("Return value for import.invoke should be true", result);
101 assertEquals("Number of specimen should be 3", 3, occurrenceService.count(DerivedUnitBase.class));
102 assertEquals("Number of field observations should be 3", 3, occurrenceService.count(FieldObservation.class));
103
104 // try {
105 // String filePath = System.getProperty("java.io.tmpdir")
106 // + File.separator + "excelSpecimenOutput.xml";
107 // File file = new File(filePath);
108 // FileOutputStream myOut = new FileOutputStream(file);
109 // System.out.println(file.getAbsolutePath());
110 // printDataSet(myOut, new String[] { "AgentBase", "Collection",
111 // "DerivationEvent", "DeterminationEvent",
112 // "DescriptionElementBase", "DescriptionBase", "Extension",
113 // "GatheringEvent", "GatheringEvent_DefinedTermBase",
114 // "LanguageString", "OriginalSourceBase", "Reference",
115 // "TaxonBase", "TaxonNameBase", "TypeDesignationBase",
116 // "TaxonNameBase_TypeDesignationBase",
117 // "SpecimenOrObservationBase", "DefinedTermBase",
118 // "TermVocabulary", "Representation" });
119 // // printDataSet(myOut);
120 // } catch (FileNotFoundException e) {
121 // Assert.fail(e.getLocalizedMessage());
122 // }
123
124 }
125
126 }