/
AbstractIntegrationTest.java
82 lines (65 loc) · 3.15 KB
/
AbstractIntegrationTest.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
package org.jumpmind.symmetric;
import java.io.File;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.lang.StringUtils;
import org.jumpmind.symmetric.MultiDatabaseTestFactory.DatabaseRole;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.TestConstants;
import org.jumpmind.symmetric.db.IDbDialect;
import org.jumpmind.symmetric.db.SqlScript;
import org.jumpmind.symmetric.service.IBootstrapService;
abstract public class AbstractIntegrationTest extends AbstractTest {
private SymmetricEngine clientEngine;
private SymmetricEngine rootEngine;
private String clientDatabaseType;
private String rootDatabaseType;
protected SymmetricEngine getClientEngine() {
if (this.clientEngine == null) {
this.clientEngine = createEngine(getClientFile());
dropAndCreateDatabaseTables(getClientDatabaseName(), clientEngine);
}
return this.clientEngine;
}
protected String getRootDatabaseName() {
if (rootDatabaseType == null) {
IDbDialect dialect = (IDbDialect) getRootEngine().getApplicationContext().getBean(Constants.DB_DIALECT);
rootDatabaseType = dialect.getName().toLowerCase();
}
return rootDatabaseType;
}
protected String getClientDatabaseName() {
if (clientDatabaseType == null) {
IDbDialect dialect = (IDbDialect) getClientEngine().getApplicationContext().getBean(Constants.DB_DIALECT);
clientDatabaseType = dialect.getName().toLowerCase();
}
return clientDatabaseType;
}
protected SymmetricEngine getRootEngine() {
if (this.rootEngine == null) {
this.rootEngine = createEngine(getRootFile());
dropAndCreateDatabaseTables(getRootDatabaseName(), rootEngine);
((IBootstrapService) this.rootEngine.getApplicationContext().getBean(Constants.BOOTSTRAP_SERVICE)).init();
new SqlScript(getResource(TestConstants.TEST_ROOT_DOMAIN_SETUP_SCRIPT), (DataSource) this.rootEngine
.getApplicationContext().getBean(Constants.DATA_SOURCE), true).execute();
this.rootEngine.start();
}
return this.rootEngine;
}
File getClientFile() {
Properties properties = MultiDatabaseTestFactory.getTestProperties();
String[] databaseTypes = StringUtils.split(properties.getProperty("test.client"), ",");
return MultiDatabaseTestFactory.writeTempPropertiesFileFor(databaseTypes[0], DatabaseRole.CLIENT);
}
File getRootFile() {
Properties properties = MultiDatabaseTestFactory.getTestProperties();
String[] databaseTypes = StringUtils.split(properties.getProperty("test.root"), ",");
return MultiDatabaseTestFactory.writeTempPropertiesFileFor(databaseTypes[0], DatabaseRole.ROOT);
}
public void setClientDatabaseType(String clientDatabaseType) {
this.clientDatabaseType = clientDatabaseType;
}
public void setRootDatabaseType(String rootDatabaseType) {
this.rootDatabaseType = rootDatabaseType;
}
}