1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.database;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
|
15
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
16
|
import org.junit.Before;
|
17
|
import org.junit.BeforeClass;
|
18
|
import org.junit.Test;
|
19
|
import org.springframework.beans.factory.config.BeanDefinition;
|
20
|
|
21
|
/**
|
22
|
* @author a.mueller
|
23
|
* @since 18.12.2008
|
24
|
*/
|
25
|
public class CdmDataSourceTest {
|
26
|
private static final Logger logger = LogManager.getLogger(CdmDataSourceTest.class);
|
27
|
|
28
|
private static String server;
|
29
|
private static String database;
|
30
|
private static String username;
|
31
|
private static String pwd;
|
32
|
private static int port;
|
33
|
private static ICdmDataSource datasource;
|
34
|
|
35
|
/**
|
36
|
* @throws java.lang.Exception
|
37
|
*/
|
38
|
@BeforeClass
|
39
|
public static void setUpBeforeClass() throws Exception {
|
40
|
}
|
41
|
|
42
|
|
43
|
/**
|
44
|
* @throws java.lang.Exception
|
45
|
*/
|
46
|
@Before
|
47
|
public void setUp() throws Exception {
|
48
|
server = "myServer";
|
49
|
database = "myDatabase";
|
50
|
username = "myUsername";
|
51
|
pwd = "myPassword";
|
52
|
port = 80;
|
53
|
datasource = CdmDataSource.NewMySqlInstance(server, database, port, username, pwd);
|
54
|
}
|
55
|
|
56
|
|
57
|
//*************** TESTS ***********************************************
|
58
|
|
59
|
@Test
|
60
|
public void testNewMySqlInstanceStringStringStringString() {
|
61
|
ICdmDataSource ds = CdmDataSource.NewMySqlInstance(server, database, username, pwd);
|
62
|
assertNotNull("NewMySqlInstance(String, String, String, String) should not return null ", ds);
|
63
|
assertEquals(server, ds.getServer());
|
64
|
assertEquals(database, ds.getDatabase());
|
65
|
assertEquals(username, ds.getUsername());
|
66
|
assertEquals(pwd, ds.getPassword());
|
67
|
assertEquals(DatabaseTypeEnum.MySQL, ds.getDatabaseType());
|
68
|
}
|
69
|
|
70
|
@Test
|
71
|
public void testNewMySqlInstanceStringStringIntStringString() {
|
72
|
ICdmDataSource ds = CdmDataSource.NewMySqlInstance(server, database, port, username, pwd);
|
73
|
assertNotNull("NewMySqlInstance(String, String, int, String, String) should not return null ", ds);
|
74
|
assertEquals(server, ds.getServer());
|
75
|
assertEquals(database, ds.getDatabase());
|
76
|
assertEquals(username, ds.getUsername());
|
77
|
assertEquals(pwd, ds.getPassword());
|
78
|
assertEquals(port, ds.getPort());
|
79
|
assertEquals(DatabaseTypeEnum.MySQL, ds.getDatabaseType());
|
80
|
}
|
81
|
|
82
|
@Test
|
83
|
public void testNewSqlServer2005InstanceStringStringStringString() {
|
84
|
ICdmDataSource ds = CdmDataSource.NewSqlServer2005Instance(server, database, -1, username, pwd);
|
85
|
assertNotNull("NewSqlServer2005Instance(String, String, String, String) should not return null ", ds);
|
86
|
assertEquals(server, ds.getServer());
|
87
|
assertEquals(database, ds.getDatabase());
|
88
|
assertEquals(username, ds.getUsername());
|
89
|
assertEquals(pwd, ds.getPassword());
|
90
|
assertEquals(DatabaseTypeEnum.SqlServer2005, ds.getDatabaseType());
|
91
|
}
|
92
|
|
93
|
@Test
|
94
|
public void testNewSqlServer2005InstanceStringStringIntStringString() {
|
95
|
ICdmDataSource ds = CdmDataSource.NewSqlServer2005Instance(server, database, port, username, pwd);
|
96
|
assertNotNull("NewSqlServer2005Instance(String, String, String, String) should not return null ", ds);
|
97
|
assertEquals(server, ds.getServer());
|
98
|
assertEquals(database, ds.getDatabase());
|
99
|
assertEquals(username, ds.getUsername());
|
100
|
assertEquals(pwd, ds.getPassword());
|
101
|
assertEquals(port, ds.getPort());
|
102
|
assertEquals(DatabaseTypeEnum.SqlServer2005, ds.getDatabaseType());
|
103
|
}
|
104
|
|
105
|
@Test
|
106
|
public void testNewH2EmbeddedInstanceStringStringString() {
|
107
|
ICdmDataSource ds = CdmDataSource.NewH2EmbeddedInstance(database, username, pwd, null);
|
108
|
assertNotNull("NewH2EmbeddedInstance(String, String, String) should not return null ", ds);
|
109
|
assertEquals(null, ds.getServer()); //TODO right?
|
110
|
assertEquals(database, ds.getDatabase());
|
111
|
assertEquals(username, ds.getUsername());
|
112
|
assertEquals(pwd, ds.getPassword());
|
113
|
assertEquals(DatabaseTypeEnum.H2, ds.getDatabaseType());
|
114
|
}
|
115
|
|
116
|
@Test
|
117
|
public void testNewH2InMemoryInstance() {
|
118
|
ICdmDataSource ds = CdmDataSource.NewH2InMemoryInstance();
|
119
|
assertNotNull("NewH2InMemoryInstance() should not return null ", ds);
|
120
|
assertEquals(DatabaseTypeEnum.H2, ds.getDatabaseType());
|
121
|
assertEquals(null, ds.getServer());
|
122
|
assertEquals(null, ds.getDatabase());
|
123
|
assertEquals("sa", ds.getUsername()); //TODO right?
|
124
|
assertEquals("", ds.getPassword());
|
125
|
assertEquals(DatabaseTypeEnum.H2, ds.getDatabaseType());
|
126
|
}
|
127
|
|
128
|
@Test
|
129
|
public void testCdmDataSource() {
|
130
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
131
|
H2Mode h2Mode = H2Mode.EMBEDDED;
|
132
|
String filePath = "path";
|
133
|
ICdmDataSource ds = new CdmDataSource(dbType, server, database, port, username, pwd, filePath, h2Mode);
|
134
|
assertNotNull("new datasource() should not be null", ds);
|
135
|
}
|
136
|
|
137
|
@Test
|
138
|
public void testGetName() {
|
139
|
assertNotNull("datasource should not be null", datasource);
|
140
|
assertEquals(database, datasource.getName());
|
141
|
}
|
142
|
|
143
|
@Test
|
144
|
public void testGetDatasourceBean() {
|
145
|
BeanDefinition bean = datasource.getDatasourceBean();
|
146
|
assertNotNull(bean);
|
147
|
assertEquals("the bean definition should have 4 properties: url, driverClassname, username, password", 4, bean.getPropertyValues().size());
|
148
|
//TODO to be continued
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* Test method for {@link eu.etaxonomy.cdm.database.CdmDataSource#getInitMethodName()}.
|
153
|
* Test method for {@link eu.etaxonomy.cdm.database.CdmDataSource#setInitMethodName(java.lang.String)}.
|
154
|
*/
|
155
|
@Test
|
156
|
public void testGetSetInitMethodName() {
|
157
|
String initMethodName = "init";
|
158
|
((CdmDataSource)datasource).setInitMethodName(initMethodName);
|
159
|
assertEquals(initMethodName, ((CdmDataSource)datasource).getInitMethodName());
|
160
|
((CdmDataSource)datasource).setInitMethodName(null);
|
161
|
assertEquals(null, ((CdmDataSource)datasource).getInitMethodName());
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* Test method for {@link eu.etaxonomy.cdm.database.CdmDataSource#getDestroyMethodName()}.
|
166
|
* Test method for {@link eu.etaxonomy.cdm.database.CdmDataSource#setDestroyMethodName(java.lang.String)}.
|
167
|
*/
|
168
|
@Test
|
169
|
public void testGetSetDestroyMethodName() {
|
170
|
String destroyMethodName = "destroy";
|
171
|
((CdmDataSource)datasource).setDestroyMethodName(destroyMethodName);
|
172
|
assertEquals(destroyMethodName, ((CdmDataSource)datasource).getDestroyMethodName());
|
173
|
((CdmDataSource)datasource).setDestroyMethodName(null);
|
174
|
assertEquals(null, ((CdmDataSource)datasource).getDestroyMethodName());
|
175
|
}
|
176
|
|
177
|
@Test
|
178
|
public void testGetDatabase() {
|
179
|
assertEquals(database, datasource.getDatabase());
|
180
|
}
|
181
|
|
182
|
@Test
|
183
|
public void testGetDatabaseType() {
|
184
|
assertEquals(DatabaseTypeEnum.MySQL, datasource.getDatabaseType());
|
185
|
}
|
186
|
|
187
|
@Test
|
188
|
public void testGetFilePath() {
|
189
|
assertEquals(null, datasource.getFilePath());
|
190
|
String filePath = "path";
|
191
|
ICdmDataSource ds = new CdmDataSource(DatabaseTypeEnum.H2, server, database, port, username, pwd, filePath, H2Mode.EMBEDDED);
|
192
|
assertNotNull("new datasource() should not be null", ds);
|
193
|
assertEquals(filePath, ds.getFilePath());
|
194
|
}
|
195
|
|
196
|
@Test
|
197
|
public void testGetPort() {
|
198
|
assertEquals(port, datasource.getPort());
|
199
|
}
|
200
|
|
201
|
@Test
|
202
|
public void testGetServer() {
|
203
|
assertEquals(server, datasource.getServer());
|
204
|
}
|
205
|
|
206
|
@Test
|
207
|
public void testGetMode() {
|
208
|
assertEquals(null, datasource.getFilePath());
|
209
|
String filePath = "path";
|
210
|
H2Mode mode = H2Mode.EMBEDDED;
|
211
|
ICdmDataSource ds = new CdmDataSource(DatabaseTypeEnum.H2, server, database, port, username, pwd, filePath, mode);
|
212
|
assertNotNull("new datasource() should not be null", ds);
|
213
|
assertEquals(mode, ds.getMode());
|
214
|
}
|
215
|
|
216
|
@Test
|
217
|
public void testGetPassword() {
|
218
|
assertEquals(pwd, datasource.getPassword());
|
219
|
}
|
220
|
|
221
|
@Test
|
222
|
public void testGetUsername() {
|
223
|
assertEquals(username, datasource.getUsername());
|
224
|
}
|
225
|
|
226
|
@Test
|
227
|
public void testTestConnection() {
|
228
|
logger.warn("Not yet implemented");
|
229
|
}
|
230
|
}
|