Search in sources :

Example 1 with RuntimeEnvironment

use of liquibase.RuntimeEnvironment in project liquibase by liquibase.

the class ChangeLogIteratorTest method runChangeSet_emptyFiltersIterator.

@Test
public void runChangeSet_emptyFiltersIterator() throws Exception {
    TestChangeSetVisitor testChangeLogVisitor = new TestChangeSetVisitor();
    ChangeLogIterator iterator = new ChangeLogIterator(changeLog);
    iterator.run(testChangeLogVisitor, new RuntimeEnvironment(null, null, null));
    assertEquals(6, testChangeLogVisitor.visitedChangeSets.size());
}
Also used : RuntimeEnvironment(liquibase.RuntimeEnvironment) Test(org.junit.Test)

Example 2 with RuntimeEnvironment

use of liquibase.RuntimeEnvironment in project liquibase by liquibase.

the class ChangeLogIteratorTest method runChangeSet_singleFilterIterator.

@Test
public void runChangeSet_singleFilterIterator() throws Exception {
    TestChangeSetVisitor testChangeLogVisitor = new TestChangeSetVisitor();
    ChangeLogIterator iterator = new ChangeLogIterator(changeLog, new ContextChangeSetFilter(new Contexts("test1")));
    iterator.run(testChangeLogVisitor, new RuntimeEnvironment(null, null, null));
    assertEquals(4, testChangeLogVisitor.visitedChangeSets.size());
}
Also used : RuntimeEnvironment(liquibase.RuntimeEnvironment) ContextChangeSetFilter(liquibase.changelog.filter.ContextChangeSetFilter) Contexts(liquibase.Contexts) Test(org.junit.Test)

Example 3 with RuntimeEnvironment

use of liquibase.RuntimeEnvironment in project liquibase by liquibase.

the class ChangeLogIteratorTest method runChangeSet_reverseVisitor.

@Test
public void runChangeSet_reverseVisitor() throws Exception {
    TestChangeSetVisitor testChangeLogVisitor = new ReverseChangeSetVisitor();
    ChangeLogIterator iterator = new ChangeLogIterator(changeLog, new ContextChangeSetFilter(new Contexts("test1")), new DbmsChangeSetFilter(new MySQLDatabase()));
    iterator.run(testChangeLogVisitor, new RuntimeEnvironment(null, null, null));
    assertEquals(3, testChangeLogVisitor.visitedChangeSets.size());
    assertEquals("5", testChangeLogVisitor.visitedChangeSets.get(0).getId());
    assertEquals("4", testChangeLogVisitor.visitedChangeSets.get(1).getId());
    assertEquals("1", testChangeLogVisitor.visitedChangeSets.get(2).getId());
}
Also used : RuntimeEnvironment(liquibase.RuntimeEnvironment) ContextChangeSetFilter(liquibase.changelog.filter.ContextChangeSetFilter) MySQLDatabase(liquibase.database.core.MySQLDatabase) DbmsChangeSetFilter(liquibase.changelog.filter.DbmsChangeSetFilter) Contexts(liquibase.Contexts) Test(org.junit.Test)

Example 4 with RuntimeEnvironment

use of liquibase.RuntimeEnvironment in project liquibase by liquibase.

the class DatabaseChangeLog method validate.

public void validate(Database database, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
    ChangeLogIterator logIterator = new ChangeLogIterator(this, new DbmsChangeSetFilter(database), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression));
    ValidatingVisitor validatingVisitor = new ValidatingVisitor(database.getRanChangeSetList());
    validatingVisitor.validate(database, this);
    logIterator.run(validatingVisitor, new RuntimeEnvironment(database, contexts, labelExpression));
    for (String message : validatingVisitor.getWarnings().getMessages()) {
        LogFactory.getLogger().warning(message);
    }
    if (!validatingVisitor.validationPassed()) {
        throw new ValidationFailedException(validatingVisitor);
    }
}
Also used : LabelChangeSetFilter(liquibase.changelog.filter.LabelChangeSetFilter) ValidatingVisitor(liquibase.changelog.visitor.ValidatingVisitor) RuntimeEnvironment(liquibase.RuntimeEnvironment) ValidationFailedException(liquibase.exception.ValidationFailedException) ContextChangeSetFilter(liquibase.changelog.filter.ContextChangeSetFilter) DbmsChangeSetFilter(liquibase.changelog.filter.DbmsChangeSetFilter)

Example 5 with RuntimeEnvironment

use of liquibase.RuntimeEnvironment in project liquibase by liquibase.

the class XMLChangeLogSAXParserTest method testIgnoreDuplicateChangeSets.

@Test
public void testIgnoreDuplicateChangeSets() throws ChangeLogParseException, Exception {
    XMLChangeLogSAXParser xmlParser = new XMLChangeLogSAXParser();
    DatabaseChangeLog changeLog = xmlParser.parse("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/master.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
    final List<ChangeSet> changeSets = new ArrayList<ChangeSet>();
    new ChangeLogIterator(changeLog).run(new ChangeSetVisitor() {

        @Override
        public Direction getDirection() {
            return Direction.FORWARD;
        }

        @Override
        public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
            changeSets.add(changeSet);
        }
    }, new RuntimeEnvironment(new MockDatabase(), new Contexts(), new LabelExpression()));
    Assert.assertEquals(8, changeSets.size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(0).toString());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(1).toString());
    Assert.assertEquals(1, changeSets.get(1).getContexts().getContexts().size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(2).toString());
    Assert.assertEquals(1, changeSets.get(2).getLabels().getLabels().size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(3).toString());
    Assert.assertEquals(2, changeSets.get(3).getLabels().getLabels().size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(4).toString());
    Assert.assertEquals(1, changeSets.get(4).getDbmsSet().size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog1.xml::1::testuser", changeSets.get(5).toString());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog3.xml::1::testuser", changeSets.get(6).toString());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog2.xml::1::testuser", changeSets.get(7).toString());
}
Also used : ChangeSetVisitor(liquibase.changelog.visitor.ChangeSetVisitor) RuntimeEnvironment(liquibase.RuntimeEnvironment) JUnitResourceAccessor(liquibase.test.JUnitResourceAccessor) ArrayList(java.util.ArrayList) Contexts(liquibase.Contexts) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) ChangeLogIterator(liquibase.changelog.ChangeLogIterator) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) MockDatabase(liquibase.sdk.database.MockDatabase) Database(liquibase.database.Database) LabelExpression(liquibase.LabelExpression) MockDatabase(liquibase.sdk.database.MockDatabase) LiquibaseException(liquibase.exception.LiquibaseException) ChangeSetFilterResult(liquibase.changelog.filter.ChangeSetFilterResult) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Aggregations

RuntimeEnvironment (liquibase.RuntimeEnvironment)6 Test (org.junit.Test)5 Contexts (liquibase.Contexts)4 ContextChangeSetFilter (liquibase.changelog.filter.ContextChangeSetFilter)4 DbmsChangeSetFilter (liquibase.changelog.filter.DbmsChangeSetFilter)3 MySQLDatabase (liquibase.database.core.MySQLDatabase)2 ArrayList (java.util.ArrayList)1 LabelExpression (liquibase.LabelExpression)1 ChangeLogIterator (liquibase.changelog.ChangeLogIterator)1 ChangeLogParameters (liquibase.changelog.ChangeLogParameters)1 ChangeSet (liquibase.changelog.ChangeSet)1 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)1 ChangeSetFilterResult (liquibase.changelog.filter.ChangeSetFilterResult)1 LabelChangeSetFilter (liquibase.changelog.filter.LabelChangeSetFilter)1 ChangeSetVisitor (liquibase.changelog.visitor.ChangeSetVisitor)1 ValidatingVisitor (liquibase.changelog.visitor.ValidatingVisitor)1 Database (liquibase.database.Database)1 LiquibaseException (liquibase.exception.LiquibaseException)1 ValidationFailedException (liquibase.exception.ValidationFailedException)1 MockDatabase (liquibase.sdk.database.MockDatabase)1