Search in sources :

Example 1 with RanChangeSet

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

the class DatabaseUpgradeSupportTest method shouldRetrieveAllRanUpgrades.

@Test
public void shouldRetrieveAllRanUpgrades() throws Exception {
    RanChangeSet ranChangeSet1 = new RanChangeSet(changeSet1);
    RanChangeSet ranChangeSet2 = new RanChangeSet(changeSet2);
    when(database.getRanChangeSetList()).thenReturn(Arrays.asList(ranChangeSet1, ranChangeSet2));
    List<ChangeSetInfo> changeSets = databaseUpgradeSupport.listRanUpgrades();
    assertThat(changeSets, is(not(nullValue())));
    assertThat(changeSets.size(), is(2));
    verify(database).getRanChangeSetList();
}
Also used : RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 2 with RanChangeSet

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

the class ChangeSetExecutedPrecondition method check.

@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
    ObjectQuotingStrategy objectQuotingStrategy = null;
    if (changeSet == null) {
        objectQuotingStrategy = ObjectQuotingStrategy.LEGACY;
    } else {
        objectQuotingStrategy = changeSet.getObjectQuotingStrategy();
    }
    String changeLogFile = getChangeLogFile();
    if (changeLogFile == null) {
        changeLogFile = changeLog.getLogicalFilePath();
    }
    ChangeSet interestedChangeSet = new ChangeSet(getId(), getAuthor(), false, false, changeLogFile, null, null, false, objectQuotingStrategy, changeLog);
    RanChangeSet ranChangeSet;
    try {
        ranChangeSet = database.getRanChangeSet(interestedChangeSet);
    } catch (Exception e) {
        throw new PreconditionErrorException(e, changeLog, this);
    }
    if (ranChangeSet == null || ranChangeSet.getExecType() == null || !ranChangeSet.getExecType().ran) {
        throw new PreconditionFailedException("Change Set '" + interestedChangeSet.toString(false) + "' has not been run", changeLog, this);
    }
}
Also used : PreconditionFailedException(liquibase.exception.PreconditionFailedException) RanChangeSet(liquibase.changelog.RanChangeSet) ChangeSet(liquibase.changelog.ChangeSet) ObjectQuotingStrategy(liquibase.database.ObjectQuotingStrategy) PreconditionFailedException(liquibase.exception.PreconditionFailedException) PreconditionErrorException(liquibase.exception.PreconditionErrorException) RanChangeSet(liquibase.changelog.RanChangeSet) PreconditionErrorException(liquibase.exception.PreconditionErrorException)

Example 3 with RanChangeSet

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

the class ExecutedAfterChangeSetFilterTest method accepts_nullDate.

@Test
public void accepts_nullDate() throws Exception {
    ArrayList<RanChangeSet> ranChanges = new ArrayList<RanChangeSet>();
    ranChanges.add(new RanChangeSet("path/changelog", "1", "testAuthor", CheckSum.parse("12345"), new Date(), null, null, null, null, null, null, null));
    ranChanges.add(new RanChangeSet("path/changelog", "2", "testAuthor", CheckSum.parse("12345"), null, null, null, null, null, null, null, null));
    ranChanges.add(new RanChangeSet("path/changelog", "3", "testAuthor", CheckSum.parse("12345"), new Date(), null, null, null, null, null, null, null));
    ExecutedAfterChangeSetFilter filter = new ExecutedAfterChangeSetFilter(new Date(), ranChanges);
    assertFalse(filter.accepts(new ChangeSet("1", "testAuthor", false, false, "path/changelog", null, null, null)).isAccepted());
}
Also used : ArrayList(java.util.ArrayList) RanChangeSet(liquibase.changelog.RanChangeSet) ChangeSet(liquibase.changelog.ChangeSet) Date(java.util.Date) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 4 with RanChangeSet

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

the class ExecutedAfterChangeSetFilterTest method accepts.

@Test
public void accepts() throws Exception {
    ArrayList<RanChangeSet> ranChanges = new ArrayList<RanChangeSet>();
    ranChanges.add(new RanChangeSet("path/changelog", "1", "testAuthor", CheckSum.parse("12345"), new Date(new Date().getTime() - 10 * 1000 * 60 * 60), null, null, null, null, null, null, null));
    ranChanges.add(new RanChangeSet("path/changelog", "2", "testAuthor", CheckSum.parse("12345"), new Date(new Date().getTime() - 8 * 1000 * 60 * 60), null, null, null, null, null, null, null));
    ranChanges.add(new RanChangeSet("path/changelog", "3", "testAuthor", CheckSum.parse("12345"), new Date(new Date().getTime() - 4 * 1000 * 60 * 60), null, null, null, null, null, null, null));
    ExecutedAfterChangeSetFilter filter = new ExecutedAfterChangeSetFilter(new Date(new Date().getTime() - 6 * 1000 * 60 * 60), ranChanges);
    assertFalse(filter.accepts(new ChangeSet("1", "testAuthor", false, false, "path/changelog", null, null, null)).isAccepted());
    assertFalse(filter.accepts(new ChangeSet("2", "testAuthor", false, false, "path/changelog", null, null, null)).isAccepted());
    assertTrue(filter.accepts(new ChangeSet("3", "testAuthor", false, false, "path/changelog", null, null, null)).isAccepted());
}
Also used : ArrayList(java.util.ArrayList) RanChangeSet(liquibase.changelog.RanChangeSet) ChangeSet(liquibase.changelog.ChangeSet) Date(java.util.Date) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 5 with RanChangeSet

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

the class ExecutedAfterChangeSetFilterTest method accepts_noRan.

@Test
public void accepts_noRan() throws Exception {
    ExecutedAfterChangeSetFilter filter = new ExecutedAfterChangeSetFilter(new Date(), new ArrayList<RanChangeSet>());
    assertFalse(filter.accepts(new ChangeSet("1", "testAuthor", false, false, "path/changelog", null, null, null)).isAccepted());
}
Also used : RanChangeSet(liquibase.changelog.RanChangeSet) ChangeSet(liquibase.changelog.ChangeSet) Date(java.util.Date) 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