#3279:
[cdmlib.git] / cdmlib-io / src / test / java / eu / etaxonomy / cdm / io / specimen / abcd206 / in / SpecimenImportConfiguratorTest.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.abcd206.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.Test;
22 import org.unitils.dbunit.annotation.DataSet;
23 import org.unitils.spring.annotation.SpringBeanByName;
24 import org.unitils.spring.annotation.SpringBeanByType;
25
26 import eu.etaxonomy.cdm.api.service.INameService;
27 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
28 import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
29 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
30 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
31 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
32 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
33
34 /**
35 * @author a.mueller
36 * @created 29.01.2009
37 * @version 1.0
38 */
39 public class SpecimenImportConfiguratorTest extends CdmTransactionalIntegrationTest {
40
41 @SpringBeanByName
42 CdmApplicationAwareDefaultImport<?> defaultImport;
43
44 @SpringBeanByType
45 INameService nameService;
46
47 @SpringBeanByType
48 IOccurrenceService occurrenceService;
49
50
51 private IImportConfigurator configurator;
52
53 @Before
54 public void setUp() {
55 String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/SpecimenImportConfiguratorTest-input.xml";
56 URL url = this.getClass().getResource(inputFile);
57 assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
58 try {
59 configurator = Abcd206ImportConfigurator.NewInstance(url.toURI(), null);
60 } catch (URISyntaxException e) {
61 e.printStackTrace();
62 Assert.fail();
63 }
64 assertNotNull("Configurator could not be created", configurator);
65 }
66
67 @Test
68 public void testInit() {
69 assertNotNull("import instance should not be null", defaultImport);
70 assertNotNull("nameService should not be null", nameService);
71 assertNotNull("occurence service should not be null", occurrenceService);
72 }
73
74 @Test
75 @DataSet(value="../../../BlankDataSet.xml")
76 public void testDoInvoke() {
77 boolean result = defaultImport.invoke(configurator);
78 assertTrue("Return value for import.invoke should be true", result);
79
80 assertEquals("Number of TaxonNames is incorrect", 11, nameService.count(TaxonNameBase.class));
81 assertEquals("Number of specimen is incorrect", 10, occurrenceService.count(DerivedUnitBase.class));
82
83
84 }
85
86 }