/
AbstractDatabaseTest.java
139 lines (112 loc) · 4.58 KB
/
AbstractDatabaseTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* SymmetricDS is an open source database synchronization solution.
*
* Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/
package org.jumpmind.symmetric.test;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.SymmetricEngine;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.db.IDbDialect;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.symmetric.util.AppUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.springframework.jdbc.core.JdbcTemplate;
public class AbstractDatabaseTest {
static final Log logger = LogFactory.getLog(AbstractDatabaseTest.class);
protected String database;
static boolean standalone = false;
public AbstractDatabaseTest(String dbName) {
this.database = dbName;
}
public AbstractDatabaseTest() throws Exception {
if (!standalone) {
logger.info("Running test in standalone mode");
standalone = true;
TestSetupUtil.setup(DatabaseTestSuite.DEFAULT_TEST_PREFIX, TestConstants.TEST_CONTINUOUS_SETUP_SCRIPT,
null, TestSetupUtil.getRootDbTypes(DatabaseTestSuite.DEFAULT_TEST_PREFIX)[0]);
}
}
protected SymmetricEngine getSymmetricEngine() {
return TestSetupUtil.getRootEngine();
}
protected IParameterService getParameterService() {
return AppUtils.find(Constants.PARAMETER_SERVICE, getSymmetricEngine());
}
protected IDbDialect getDbDialect() {
return AppUtils.find(Constants.DB_DIALECT, getSymmetricEngine());
}
protected DataSource getDataSource() {
return AppUtils.find(Constants.DATA_SOURCE, getSymmetricEngine());
}
protected JdbcTemplate getJdbcTemplate() {
return new JdbcTemplate((DataSource) AppUtils.find(Constants.DATA_SOURCE, getSymmetricEngine()));
}
@SuppressWarnings("unchecked")
protected <T> T find(String name) {
return (T) AppUtils.find(name, getSymmetricEngine());
}
@AfterClass
public static void cleanup() throws Exception {
if (standalone) {
logger.info("Cleaning up after test in standalone mode");
TestSetupUtil.cleanup();
standalone = false;
}
}
protected void cleanSlate(final String... tableName) {
for (String table : tableName) {
getJdbcTemplate().update("delete from " + table);
}
}
protected void assertTrue(boolean condition, String message) {
Assert.assertTrue(message, condition);
}
protected void assertFalse(boolean condition, String message) {
Assert.assertFalse(message, condition);
}
protected void assertNotNull(Object condition, String message) {
Assert.assertNotNull(message, condition);
}
protected void assertNull(Object condition) {
Assert.assertNull(condition);
}
protected void assertNotNull(Object condition) {
Assert.assertNotNull(condition);
}
protected void assertNull(Object condition, String message) {
Assert.assertNull(message, condition);
}
protected void assertFalse(boolean condition) {
Assert.assertFalse(condition);
}
protected void assertTrue(boolean condition) {
Assert.assertTrue(condition);
}
protected void assertEquals(Object actual, Object expected) {
Assert.assertEquals(expected, actual);
}
protected void assertEquals(Object actual, Object expected, String message) {
Assert.assertEquals(message, expected, actual);
}
protected void assertNotSame(Object actual, Object expected, String message) {
Assert.assertNotSame(message, expected, actual);
}
}