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 DropIndexStatementTest extends AbstractSqlStatementTest {
13: private static final String TABLE_NAME = "DropIndexTest";
14: private static final String COLUMN_NAME = "colName";
15: private static final String IDX_NAME = "idx_dropindextest";
16: private static final String ALT_IDX_NAME = "idx_altdindextest";
17:
18: protected void setupDatabase(Database database) throws Exception {
19: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
20: .addPrimaryKeyColumn("id", "int").addColumn(
21: COLUMN_NAME, "varchar(50)",
22: new NotNullConstraint()), database);
23:
24: new JdbcTemplate(database).execute(new CreateIndexStatement(
25: IDX_NAME, null, TABLE_NAME, COLUMN_NAME));
26:
27: dropAndCreateTable(new CreateTableStatement(
28: TestContext.ALT_SCHEMA, TABLE_NAME)
29: .addPrimaryKeyColumn("id", "int").addColumn(
30: COLUMN_NAME, "varchar(50)",
31: new NotNullConstraint()), database);
32:
33: if (database.supportsSchemas()) {
34: new JdbcTemplate(database)
35: .execute(new CreateIndexStatement(ALT_IDX_NAME,
36: TestContext.ALT_SCHEMA, TABLE_NAME,
37: COLUMN_NAME));
38: }
39: }
40:
41: protected SqlStatement generateTestStatement() {
42: return new DropIndexStatement(null, null, null);
43: }
44:
45: @Test
46: public void execute_defaultSchema() throws Exception {
47: new DatabaseTestTemplate()
48: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
49: null, new DropIndexStatement(IDX_NAME, null,
50: TABLE_NAME)) {
51:
52: protected void preExecuteAssert(
53: DatabaseSnapshot snapshot) {
54: assertNotNull(snapshot.getIndex(IDX_NAME));
55: }
56:
57: protected void postExecuteAssert(
58: DatabaseSnapshot snapshot) {
59: assertNull(snapshot.getIndex(IDX_NAME));
60: }
61:
62: });
63: }
64:
65: //todo: issues with schemas on some databases
66: // @Test
67: // public void execute_altSchema() throws Exception {
68: // new DatabaseTestTemplate().testOnAvailableDatabases(
69: // new SqlStatementDatabaseTest(TestContext.ALT_SCHEMA, new DropIndexStatement(ALT_IDX_NAME, TestContext.ALT_SCHEMA, TABLE_NAME)) {
70: //
71: // protected void preExecuteAssert(DatabaseSnapshot snapshot) {
72: // //todo: how do we assert indexes within a schema snapshot?
73: //// assertNotNull(snapshot.getIndex(ALT_IDX_NAME));
74: // }
75: //
76: // protected void postExecuteAssert(DatabaseSnapshot snapshot) {
77: // //todo: how do we assert indexes within a schema snapshot?
78: //// assertNull(snapshot.getIndex(ALT_IDX_NAME));
79: // }
80: //
81: // });
82: // }
83: }
|