001: package liquibase.database.sql;
002:
003: import liquibase.database.Database;
004: import liquibase.database.DerbyDatabase;
005: import liquibase.database.MSSQLDatabase;
006: import liquibase.database.structure.DatabaseSnapshot;
007: import liquibase.test.DatabaseTest;
008: import liquibase.test.DatabaseTestTemplate;
009: import liquibase.test.SqlStatementDatabaseTest;
010: import liquibase.test.TestContext;
011: import static org.junit.Assert.*;
012: import org.junit.Test;
013:
014: public class DropColumnStatementTest extends AbstractSqlStatementTest {
015:
016: private static final String TABLE_NAME = "DropColumnTest";
017: private static final String COLUMN_NAME = "testCol";
018:
019: protected void setupDatabase(Database database) throws Exception {
020: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
021: .addPrimaryKeyColumn("id", "int").addColumn(
022: COLUMN_NAME, "varchar(50)"), database);
023:
024: dropAndCreateTable(new CreateTableStatement(
025: TestContext.ALT_SCHEMA, TABLE_NAME)
026: .addPrimaryKeyColumn("id", "int").addColumn(
027: COLUMN_NAME, "varchar(50)"), database);
028: }
029:
030: @Test
031: public void supportsDatabase() throws Exception {
032: new DatabaseTestTemplate()
033: .testOnAllDatabases(new DatabaseTest() {
034: public void performTest(Database database)
035: throws Exception {
036: if (database instanceof DerbyDatabase) {
037: assertFalse(generateTestStatement()
038: .supportsDatabase(database));
039: } else {
040: assertTrue(generateTestStatement()
041: .supportsDatabase(database));
042: }
043: }
044: });
045: }
046:
047: protected DropColumnStatement generateTestStatement() {
048: return new DropColumnStatement(null, null, null);
049: }
050:
051: @Test
052: public void execute_defaultSchema() throws Exception {
053: new DatabaseTestTemplate()
054: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
055: null, new DropColumnStatement(null, TABLE_NAME,
056: COLUMN_NAME)) {
057:
058: protected boolean supportsTest(Database database) {
059: return !(database instanceof MSSQLDatabase); //for some reason, the metadata isn't updated by mssql
060: }
061:
062: protected void preExecuteAssert(
063: DatabaseSnapshot snapshot) {
064: assertNotNull(snapshot.getTable(TABLE_NAME)
065: .getColumn(COLUMN_NAME));
066: }
067:
068: protected void postExecuteAssert(
069: DatabaseSnapshot snapshot) {
070: assertNull(snapshot.getTable(TABLE_NAME)
071: .getColumn(COLUMN_NAME));
072: }
073:
074: });
075: }
076:
077: @Test
078: public void execute_altSchema() throws Exception {
079: new DatabaseTestTemplate()
080: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
081: TestContext.ALT_SCHEMA,
082: new DropColumnStatement(TestContext.ALT_SCHEMA,
083: TABLE_NAME, COLUMN_NAME)) {
084:
085: protected void preExecuteAssert(
086: DatabaseSnapshot snapshot) {
087: assertNotNull(snapshot.getTable(TABLE_NAME)
088: .getColumn(COLUMN_NAME));
089: }
090:
091: protected void postExecuteAssert(
092: DatabaseSnapshot snapshot) {
093: assertNull(snapshot.getTable(TABLE_NAME)
094: .getColumn(COLUMN_NAME));
095: }
096:
097: });
098:
099: }
100: }
|