01: package liquibase.database.sql;
02:
03: import liquibase.database.*;
04: import liquibase.database.structure.DatabaseSnapshot;
05: import liquibase.exception.JDBCException;
06: import liquibase.test.DatabaseTestTemplate;
07: import liquibase.test.SqlStatementDatabaseTest;
08: import liquibase.test.TestContext;
09: import static org.junit.Assert.*;
10: import org.junit.Test;
11:
12: public class DropTableStatementTest extends AbstractSqlStatementTest {
13: private static final String TABLE_NAME = "DropTableTest";
14:
15: protected void setupDatabase(Database database) throws Exception {
16: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
17: .addPrimaryKeyColumn("id", "int"), database);
18:
19: dropAndCreateTable(new CreateTableStatement(
20: TestContext.ALT_SCHEMA, TABLE_NAME)
21: .addPrimaryKeyColumn("id", "int"), database);
22: }
23:
24: protected SqlStatement generateTestStatement() {
25: return new DropTableStatement(null, null, true);
26: }
27:
28: @Test
29: public void execute_defaultSchema() throws Exception {
30: new DatabaseTestTemplate()
31: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
32: null, new DropTableStatement(null, TABLE_NAME,
33: false)) {
34:
35: protected void preExecuteAssert(
36: DatabaseSnapshot snapshot) {
37: assertNotNull(snapshot.getTable(TABLE_NAME));
38: }
39:
40: protected void postExecuteAssert(
41: DatabaseSnapshot snapshot) {
42: assertNull(snapshot.getTable(TABLE_NAME));
43: }
44:
45: });
46: }
47:
48: @Test
49: public void execute_cascadeConstraints() throws Exception {
50: new DatabaseTestTemplate()
51: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
52: null, new DropTableStatement(null, TABLE_NAME,
53: true)) {
54:
55: protected boolean expectedException(
56: Database database, JDBCException exception) {
57: return database instanceof DerbyDatabase
58: || database instanceof DB2Database
59: || database instanceof FirebirdDatabase
60: || database instanceof MSSQLDatabase;
61: }
62:
63: protected void preExecuteAssert(
64: DatabaseSnapshot snapshot) {
65: assertNotNull(snapshot.getTable(TABLE_NAME));
66: }
67:
68: protected void postExecuteAssert(
69: DatabaseSnapshot snapshot) {
70: assertNull(snapshot.getTable(TABLE_NAME));
71: }
72:
73: });
74: }
75:
76: @Test
77: public void execute_altSchema() throws Exception {
78: new DatabaseTestTemplate()
79: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
80: TestContext.ALT_SCHEMA, new DropTableStatement(
81: TestContext.ALT_SCHEMA, TABLE_NAME,
82: false)) {
83:
84: protected void preExecuteAssert(
85: DatabaseSnapshot snapshot) {
86: assertNotNull(snapshot.getTable(TABLE_NAME));
87: }
88:
89: protected void postExecuteAssert(
90: DatabaseSnapshot snapshot) {
91: assertNull(snapshot.getTable(TABLE_NAME));
92: }
93:
94: });
95: }
96: }
|