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