-
-
Save mrserverless/b50b5b89bc1bad1fa556 to your computer and use it in GitHub Desktop.
Dropwizard JDBI Integration Test slightly more simplified and upgraded to Dropwizard version 0.7.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class JdbiIntegrationTest { | |
protected DBI dbi; | |
private Handle handle; | |
private Liquibase liquibase; | |
protected abstract DataSourceFactory getDataSourceFactory(); | |
protected abstract void setUpDataAccessObjects(); | |
@Before | |
public void setUpDatabase() throws Exception { | |
Environment environment = new Environment( "test-env", Jackson.newObjectMapper(), null, new MetricRegistry(), null ); | |
dbi = new DBIFactory().build( environment, getDataSourceFactory(), "test" ); | |
handle = dbi.open(); | |
migrateDatabase(); | |
setUpDataAccessObjects(); | |
} | |
@After | |
public void tearDown() throws Exception { | |
liquibase.dropAll(); | |
handle.close(); | |
} | |
private void migrateDatabase() throws LiquibaseException { | |
liquibase = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(handle.getConnection())); | |
liquibase.update(""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this!