Search in sources :

Example 6 with RanChangeSet

use of liquibase.changelog.RanChangeSet in project liquibase by liquibase.

the class ValidatingVisitorPreConditionsTest method testPreconditionForOracleOnOracleWithChangeLog.

/**
     * Test against oracle, but I don't know for sure if the precondition is really
     * validated because oracle supports creating sequences.
     */
@Test
public void testPreconditionForOracleOnOracleWithChangeLog() {
    // create the pre condition
    PreconditionContainer preCondition = new PreconditionContainer();
    preCondition.setOnFail(PreconditionContainer.FailOption.MARK_RAN.toString());
    DBMSPrecondition dbmsPrecondition = new DBMSPrecondition();
    dbmsPrecondition.setType("oracle");
    preCondition.addNestedPrecondition(dbmsPrecondition);
    changeSet1.setPreconditions(preCondition);
    OracleDatabase oracleDb = new OracleDatabase() {

        @Override
        public List<RanChangeSet> getRanChangeSetList() throws DatabaseException {
            return new ArrayList<RanChangeSet>();
        }

        @Override
        public void rollback() throws DatabaseException {
        //super.rollback();
        }
    };
    String[] empty = {};
    boolean exceptionThrown = false;
    try {
        changeLog.validate(oracleDb, empty);
    } catch (LiquibaseException ex) {
        exceptionThrown = true;
    }
    assertFalse(exceptionThrown);
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) PreconditionContainer(liquibase.precondition.core.PreconditionContainer) DBMSPrecondition(liquibase.precondition.core.DBMSPrecondition) ArrayList(java.util.ArrayList) LiquibaseException(liquibase.exception.LiquibaseException) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 7 with RanChangeSet

use of liquibase.changelog.RanChangeSet in project liquibase by liquibase.

the class ValidatingVisitorTest method visit_successful.

@Test
public void visit_successful() throws Exception {
    CreateTableChange change1 = new CreateTableChange();
    change1.setTableName("table1");
    ColumnConfig column1 = new ColumnConfig();
    change1.addColumn(column1);
    column1.setName("col1");
    column1.setType("int");
    CreateTableChange change2 = new CreateTableChange();
    change2.setTableName("table2");
    ColumnConfig column2 = new ColumnConfig();
    change2.addColumn(column2);
    column2.setName("col2");
    column2.setType("int");
    changeSet1.addChange(change1);
    changeSet2.addChange(change2);
    ValidatingVisitor handler = new ValidatingVisitor(new ArrayList<RanChangeSet>());
    handler.visit(changeSet1, new DatabaseChangeLog(), new MockDatabase(), null);
    handler.visit(changeSet2, new DatabaseChangeLog(), new MockDatabase(), null);
    assertTrue(handler.validationPassed());
}
Also used : ColumnConfig(liquibase.change.ColumnConfig) CreateTableChange(liquibase.change.core.CreateTableChange) MockDatabase(liquibase.sdk.database.MockDatabase) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 8 with RanChangeSet

use of liquibase.changelog.RanChangeSet in project liquibase by liquibase.

the class ValidatingVisitorTest method visit_torunOnly.

@Test
public void visit_torunOnly() throws Exception {
    changeSet1.addChange(new CreateTableChange() {

        @Override
        public ValidationErrors validate(Database database) {
            ValidationErrors changeValidationErrors = new ValidationErrors();
            changeValidationErrors.addError("Test message");
            return changeValidationErrors;
        }
    });
    List<RanChangeSet> ran = new ArrayList<RanChangeSet>();
    ran.add(new RanChangeSet(changeSet1));
    ValidatingVisitor handler = new ValidatingVisitor(ran);
    handler.visit(changeSet1, new DatabaseChangeLog(), null, null);
    assertEquals(0, handler.getSetupExceptions().size());
    assertTrue(handler.validationPassed());
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors) CreateTableChange(liquibase.change.core.CreateTableChange) MockDatabase(liquibase.sdk.database.MockDatabase) Database(liquibase.database.Database) ArrayList(java.util.ArrayList) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 9 with RanChangeSet

use of liquibase.changelog.RanChangeSet in project liquibase by liquibase.

the class ValidatingVisitorTest method visit_setupException.

@Test
public void visit_setupException() throws Exception {
    changeSet1.addChange(new CreateTableChange() {

        @Override
        public void finishInitialization() throws SetupException {
            throw new SetupException("Test message");
        }
    });
    ValidatingVisitor handler = new ValidatingVisitor(new ArrayList<RanChangeSet>());
    handler.visit(changeSet1, new DatabaseChangeLog(), null, null);
    assertEquals(1, handler.getSetupExceptions().size());
    assertEquals("Test message", handler.getSetupExceptions().get(0).getMessage());
    assertFalse(handler.validationPassed());
}
Also used : SetupException(liquibase.exception.SetupException) CreateTableChange(liquibase.change.core.CreateTableChange) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 10 with RanChangeSet

use of liquibase.changelog.RanChangeSet in project liquibase by liquibase.

the class ValidatingVisitorTest method visit_duplicate.

@Test
public void visit_duplicate() throws Exception {
    ValidatingVisitor handler = new ValidatingVisitor(new ArrayList<RanChangeSet>());
    handler.visit(changeSet1, new DatabaseChangeLog(), null, null);
    handler.visit(changeSet1, new DatabaseChangeLog(), null, null);
    assertEquals(1, handler.getDuplicateChangeSets().size());
    assertFalse(handler.validationPassed());
}
Also used : DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Aggregations

RanChangeSet (liquibase.changelog.RanChangeSet)16 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)8 ChangeSet (liquibase.changelog.ChangeSet)5 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)5 Date (java.util.Date)4 CreateTableChange (liquibase.change.core.CreateTableChange)4 DBMSPrecondition (liquibase.precondition.core.DBMSPrecondition)3 PreconditionContainer (liquibase.precondition.core.PreconditionContainer)3 MockDatabase (liquibase.sdk.database.MockDatabase)3 Database (liquibase.database.Database)2 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)2 LiquibaseException (liquibase.exception.LiquibaseException)2 PreconditionErrorException (liquibase.exception.PreconditionErrorException)2 PreconditionFailedException (liquibase.exception.PreconditionFailedException)2 ValidationErrors (liquibase.exception.ValidationErrors)2 Change (liquibase.change.Change)1 ColumnConfig (liquibase.change.ColumnConfig)1 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)1 OracleDatabase (liquibase.database.core.OracleDatabase)1