com.crosstreelabs.testing.DataSourceResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testing Show documentation
Show all versions of testing Show documentation
A collection of utilities used during unit and integration testing.
package com.crosstreelabs.testing;
import javax.sql.DataSource;
import org.hsqldb.jdbc.JDBCDataSource;
import org.junit.rules.ExternalResource;
/**
*
*/
public class DataSourceResource extends ExternalResource {
public static DataSource datasource;
//~ ExternalResource implementation ~~~~~~~~~~~~~~~~~~~~
@Override
protected void before() throws Throwable {
if(datasource == null) {
datasource = new JDBCDataSource();
((JDBCDataSource)datasource).setUrl("jdbc:hsqldb:mem:"+getSchema());
((JDBCDataSource)datasource).setUser("SA");
}
}
@Override
protected void after() {
datasource = null;
}
//~ Datasource necessities ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public String getSchema() {
return "PUBLIC";
}
public DataSource getDataSource() {
return datasource;
}
}