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