1
|
/**
|
2
|
* Copyright (C) 2009 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.sdd.in;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
|
14
|
import java.io.File;
|
15
|
import java.io.FileNotFoundException;
|
16
|
import java.net.MalformedURLException;
|
17
|
import java.net.URI;
|
18
|
import java.net.URISyntaxException;
|
19
|
import java.net.URL;
|
20
|
import java.sql.SQLException;
|
21
|
|
22
|
import org.apache.log4j.Level;
|
23
|
import org.junit.Assert;
|
24
|
import org.junit.Before;
|
25
|
import org.junit.Ignore;
|
26
|
import org.junit.Test;
|
27
|
import org.unitils.spring.annotation.SpringBeanByType;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
30
|
import eu.etaxonomy.cdm.api.service.INameService;
|
31
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
32
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
33
|
import eu.etaxonomy.cdm.database.CdmDataSource;
|
34
|
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
|
35
|
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
|
36
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
37
|
import eu.etaxonomy.cdm.io.common.IExportConfigurator;
|
38
|
import eu.etaxonomy.cdm.io.sdd.out.SDDCdmExporter;
|
39
|
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
|
40
|
import eu.etaxonomy.cdm.io.sdd.out.SDDExportState;
|
41
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
42
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
43
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
44
|
|
45
|
/**
|
46
|
* @author l.morris
|
47
|
* @since 14 Nov 2012
|
48
|
*
|
49
|
*/
|
50
|
public class SDDImportExportTest extends CdmTransactionalIntegrationTest {
|
51
|
|
52
|
@SpringBeanByType
|
53
|
SDDImport sddImport;
|
54
|
|
55
|
private SDDImportConfigurator importConfigurator;
|
56
|
|
57
|
@SpringBeanByType
|
58
|
SDDCdmExporter sddCdmExporter;
|
59
|
|
60
|
@SpringBeanByType
|
61
|
INameService nameService;
|
62
|
|
63
|
@SpringBeanByType
|
64
|
ITaxonService taxonService;
|
65
|
|
66
|
@SpringBeanByType
|
67
|
IClassificationService classificationService;
|
68
|
|
69
|
private IExportConfigurator exportConfigurator;
|
70
|
|
71
|
@Before
|
72
|
@Ignore
|
73
|
//calling before testInit testDoInvoke. db stuff into devlopeACustomDatabase
|
74
|
//setDefaultRollback
|
75
|
public void setUp() throws URISyntaxException, MalformedURLException {
|
76
|
// input data
|
77
|
//URL url = this.getClass().getResource("/eu/etaxonomy/cdm/io/sdd/SDDImportTest-input3.xml");
|
78
|
URL url = this.getClass().getResource("/eu/etaxonomy/cdm/io/sdd/ant.sdd.xml");
|
79
|
URI uri = url.toURI();
|
80
|
|
81
|
// export data
|
82
|
String exporturlStr = "SDDImportExportTest.sdd.xml";
|
83
|
File f = new File(exporturlStr);
|
84
|
exporturlStr = f.toURI().toURL().toString();
|
85
|
logger.debug("The exporturlStr is " + exporturlStr);
|
86
|
|
87
|
// URI.create("file:///C:/localCopy/Data/xper/Cichorieae-DA2.sdd.xml");
|
88
|
|
89
|
Assert.assertNotNull(url);
|
90
|
|
91
|
ICdmDataSource loadedDataSource = null;
|
92
|
|
93
|
/*
|
94
|
* enable below line if you wish to use a custom data source
|
95
|
*/
|
96
|
//loadedDataSource = customDataSource();
|
97
|
|
98
|
importConfigurator = SDDImportConfigurator.NewInstance(uri, loadedDataSource);
|
99
|
exportConfigurator = SDDExportConfigurator.NewInstance(loadedDataSource, exporturlStr);
|
100
|
}
|
101
|
|
102
|
@Test
|
103
|
@Ignore
|
104
|
public void testDoInvoke() {
|
105
|
|
106
|
assertNotNull("sddImport should not be null", sddImport);
|
107
|
assertNotNull("sddCdmExporter should not be null", sddCdmExporter);
|
108
|
|
109
|
setDefaultRollback(false);
|
110
|
|
111
|
//printDataSet(System.err, new String[]{"DEFINEDTERMBASE"});
|
112
|
|
113
|
sddImport.doInvoke(new SDDImportState(importConfigurator));
|
114
|
|
115
|
//logger.setLevel(Level.DEBUG);
|
116
|
commitAndStartNewTransaction(new String[]{"DEFINEDTERMBASE"});
|
117
|
logger.setLevel(Level.DEBUG);
|
118
|
|
119
|
logger.debug("Name count: " + (nameService.count(null)));
|
120
|
logger.debug("Classification count: " + (classificationService.count(Classification.class)));
|
121
|
logger.debug("Taxon count: " + (taxonService.count(Taxon.class)));
|
122
|
|
123
|
//sddCdmExporter.doInvoke(null);
|
124
|
sddCdmExporter.doInvoke(new SDDExportState((SDDExportConfigurator) exportConfigurator));
|
125
|
assertEquals("Number of TaxonNames should be 1", 1, nameService.count(null));
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* @param loadedDataSource
|
130
|
* @return
|
131
|
*/
|
132
|
private ICdmDataSource customDataSource() {
|
133
|
|
134
|
CdmPersistentDataSource loadedDataSource = null;
|
135
|
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_test_niels2", 3306, "edit", password, code);
|
136
|
String dataSourceName = "cdm_test2";
|
137
|
String password = CdmUtils.readInputLine("Password: ");
|
138
|
ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", "cdm_test2", 3306, "ljm", password);
|
139
|
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("160.45.63.201", "cdm_test", 3306, "edit", password);
|
140
|
boolean connectionAvailable;
|
141
|
try {
|
142
|
connectionAvailable = dataSource.testConnection();
|
143
|
logger.debug("Is connection avaiable " + connectionAvailable);
|
144
|
Assert.assertTrue("Testdatabase is not available", connectionAvailable);
|
145
|
|
146
|
} catch (ClassNotFoundException e1) {
|
147
|
e1.printStackTrace();
|
148
|
} catch (SQLException e1) {
|
149
|
e1.printStackTrace();
|
150
|
}
|
151
|
|
152
|
CdmPersistentDataSource.save(dataSourceName, dataSource);
|
153
|
try {
|
154
|
loadedDataSource = CdmPersistentDataSource.NewInstance(dataSourceName);
|
155
|
// CdmApplicationController.NewInstance(loadedDataSource, DbSchemaValidation.CREATE);
|
156
|
// NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode();
|
157
|
//
|
158
|
// Assert.assertEquals(NomenclaturalCode.ICNAFP, loadedCode);
|
159
|
} catch (DataSourceNotFoundException e) {
|
160
|
// TODO Auto-generated catch block
|
161
|
e.printStackTrace();
|
162
|
}
|
163
|
//return loadedDataSource;
|
164
|
return dataSource;
|
165
|
}
|
166
|
|
167
|
@Override
|
168
|
public void createTestDataSet() throws FileNotFoundException {}
|
169
|
}
|