2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.io
.sdd
.in
;
11 import static org
.junit
.Assert
.assertEquals
;
12 import static org
.junit
.Assert
.assertNotNull
;
15 import java
.io
.FileNotFoundException
;
16 import java
.net
.MalformedURLException
;
18 import java
.net
.URISyntaxException
;
20 import java
.sql
.SQLException
;
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
;
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
;
50 public class SDDImportExportTest
extends CdmTransactionalIntegrationTest
{
55 private SDDImportConfigurator importConfigurator
;
58 SDDCdmExporter sddCdmExporter
;
61 INameService nameService
;
64 ITaxonService taxonService
;
67 IClassificationService classificationService
;
69 private IExportConfigurator exportConfigurator
;
73 //calling before testInit testDoInvoke. db stuff into devlopeACustomDatabase
75 public void setUp() throws URISyntaxException
, MalformedURLException
{
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();
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
);
87 // URI.create("file:///C:/localCopy/Data/xper/Cichorieae-DA2.sdd.xml");
89 Assert
.assertNotNull(url
);
91 ICdmDataSource loadedDataSource
= null;
94 * enable below line if you wish to use a custom data source
96 //loadedDataSource = customDataSource();
98 importConfigurator
= SDDImportConfigurator
.NewInstance(uri
, loadedDataSource
);
99 exportConfigurator
= SDDExportConfigurator
.NewInstance(loadedDataSource
, exporturlStr
);
104 public void testDoInvoke() {
106 assertNotNull("sddImport should not be null", sddImport
);
107 assertNotNull("sddCdmExporter should not be null", sddCdmExporter
);
109 setDefaultRollback(false);
111 //printDataSet(System.err, new String[]{"DEFINEDTERMBASE"});
113 sddImport
.doInvoke(new SDDImportState(importConfigurator
));
115 //logger.setLevel(Level.DEBUG);
116 commitAndStartNewTransaction(new String
[]{"DEFINEDTERMBASE"});
117 logger
.setLevel(Level
.DEBUG
);
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)));
123 //sddCdmExporter.doInvoke(null);
124 sddCdmExporter
.doInvoke(new SDDExportState((SDDExportConfigurator
) exportConfigurator
));
125 assertEquals("Number of TaxonNames should be 1", 1, nameService
.count(null));
129 * @param loadedDataSource
132 private ICdmDataSource
customDataSource() {
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
;
142 connectionAvailable
= dataSource
.testConnection();
143 logger
.debug("Is connection avaiable " + connectionAvailable
);
144 Assert
.assertTrue("Testdatabase is not available", connectionAvailable
);
146 } catch (ClassNotFoundException e1
) {
147 e1
.printStackTrace();
148 } catch (SQLException e1
) {
149 e1
.printStackTrace();
152 CdmPersistentDataSource
.save(dataSourceName
, dataSource
);
154 loadedDataSource
= CdmPersistentDataSource
.NewInstance(dataSourceName
);
155 // CdmApplicationController.NewInstance(loadedDataSource, DbSchemaValidation.CREATE);
156 // NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode();
158 // Assert.assertEquals(NomenclaturalCode.ICNAFP, loadedCode);
159 } catch (DataSourceNotFoundException e
) {
160 // TODO Auto-generated catch block
163 //return loadedDataSource;
168 public void createTestDataSet() throws FileNotFoundException
{}