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
;
17 import java
.net
.URISyntaxException
;
19 import java
.sql
.SQLException
;
21 import org
.junit
.Assert
;
22 import org
.junit
.Before
;
23 import org
.junit
.Ignore
;
24 import org
.junit
.Test
;
25 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
27 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
30 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
31 import eu
.etaxonomy
.cdm
.common
.URI
;
32 import eu
.etaxonomy
.cdm
.database
.CdmDataSource
;
33 import eu
.etaxonomy
.cdm
.database
.CdmPersistentDataSource
;
34 import eu
.etaxonomy
.cdm
.database
.DataSourceNotFoundException
;
35 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
36 import eu
.etaxonomy
.cdm
.io
.common
.IExportConfigurator
;
37 import eu
.etaxonomy
.cdm
.io
.sdd
.out
.SDDCdmExporter
;
38 import eu
.etaxonomy
.cdm
.io
.sdd
.out
.SDDExportConfigurator
;
39 import eu
.etaxonomy
.cdm
.io
.sdd
.out
.SDDExportState
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
42 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
48 public class SDDImportExportTest
extends CdmTransactionalIntegrationTest
{
53 private SDDImportConfigurator importConfigurator
;
56 SDDCdmExporter sddCdmExporter
;
59 INameService nameService
;
62 ITaxonService taxonService
;
65 IClassificationService classificationService
;
67 private IExportConfigurator exportConfigurator
;
71 //calling before testInit testDoInvoke. db stuff into devlopeACustomDatabase
73 public void setUp() throws URISyntaxException
, MalformedURLException
{
75 //URL url = this.getClass().getResource("/eu/etaxonomy/cdm/io/sdd/SDDImportTest-input3.xml");
76 URL url
= this.getClass().getResource("/eu/etaxonomy/cdm/io/sdd/ant.sdd.xml");
77 URI uri
= URI
.fromUrl(url
);
80 String exporturlStr
= "SDDImportExportTest.sdd.xml";
81 File f
= new File(exporturlStr
);
82 exporturlStr
= f
.toURI().toURL().toString();
83 logger
.debug("The exporturlStr is " + exporturlStr
);
85 // URI.create("file:///C:/localCopy/Data/xper/Cichorieae-DA2.sdd.xml");
87 Assert
.assertNotNull(url
);
89 ICdmDataSource loadedDataSource
= null;
92 * enable below line if you wish to use a custom data source
94 //loadedDataSource = customDataSource();
96 importConfigurator
= SDDImportConfigurator
.NewInstance(uri
, loadedDataSource
);
97 exportConfigurator
= SDDExportConfigurator
.NewInstance(loadedDataSource
, exporturlStr
);
102 public void testDoInvoke() {
104 assertNotNull("sddImport should not be null", sddImport
);
105 assertNotNull("sddCdmExporter should not be null", sddCdmExporter
);
107 setDefaultRollback(false);
109 //printDataSet(System.err, new String[]{"DEFINEDTERMBASE"});
111 sddImport
.doInvoke(new SDDImportState(importConfigurator
));
113 //logger.setLevel(Level.DEBUG);
114 commitAndStartNewTransaction(new String
[]{"DEFINEDTERMBASE"});
116 logger
.debug("Name count: " + (nameService
.count(null)));
117 logger
.debug("Classification count: " + (classificationService
.count(Classification
.class)));
118 logger
.debug("Taxon count: " + (taxonService
.count(Taxon
.class)));
120 //sddCdmExporter.doInvoke(null);
121 sddCdmExporter
.doInvoke(new SDDExportState((SDDExportConfigurator
) exportConfigurator
));
122 assertEquals("Number of TaxonNames should be 1", 1, nameService
.count(null));
125 private ICdmDataSource
customDataSource() {
127 CdmPersistentDataSource loadedDataSource
= null;
128 //ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_test_niels2", 3306, "edit", password, code);
129 String dataSourceName
= "cdm_test2";
130 String password
= CdmUtils
.readInputLine("Password: ");
131 ICdmDataSource dataSource
= CdmDataSource
.NewMySqlInstance("127.0.0.1", "cdm_test2", 3306, "ljm", password
);
132 //ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("160.45.63.201", "cdm_test", 3306, "edit", password);
133 boolean connectionAvailable
;
135 connectionAvailable
= dataSource
.testConnection();
136 logger
.debug("Is connection avaiable " + connectionAvailable
);
137 Assert
.assertTrue("Testdatabase is not available", connectionAvailable
);
139 } catch (ClassNotFoundException e1
) {
140 e1
.printStackTrace();
141 } catch (SQLException e1
) {
142 e1
.printStackTrace();
145 CdmPersistentDataSource
.save(dataSourceName
, dataSource
);
147 loadedDataSource
= CdmPersistentDataSource
.NewInstance(dataSourceName
);
148 // CdmApplicationController.NewInstance(loadedDataSource, DbSchemaValidation.CREATE);
149 // NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode();
151 // Assert.assertEquals(NomenclaturalCode.ICNAFP, loadedCode);
152 } catch (DataSourceNotFoundException e
) {
153 // TODO Auto-generated catch block
156 //return loadedDataSource;
161 public void createTestDataSet() throws FileNotFoundException
{}