01: package liquibase.database.sql;
02:
03: import liquibase.database.Database;
04: import liquibase.database.DerbyDatabase;
05: import liquibase.database.structure.DatabaseSnapshot;
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 DropDefaultValueStatementTest extends
13: AbstractSqlStatementTest {
14: private static final String TABLE_NAME = "DropDefaultTest";
15: private static final String COLUMN_NAME = "testCol";
16:
17: protected void setupDatabase(Database database) throws Exception {
18: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
19: .addPrimaryKeyColumn("id", "int").addColumn(
20: COLUMN_NAME, "varchar(50)", "'Def Value'"),
21: database);
22:
23: dropAndCreateTable(new CreateTableStatement(
24: TestContext.ALT_SCHEMA, TABLE_NAME)
25: .addPrimaryKeyColumn("id", "int").addColumn(
26: COLUMN_NAME, "varchar(50)", "'Def Value'"),
27: database);
28: }
29:
30: protected DropDefaultValueStatement generateTestStatement() {
31: return new DropDefaultValueStatement(null, null, null);
32: }
33:
34: @Test
35: public void execute_defaultSchema() throws Exception {
36: new DatabaseTestTemplate()
37: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
38: null, new DropDefaultValueStatement(null,
39: TABLE_NAME, COLUMN_NAME)) {
40:
41: protected boolean supportsTest(Database database) {
42: return !(database instanceof DerbyDatabase);
43: }
44:
45: protected void preExecuteAssert(
46: DatabaseSnapshot snapshot) {
47: assertNotNull(snapshot.getTable(TABLE_NAME)
48: .getColumn(COLUMN_NAME)
49: .getDefaultValue());
50: }
51:
52: protected void postExecuteAssert(
53: DatabaseSnapshot snapshot) {
54: assertNull(snapshot.getTable(TABLE_NAME)
55: .getColumn(COLUMN_NAME)
56: .getDefaultValue());
57: }
58:
59: });
60: }
61:
62: @Test
63: public void execute_altSchema() throws Exception {
64: new DatabaseTestTemplate()
65: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
66: TestContext.ALT_SCHEMA,
67: new DropDefaultValueStatement(
68: TestContext.ALT_SCHEMA, TABLE_NAME,
69: COLUMN_NAME)) {
70:
71: protected boolean supportsTest(Database database) {
72: return !(database instanceof DerbyDatabase);
73: }
74:
75: protected void preExecuteAssert(
76: DatabaseSnapshot snapshot) {
77: assertNotNull(snapshot.getTable(TABLE_NAME)
78: .getColumn(COLUMN_NAME)
79: .getDefaultValue());
80: }
81:
82: protected void postExecuteAssert(
83: DatabaseSnapshot snapshot) {
84: assertNull(snapshot.getTable(TABLE_NAME)
85: .getColumn(COLUMN_NAME)
86: .getDefaultValue());
87: }
88: });
89: }
90: }
|