Skip to content

Instantly share code, notes, and snippets.

@mrserverless
Forked from thody/JdbiIntegrationTest.java
Last active August 29, 2015 14:08
Show Gist options
  • Save mrserverless/b50b5b89bc1bad1fa556 to your computer and use it in GitHub Desktop.
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
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("");
}
}
@esiqveland
Copy link

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment