001: package liquibase.database.sql;
002:
003: import liquibase.database.CacheDatabase;
004: import liquibase.database.Database;
005: import liquibase.database.FirebirdDatabase;
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 RenameTableStatementTest extends AbstractSqlStatementTest {
015: private static final String TABLE_NAME = "RenameColumnTest";
016: private static final String NEW_TABLE_NAME = "RenameColumnTest_new";
017:
018: protected void setupDatabase(Database database) throws Exception {
019:
020: dropTableIfExists(null, NEW_TABLE_NAME, database);
021: dropTableIfExists(TestContext.ALT_SCHEMA, NEW_TABLE_NAME,
022: database);
023:
024: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
025: .addPrimaryKeyColumn("id", "int"), database);
026:
027: dropAndCreateTable(new CreateTableStatement(
028: TestContext.ALT_SCHEMA, TABLE_NAME)
029: .addPrimaryKeyColumn("id", "int"), database);
030: }
031:
032: protected SqlStatement generateTestStatement() {
033: return new RenameTableStatement(null, null, null);
034: }
035:
036: @Test
037: public void execute_defaultSchema() throws Exception {
038: new DatabaseTestTemplate()
039: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
040: null, new RenameTableStatement(null,
041: TABLE_NAME, NEW_TABLE_NAME)) {
042:
043: protected void preExecuteAssert(
044: DatabaseSnapshot snapshot) {
045: assertNotNull(snapshot.getTable(TABLE_NAME));
046: assertNull(snapshot.getTable(NEW_TABLE_NAME));
047: }
048:
049: protected void postExecuteAssert(
050: DatabaseSnapshot snapshot) {
051: assertNull(snapshot.getTable(TABLE_NAME));
052: assertNotNull(snapshot.getTable(NEW_TABLE_NAME));
053: }
054:
055: });
056: }
057:
058: @Test
059: public void execute_altSchema() throws Exception {
060: new DatabaseTestTemplate()
061: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
062: TestContext.ALT_SCHEMA,
063: new RenameTableStatement(
064: TestContext.ALT_SCHEMA, TABLE_NAME,
065: NEW_TABLE_NAME)) {
066:
067: protected void preExecuteAssert(
068: DatabaseSnapshot snapshot) {
069: assertNotNull(snapshot.getTable(TABLE_NAME));
070: assertNull(snapshot.getTable(NEW_TABLE_NAME));
071: }
072:
073: protected void postExecuteAssert(
074: DatabaseSnapshot snapshot) {
075: assertNull(snapshot.getTable(TABLE_NAME));
076: assertNotNull(snapshot.getTable(NEW_TABLE_NAME));
077: }
078:
079: });
080: }
081:
082: @Test
083: public void supportsDatabase() throws Exception {
084: new DatabaseTestTemplate()
085: .testOnAllDatabases(new DatabaseTest() {
086: public void performTest(Database database)
087: throws Exception {
088:
089: if (database instanceof CacheDatabase
090: || database instanceof FirebirdDatabase) {
091: assertFalse(generateTestStatement()
092: .supportsDatabase(database));
093: } else {
094: assertTrue(generateTestStatement()
095: .supportsDatabase(database));
096: }
097: }
098: });
099: }
100:
101: }
|