01: package liquibase.database.sql;
02:
03: import liquibase.database.DB2Database;
04: import liquibase.database.Database;
05: import liquibase.database.structure.DatabaseSnapshot;
06: import liquibase.test.DatabaseTest;
07: import liquibase.test.DatabaseTestTemplate;
08: import liquibase.test.SqlStatementDatabaseTest;
09: import liquibase.test.TestContext;
10: import static org.junit.Assert.*;
11: import org.junit.Test;
12:
13: public class ReorganizeTableStatementTest extends
14: AbstractSqlStatementTest {
15: private static final String TABLE_NAME = "AddReorgTableTest";
16:
17: protected void setupDatabase(Database database) throws Exception {
18: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
19: .addColumn("existingCol", "int"), database);
20: dropAndCreateTable(new CreateTableStatement(
21: TestContext.ALT_SCHEMA, TABLE_NAME).addColumn(
22: "existingCol", "int"), database);
23: }
24:
25: protected SqlStatement generateTestStatement() {
26: return new ReorganizeTableStatement(null, null);
27: }
28:
29: @Test
30: public void supportsDatabase() throws Exception {
31: new DatabaseTestTemplate()
32: .testOnAllDatabases(new DatabaseTest() {
33: public void performTest(Database database)
34: throws Exception {
35: if (database instanceof DB2Database) {
36: assertTrue(new ReorganizeTableStatement(
37: null, null)
38: .supportsDatabase(database));
39: } else {
40: assertFalse(new ReorganizeTableStatement(
41: null, null)
42: .supportsDatabase(database));
43: }
44: }
45: });
46: }
47:
48: @Test
49: public void execute_noSchema() throws Exception {
50: new DatabaseTestTemplate()
51: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
52: null, new ReorganizeTableStatement(null,
53: TABLE_NAME)) {
54: protected void preExecuteAssert(
55: DatabaseSnapshot snapshot) {
56: ; //nothing to test
57: }
58:
59: protected void postExecuteAssert(
60: DatabaseSnapshot snapshot) {
61: ; //nothing to test
62: }
63: });
64: }
65:
66: @Test
67: public void execute_withSchema() throws Exception {
68: new DatabaseTestTemplate()
69: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
70: TestContext.ALT_SCHEMA,
71: new ReorganizeTableStatement(
72: TestContext.ALT_SCHEMA, TABLE_NAME)) {
73: protected void preExecuteAssert(
74: DatabaseSnapshot snapshot) {
75: ; //nothing to test
76: }
77:
78: protected void postExecuteAssert(
79: DatabaseSnapshot snapshot) {
80: ; //nothing to test
81: }
82: });
83: }
84: }
|