Search in sources :

Example 1 with FlywayCallback

use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.

the class FlywayCallbackSmallTest method failingCallbackTest.

@Test(expected = IllegalStateException.class)
public void failingCallbackTest() {
    FlywayCallback failingCallback = new BaseFlywayCallback() {

        @Override
        public void beforeMigrate(Connection connection) {
            throw new IllegalStateException("Failing");
        }
    };
    final Flyway flyway = new Flyway();
    flyway.configure(createProperties("failing"));
    flyway.setCallbacks(failingCallback);
    assertNotNull(flyway.getDataSource());
    flyway.migrate();
}
Also used : FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) BaseFlywayCallback(org.flywaydb.core.api.callback.BaseFlywayCallback) BaseFlywayCallback(org.flywaydb.core.api.callback.BaseFlywayCallback) Connection(java.sql.Connection) Test(org.junit.Test)

Example 2 with FlywayCallback

use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.

the class FlywayCallbackSmallTest method baselineTest.

@Test
public void baselineTest() {
    Properties properties = createProperties("baseline");
    FlywayCallbackImpl callbackImpl = new FlywayCallbackImpl();
    FlywayCallback[] callbacks = new FlywayCallback[] { callbackImpl };
    final Flyway flyway = new Flyway();
    flyway.configure(properties);
    flyway.setCallbacks(callbacks);
    assertNotNull(flyway.getDataSource());
    assertFalse(callbackImpl.isBeforeBaseline());
    assertFalse(callbackImpl.isAfterBaseline());
    flyway.baseline();
    assertFalse(callbackImpl.isBeforeClean());
    assertFalse(callbackImpl.isAfterClean());
    assertFalse(callbackImpl.isAfterEachMigrate());
    assertFalse(callbackImpl.isAfterInfo());
    assertTrue(callbackImpl.isAfterBaseline());
    assertFalse(callbackImpl.isAfterMigrate());
    assertFalse(callbackImpl.isAfterRepair());
    assertFalse(callbackImpl.isAfterValidate());
    assertFalse(callbackImpl.isBeforeEachMigrate());
    assertFalse(callbackImpl.isBeforeInfo());
    assertTrue(callbackImpl.isBeforeBaseline());
    assertFalse(callbackImpl.isBeforeMigrate());
    assertFalse(callbackImpl.isBeforeRepair());
    assertFalse(callbackImpl.isBeforeValidate());
}
Also used : FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) BaseFlywayCallback(org.flywaydb.core.api.callback.BaseFlywayCallback) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with FlywayCallback

use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.

the class FlywayCallbackSmallTest method repairTest.

@Test
public void repairTest() {
    Properties properties = createProperties("repair");
    FlywayCallbackImpl callbackImpl = new FlywayCallbackImpl();
    FlywayCallback[] callbacks = new FlywayCallback[] { callbackImpl };
    final Flyway flyway = new Flyway();
    flyway.configure(properties);
    flyway.setCallbacks(callbacks);
    assertNotNull(flyway.getDataSource());
    assertFalse(callbackImpl.isBeforeRepair());
    assertFalse(callbackImpl.isAfterRepair());
    flyway.repair();
    assertFalse(callbackImpl.isBeforeClean());
    assertFalse(callbackImpl.isAfterClean());
    assertFalse(callbackImpl.isAfterEachMigrate());
    assertFalse(callbackImpl.isAfterInfo());
    assertFalse(callbackImpl.isAfterBaseline());
    assertFalse(callbackImpl.isAfterMigrate());
    assertTrue(callbackImpl.isAfterRepair());
    assertFalse(callbackImpl.isAfterValidate());
    assertFalse(callbackImpl.isBeforeEachMigrate());
    assertFalse(callbackImpl.isBeforeInfo());
    assertFalse(callbackImpl.isBeforeBaseline());
    assertFalse(callbackImpl.isBeforeMigrate());
    assertTrue(callbackImpl.isBeforeRepair());
    assertFalse(callbackImpl.isBeforeValidate());
}
Also used : FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) BaseFlywayCallback(org.flywaydb.core.api.callback.BaseFlywayCallback) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with FlywayCallback

use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.

the class FlywayCallbackSmallTest method infoTest.

@Test
public void infoTest() {
    Properties properties = createProperties("info");
    FlywayCallbackImpl callbackImpl = new FlywayCallbackImpl();
    FlywayCallback[] callbacks = new FlywayCallback[] { callbackImpl };
    final Flyway flyway = new Flyway();
    flyway.configure(properties);
    flyway.setCallbacks(callbacks);
    assertNotNull(flyway.getDataSource());
    assertFalse(callbackImpl.isBeforeInfo());
    assertFalse(callbackImpl.isAfterInfo());
    flyway.info();
    assertFalse(callbackImpl.isBeforeClean());
    assertFalse(callbackImpl.isAfterClean());
    assertFalse(callbackImpl.isAfterEachMigrate());
    assertTrue(callbackImpl.isAfterInfo());
    assertFalse(callbackImpl.isAfterBaseline());
    assertFalse(callbackImpl.isAfterMigrate());
    assertFalse(callbackImpl.isAfterRepair());
    assertFalse(callbackImpl.isAfterValidate());
    assertFalse(callbackImpl.isBeforeEachMigrate());
    assertTrue(callbackImpl.isBeforeInfo());
    assertFalse(callbackImpl.isBeforeBaseline());
    assertFalse(callbackImpl.isBeforeMigrate());
    assertFalse(callbackImpl.isBeforeRepair());
    assertFalse(callbackImpl.isBeforeValidate());
}
Also used : FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) BaseFlywayCallback(org.flywaydb.core.api.callback.BaseFlywayCallback) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with FlywayCallback

use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.

the class FlywayCallbackSmallTest method migrateEachTest.

@Test
public void migrateEachTest() {
    cleanTest();
    Properties properties = createProperties("migrate_each");
    FlywayCallbackImpl callbackImpl = new FlywayCallbackImpl();
    FlywayCallback[] callbacks = new FlywayCallback[] { callbackImpl };
    final Flyway flyway = new Flyway();
    flyway.configure(properties);
    flyway.setCallbacks(callbacks);
    assertNotNull(flyway.getDataSource());
    assertFalse(callbackImpl.isBeforeRepair());
    assertFalse(callbackImpl.isAfterRepair());
    flyway.migrate();
    assertFalse(callbackImpl.isBeforeClean());
    assertFalse(callbackImpl.isAfterClean());
    assertTrue(callbackImpl.isAfterEachMigrate());
    assertFalse(callbackImpl.isAfterInfo());
    assertFalse(callbackImpl.isAfterBaseline());
    assertTrue(callbackImpl.isAfterMigrate());
    assertFalse(callbackImpl.isAfterRepair());
    assertFalse(callbackImpl.isAfterValidate());
    assertTrue(callbackImpl.isBeforeEachMigrate());
    assertFalse(callbackImpl.isBeforeInfo());
    assertFalse(callbackImpl.isBeforeBaseline());
    assertTrue(callbackImpl.isBeforeMigrate());
    assertFalse(callbackImpl.isBeforeRepair());
    assertFalse(callbackImpl.isBeforeValidate());
}
Also used : FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) BaseFlywayCallback(org.flywaydb.core.api.callback.BaseFlywayCallback) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

FlywayCallback (org.flywaydb.core.api.callback.FlywayCallback)15 Test (org.junit.Test)10 Properties (java.util.Properties)8 BaseFlywayCallback (org.flywaydb.core.api.callback.BaseFlywayCallback)8 Connection (java.sql.Connection)5 MigrationResolver (org.flywaydb.core.api.resolver.MigrationResolver)3 DbSupport (org.flywaydb.core.internal.dbsupport.DbSupport)3 Schema (org.flywaydb.core.internal.dbsupport.Schema)3 MetaDataTable (org.flywaydb.core.internal.metadatatable.MetaDataTable)3 SqlScriptFlywayCallback (org.flywaydb.core.internal.callback.SqlScriptFlywayCallback)2 MigrationInfoServiceImpl (org.flywaydb.core.internal.info.MigrationInfoServiceImpl)2 CompositeMigrationResolver (org.flywaydb.core.internal.resolver.CompositeMigrationResolver)2 TransactionTemplate (org.flywaydb.core.internal.util.jdbc.TransactionTemplate)2 SQLException (java.sql.SQLException)1 LinkedHashSet (java.util.LinkedHashSet)1 Callable (java.util.concurrent.Callable)1 Flyway (org.flywaydb.core.Flyway)1 FlywayException (org.flywaydb.core.api.FlywayException)1 MigrationInfoService (org.flywaydb.core.api.MigrationInfoService)1 DbRepair (org.flywaydb.core.internal.command.DbRepair)1