dadrus / jpa-unit

JUnit extension to test javax.persistence entities
Apache License 2.0
29 stars 9 forks source link

Add support for Liquibase changelogs #2

Closed dadrus closed 7 years ago

dadrus commented 7 years ago

Liquibase (http://www.liquibase.org) is a powerful tool which enables versioning control for the DB schema and contents. Adding support for it would give more added value to the test extension.

dadrus commented 7 years ago

Actually already supported by a corresponding implementation of a bootstrapping method (see below). Dedicated annotations might however be helpful.

@RunWith(JpaUnitRunner.class)
public class FlywaydbTest {

    @PersistenceContext(unitName = "my-verification-unit")
    private EntityManager manager;

    @Bootstrapping
    public static void prepareDataBase(final DataSource ds) throws Exception {
        final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(ds.getConnection()));
        final Liquibase liquibase = new Liquibase("changelog/changelog.xml", new ClassLoaderResourceAccessor(), database);
        liquibase.dropAll();
        liquibase.update((String) null);
    }

    @Test
    public void someTest() {
        // test code here
    }
}
dadrus commented 7 years ago

Since the desired functionality is already supported using the @Bootstrapping method, the ticket is closed.