1
|
/**
|
2
|
* Copyright (C) 2017 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.tropicos;
|
10
|
|
11
|
import static org.junit.Assert.assertNotNull;
|
12
|
|
13
|
import java.io.FileNotFoundException;
|
14
|
import java.net.URL;
|
15
|
import java.util.List;
|
16
|
|
17
|
import org.junit.Assert;
|
18
|
import org.junit.Before;
|
19
|
import org.junit.Ignore;
|
20
|
import org.junit.Test;
|
21
|
import org.unitils.dbunit.annotation.DataSet;
|
22
|
import org.unitils.spring.annotation.SpringBeanByName;
|
23
|
import org.unitils.spring.annotation.SpringBeanByType;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.service.INameService;
|
26
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
27
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
|
28
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
29
|
import eu.etaxonomy.cdm.io.tropicos.in.TropicosNameImportConfigurator;
|
30
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
31
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
32
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
33
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
34
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
35
|
|
36
|
/**
|
37
|
* @author a.mueller
|
38
|
* @since 15.11.2017
|
39
|
*/
|
40
|
public class TropicosNameImportTest extends CdmTransactionalIntegrationTest{
|
41
|
|
42
|
@SpringBeanByName
|
43
|
private CdmApplicationAwareDefaultImport<?> defaultImport;
|
44
|
|
45
|
@SpringBeanByType
|
46
|
private INameService nameService;
|
47
|
|
48
|
@SpringBeanByType
|
49
|
private ITaxonService taxonService;
|
50
|
|
51
|
private TropicosNameImportConfigurator configShort;
|
52
|
private TropicosNameImportConfigurator configLong;
|
53
|
|
54
|
@Before
|
55
|
public void setUp() {
|
56
|
String inputFile = "/eu/etaxonomy/cdm/io/tropicos/TropicosNameImportTest-input.txt";
|
57
|
|
58
|
try {
|
59
|
URL url = this.getClass().getResource(inputFile);
|
60
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
61
|
|
62
|
String inputFileLong = "/eu/etaxonomy/cdm/io/tropicos/TropicosNameImportTest-input.txt";
|
63
|
URL urlLong = this.getClass().getResource(inputFileLong);
|
64
|
assertNotNull("URL for the test file '" + inputFileLong + "' does not exist", urlLong);
|
65
|
|
66
|
configShort = TropicosNameImportConfigurator.NewInstance(url.toURI(), null);
|
67
|
configLong = TropicosNameImportConfigurator.NewInstance(urlLong.toURI(), null);
|
68
|
|
69
|
|
70
|
} catch (Exception e) {
|
71
|
e.printStackTrace();
|
72
|
Assert.fail();
|
73
|
}
|
74
|
assertNotNull("Configurator could not be created", configShort);
|
75
|
assertNotNull("Configurator could not be created", configLong);
|
76
|
assertNotNull("nameService should not be null", nameService);
|
77
|
}
|
78
|
|
79
|
//***************************** TESTS *************************************//
|
80
|
|
81
|
@Test
|
82
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
83
|
public void testShort() {
|
84
|
configShort.setCreateTaxa(true);
|
85
|
ImportResult result = defaultImport.invoke(configShort);
|
86
|
String report = result.createReport().toString();
|
87
|
|
88
|
|
89
|
|
90
|
Integer expected = 2;
|
91
|
Assert.assertEquals(expected, result.getNewRecords(TaxonName.class));
|
92
|
|
93
|
Assert.assertTrue(report.length() > 0);
|
94
|
System.out.println(report);
|
95
|
|
96
|
List<TaxonName> list = nameService.list(TaxonName.class, null, null, null, null);
|
97
|
Assert.assertEquals("There should be 2 new taxon names", 2, list.size());
|
98
|
for (TaxonName name : list){
|
99
|
//TODO
|
100
|
}
|
101
|
|
102
|
expected = 1;
|
103
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
104
|
}
|
105
|
|
106
|
@Test
|
107
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
108
|
//@Ignore
|
109
|
public void testShortCreateTaxa() {
|
110
|
configShort.setCreateTaxa(true);
|
111
|
ImportResult result = defaultImport.invoke(configShort);
|
112
|
|
113
|
Integer expected = 2;
|
114
|
Assert.assertEquals(expected, result.getNewRecords(Taxon.class));
|
115
|
|
116
|
List<Taxon> list = taxonService.list(Taxon.class, null, null, null, null);
|
117
|
Assert.assertEquals("There should be 2 new taxa", 2, list.size());
|
118
|
}
|
119
|
|
120
|
@Test
|
121
|
@Ignore
|
122
|
public void testLongFile() {
|
123
|
ImportResult result = defaultImport.invoke(configLong);
|
124
|
String report = result.createReport().toString();
|
125
|
System.out.println(report);
|
126
|
|
127
|
Integer expected = 118; //did not count yet
|
128
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
129
|
}
|
130
|
|
131
|
@Override
|
132
|
public void createTestDataSet() throws FileNotFoundException {}
|
133
|
}
|