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.stream.mapping;
|
10
|
|
11
|
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
16
|
import org.junit.Assert;
|
17
|
import org.junit.Before;
|
18
|
import org.junit.BeforeClass;
|
19
|
import org.junit.Ignore;
|
20
|
import org.junit.Test;
|
21
|
|
22
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
23
|
import eu.etaxonomy.cdm.io.stream.mapping.DatabaseMapping;
|
24
|
import eu.etaxonomy.cdm.io.stream.mapping.IImportMapping.CdmKey;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
27
|
|
28
|
/**
|
29
|
* @author a.mueller
|
30
|
* @since 26.03.2012
|
31
|
*
|
32
|
*/
|
33
|
public class DatabaseMappingTest {
|
34
|
private static final Logger logger = LogManager.getLogger(DatabaseMappingTest.class);
|
35
|
|
36
|
|
37
|
private DatabaseMapping mapping;
|
38
|
|
39
|
private final String mappingId = "MappingKey123";
|
40
|
|
41
|
/**
|
42
|
* @throws java.lang.Exception
|
43
|
*/
|
44
|
@BeforeClass
|
45
|
public static void setUpBeforeClass() throws Exception {
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* @throws java.lang.Exception
|
50
|
*/
|
51
|
@Before
|
52
|
public void setUp() throws Exception {
|
53
|
mapping = new DatabaseMapping(mappingId);
|
54
|
}
|
55
|
|
56
|
//******************* TESTS *****************************/
|
57
|
|
58
|
@Test
|
59
|
@Ignore
|
60
|
public void testGetDatabase(){
|
61
|
|
62
|
ICdmDataSource datasource = mapping.getDatabase();
|
63
|
Assert.assertNotNull("Datasource should not be null", datasource);
|
64
|
String sql = "INSERT INTO " + DatabaseMapping.TABLE_IMPORT_MAPPING+ "( task_id, source_namespace, source_id, destination_namespace, destination_id) ";
|
65
|
sql += "VALUES ( 'mappingID', 'ns1', 'source1', 'destNs', 'dest1')";
|
66
|
try {
|
67
|
datasource.executeUpdate(sql);
|
68
|
} catch (SQLException e) {
|
69
|
//maybe it just only exists
|
70
|
logger.warn("Error occurred");
|
71
|
}
|
72
|
}
|
73
|
|
74
|
@Test
|
75
|
@Ignore
|
76
|
public void testPutGetExists(){
|
77
|
|
78
|
ICdmDataSource datasource = mapping.getDatabase();
|
79
|
Assert.assertNotNull("Datasource should not be null", datasource);
|
80
|
|
81
|
TaxonName botName1 = TaxonNameFactory.NewBotanicalInstance(null);
|
82
|
int id = 23;
|
83
|
botName1.setId(id);
|
84
|
String sourceNS = "sourceNS";
|
85
|
String sourceId = "sourceName1";
|
86
|
mapping.putMapping(sourceNS, sourceId, botName1);
|
87
|
Set<CdmKey> result = mapping.get(sourceNS, sourceId);
|
88
|
Assert.assertNotNull("Result should not be null", result);
|
89
|
Assert.assertFalse("Result should not be empty", result.isEmpty());
|
90
|
|
91
|
boolean exists = mapping.exists(sourceNS, sourceId, TaxonName.class);
|
92
|
Assert.assertTrue("Mapping should exist", exists);
|
93
|
exists = mapping.exists(sourceNS + "xyz", sourceId, TaxonName.class);
|
94
|
Assert.assertFalse("Mapping with wrong namespace should not exist", exists);
|
95
|
exists = mapping.exists(sourceNS + "xyz", sourceId, TaxonName.class);
|
96
|
Assert.assertFalse("Mapping with wrong ID should not exist", exists);
|
97
|
|
98
|
}
|
99
|
|
100
|
}
|