removed exact location from specimen import test
[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.io.File;
17 import java.io.FileNotFoundException;
18 import java.io.FileOutputStream;
19 import java.net.URISyntaxException;
20 import java.net.URL;
21
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Ignore;
25 import org.junit.Test;
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.occurrence.DerivedUnitBase;
35 import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
36 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
37
38 /**
39 * @author a.mueller
40 * @created 10.05.2011
41 * @version 1.0
42 */
43 //@Ignore //currently jenkins throws an exception
44 public class ExcelSpecimenImportExampleTest extends CdmTransactionalIntegrationTest {
45
46 @SpringBeanByName
47 CdmApplicationAwareDefaultImport<?> defaultImport;
48
49 @SpringBeanByType
50 INameService nameService;
51
52 @SpringBeanByType
53 IOccurrenceService occurrenceService;
54
55
56 private IImportConfigurator configurator;
57
58 @Before
59 public void setUp() {
60 String inputFile = "/eu/etaxonomy/cdm/io/specimen/excel/in/ExcelSpecimenImportExampleTest-input.xls";
61 URL url = this.getClass().getResource(inputFile);
62 assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
63 try {
64 configurator = SpecimenCdmExcelImportConfigurator.NewInstance(url.toURI(), null);
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 // @Test
80 // public void testDoInvoke() {
81 // boolean result = defaultImport.invoke(configurator);
82 // assertTrue("Return value for import.invoke should be true", result);
83 // assertEquals("Number of specimen should be 3", 3, occurrenceService.count(DerivedUnitBase.class));
84 // assertEquals("Number of field observations should be 3", 3, occurrenceService.count(FieldObservation.class));
85 //
86 //// printDataSet(System.out, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
87 //
88 // }
89
90 @Test
91 @ExpectedDataSet
92 public void testResultSet() {
93 boolean result = defaultImport.invoke(configurator);
94 assertTrue("Return value for import.invoke should be true", result);
95 assertEquals("Number of specimen should be 3", 3, occurrenceService.count(DerivedUnitBase.class));
96 assertEquals("Number of field observations should be 3", 3, occurrenceService.count(FieldObservation.class));
97
98 try {
99 String filePath = System.getProperty("java.io.tmpdir")+File.separator+"excelSpecimenOutput.xml";
100 File file = new File(filePath);
101 FileOutputStream myOut = new FileOutputStream(file);
102 System.out.println(file.getAbsolutePath());
103 printDataSet(myOut, new String[]{"SpecimenOrObservationBase","GatheringEvent","DerivationEvent"});
104 } catch (FileNotFoundException e) {
105 // TODO Auto-generated catch block
106 e.printStackTrace();
107 }
108
109 }
110
111 }