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