Consolidate flyway modules (#3319)
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
c52b2a4ff3
commit
91be3244f2
@@ -0,0 +1,68 @@
|
||||
package com.baeldung.flywaycallbacks;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@ContextConfiguration(classes = FlywayCallbackTestConfig.class)
|
||||
public class FlywayApplicationTest {
|
||||
|
||||
private Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void migrateWithNoCallbacks() {
|
||||
logTestBoundary("migrateWithNoCallbacks");
|
||||
Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
flyway.setLocations("db/migration");
|
||||
flyway.migrate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrateWithJavaCallbacks() {
|
||||
logTestBoundary("migrateWithJavaCallbacks");
|
||||
Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
flyway.setLocations("db/migration");
|
||||
flyway.setCallbacks(new ExampleFlywayCallback());
|
||||
flyway.migrate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrateWithSqlCallbacks() {
|
||||
logTestBoundary("migrateWithSqlCallbacks");
|
||||
Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
flyway.setLocations("db/migration", "db/callbacks");
|
||||
flyway.migrate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrateWithSqlAndJavaCallbacks() {
|
||||
logTestBoundary("migrateWithSqlAndJavaCallbacks");
|
||||
Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
flyway.setLocations("db/migration", "db/callbacks");
|
||||
flyway.setCallbacks(new ExampleFlywayCallback());
|
||||
flyway.migrate();
|
||||
}
|
||||
|
||||
private void logTestBoundary(String testName) {
|
||||
System.out.println("\n");
|
||||
log.info("> " + testName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.flywaycallbacks;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
@Configuration
|
||||
public class FlywayCallbackTestConfig {
|
||||
|
||||
@Bean
|
||||
public DataSource createDatasource() {
|
||||
EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
|
||||
return dbBuilder.setType(EmbeddedDatabaseType.H2)
|
||||
.setName("DATABASE")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user