Search in sources :

Example 6 with MockSqlGeneratorChain

use of liquibase.sqlgenerator.MockSqlGeneratorChain in project liquibase by liquibase.

the class AddColumnGeneratorTest method isValid.

@Override
public void isValid() throws Exception {
    super.isValid();
    AddColumnStatement addPKColumn = new AddColumnStatement(null, null, TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, null, new PrimaryKeyConstraint("pk_name"));
    assertFalse(generatorUnderTest.validate(addPKColumn, new OracleDatabase(), new MockSqlGeneratorChain()).hasErrors());
    assertTrue(generatorUnderTest.validate(addPKColumn, new H2Database(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
    assertTrue(generatorUnderTest.validate(addPKColumn, new DB2Database(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
    assertTrue(generatorUnderTest.validate(addPKColumn, new DerbyDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
    assertTrue(generatorUnderTest.validate(addPKColumn, new SQLiteDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
    assertTrue(generatorUnderTest.validate(new AddColumnStatement(null, null, null, null, null, null, new AutoIncrementConstraint()), new MySQLDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a non-primary key identity column"));
    assertTrue(generatorUnderTest.validate(new AddColumnStatement(null, null, null, null, null, null, new AutoIncrementConstraint()), new MySQLDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a non-primary key identity column"));
    assertTrue(generatorUnderTest.validate(new AddColumnStatement(new AddColumnStatement(null, null, TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, null), new AddColumnStatement(null, null, "other_table", "other_column", COLUMN_TYPE, null)), new MySQLDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("All columns must be targeted at the same table"));
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) DB2Database(liquibase.database.core.DB2Database) AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) H2Database(liquibase.database.core.H2Database) AddColumnStatement(liquibase.statement.core.AddColumnStatement) PrimaryKeyConstraint(liquibase.statement.PrimaryKeyConstraint) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain)

Aggregations

MockSqlGeneratorChain (liquibase.sqlgenerator.MockSqlGeneratorChain)6 Test (org.junit.Test)5 MySQLDatabase (liquibase.database.core.MySQLDatabase)4 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)4 AddColumnStatement (liquibase.statement.core.AddColumnStatement)4 Sql (liquibase.sql.Sql)3 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)2 ChangeSet (liquibase.changelog.ChangeSet)1 DB2Database (liquibase.database.core.DB2Database)1 DerbyDatabase (liquibase.database.core.DerbyDatabase)1 H2Database (liquibase.database.core.H2Database)1 OracleDatabase (liquibase.database.core.OracleDatabase)1 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)1 ValidationErrors (liquibase.exception.ValidationErrors)1 MockDatabase (liquibase.sdk.database.MockDatabase)1 NotNullConstraint (liquibase.statement.NotNullConstraint)1 PrimaryKeyConstraint (liquibase.statement.PrimaryKeyConstraint)1 DropColumnStatement (liquibase.statement.core.DropColumnStatement)1 MarkChangeSetRanStatement (liquibase.statement.core.MarkChangeSetRanStatement)1