01: package liquibase.database.sql;
02:
03: import liquibase.database.Database;
04: import liquibase.database.structure.DatabaseSnapshot;
05: import liquibase.database.template.JdbcTemplate;
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 DropViewStatementTest extends AbstractSqlStatementTest {
13: private static final String VIEW_NAME = "DropViewTest";
14: private static final String TABLE_NAME = "DropViewTestTable";
15:
16: protected void setupDatabase(Database database) throws Exception {
17:
18: dropViewIfExists(null, VIEW_NAME, database);
19:
20: dropViewIfExists(TestContext.ALT_SCHEMA, VIEW_NAME, database);
21:
22: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
23: .addPrimaryKeyColumn("id", "int"), database);
24:
25: dropAndCreateTable(new CreateTableStatement(
26: TestContext.ALT_SCHEMA, TABLE_NAME)
27: .addPrimaryKeyColumn("id", "int"), database);
28:
29: new JdbcTemplate(database).execute(new CreateViewStatement(
30: null, VIEW_NAME, "select * from " + TABLE_NAME, false));
31:
32: if (database.supportsSchemas()) {
33: new JdbcTemplate(database).execute(new CreateViewStatement(
34: TestContext.ALT_SCHEMA, VIEW_NAME,
35: "select * from " + TestContext.ALT_SCHEMA + "."
36: + TABLE_NAME, false));
37: }
38: }
39:
40: protected SqlStatement generateTestStatement() {
41: return new DropViewStatement(null, null);
42: }
43:
44: @Test
45: public void execute_defaultSchema() throws Exception {
46: new DatabaseTestTemplate()
47: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
48: null, new DropViewStatement(null, VIEW_NAME)) {
49:
50: protected void preExecuteAssert(
51: DatabaseSnapshot snapshot) {
52: assertNotNull(snapshot.getView(VIEW_NAME));
53: }
54:
55: protected void postExecuteAssert(
56: DatabaseSnapshot snapshot) {
57: assertNull(snapshot.getView(VIEW_NAME));
58: }
59:
60: });
61: }
62:
63: @Test
64: public void execute_altSchema() throws Exception {
65: new DatabaseTestTemplate()
66: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
67: TestContext.ALT_SCHEMA, new DropViewStatement(
68: TestContext.ALT_SCHEMA, VIEW_NAME)) {
69:
70: protected void preExecuteAssert(
71: DatabaseSnapshot snapshot) {
72: assertNotNull(snapshot.getView(VIEW_NAME));
73: }
74:
75: protected void postExecuteAssert(
76: DatabaseSnapshot snapshot) {
77: assertNull(snapshot.getView(VIEW_NAME));
78: }
79:
80: });
81: }
82:
83: }
|