Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First round of unit test refactoring
- Loading branch information
Showing
7 changed files
with
160 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
symmetric/src/test/java/org/jumpmind/symmetric/AbstractIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.jumpmind.symmetric; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.ddlutils.Platform; | ||
import org.apache.ddlutils.io.DatabaseIO; | ||
import org.apache.ddlutils.model.Database; | ||
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.db.oracle.OracleDbDialect; | ||
import org.jumpmind.symmetric.service.IBootstrapService; | ||
|
||
abstract public class AbstractIntegrationTest { | ||
|
||
private SymmetricEngine clientEngine; | ||
|
||
private SymmetricEngine rootEngine; | ||
|
||
abstract File getClientFile(); | ||
|
||
abstract File getRootFile(); | ||
|
||
protected SymmetricEngine getClientEngine() { | ||
if (this.clientEngine == null) { | ||
this.clientEngine = createEngine(getClientFile()); | ||
dropAndCreateDatabaseTables(clientEngine); | ||
} | ||
return this.clientEngine; | ||
} | ||
|
||
protected SymmetricEngine getRootEngine() { | ||
if (this.rootEngine == null) { | ||
this.rootEngine = createEngine(getRootFile()); | ||
dropAndCreateDatabaseTables(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; | ||
} | ||
|
||
private SymmetricEngine createEngine(File propertiesFile) { | ||
return new SymmetricEngine("file:" + propertiesFile.getAbsolutePath(), null); | ||
} | ||
|
||
private void dropAndCreateDatabaseTables(SymmetricEngine engine) { | ||
DataSource ds = (DataSource) engine.getApplicationContext().getBean(Constants.DATA_SOURCE); | ||
try { | ||
IDbDialect dialect = (IDbDialect) engine.getApplicationContext().getBean(Constants.DB_DIALECT); | ||
Platform platform = dialect.getPlatform(); | ||
Database testDb = getTestDatabase(); | ||
platform.dropTables(testDb, true); | ||
dialect.purge(); | ||
|
||
new SqlScript(getResource(TestConstants.TEST_DROP_ALL_SCRIPT), ds, false).execute(); | ||
|
||
// might want to come up with a slicker way to do db specific drop/create | ||
if (dialect instanceof OracleDbDialect) { | ||
new SqlScript(getResource(TestConstants.TEST_DROP_SEQ_SCRIPT), ds, false).execute(); | ||
} | ||
|
||
platform.createTables(testDb, false, true); | ||
|
||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private Database getTestDatabase() throws IOException { | ||
return new DatabaseIO().read(new InputStreamReader(getResource("/test-tables-ddl.xml").openStream())); | ||
} | ||
|
||
private URL getResource(String resource) { | ||
return SymmetricEngineTestFactory.class.getResource(resource); | ||
} | ||
|
||
} |
23 changes: 0 additions & 23 deletions
23
symmetric/src/test/java/org/jumpmind/symmetric/DatabaseTest.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
symmetric/src/test/java/org/jumpmind/symmetric/ITestable.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.