public class HsqlDbTestRule
extends org.junit.rules.ExternalResource
TestRule that creates a temporary file-based Hypersonic SQL
database during test execution and wraps a Commons-DBCP
BasicDataSource around it.
The developer can influence the temporary folder, where the database should
be created and/or can provide initial configuration logic for the used
BasicDataSource via a HsqlDbTestRule.DataSourceConfigurator.
Usage example:
public class HsqlDbTestRuleTest
{
@Rule
public HsqlDbTestRule _db = new HsqlDbTestRule();
@Test
public void test() throws SQLException
{
final Connection connection = _db.getConnection();
assertNotNull(connection);
// Do some DB operations
conneciton.close();
}
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
HsqlDbTestRule.DataSourceConfigurator
A command interface for providing custom configuration logic for the
internal
BasicDataSource. |
| Modifier and Type | Field and Description |
|---|---|
static String |
NAME_TEST_DB
The name of the temporary Hypersonic SQL database that is creating during
test runs.
|
| Constructor and Description |
|---|
HsqlDbTestRule()
Creates a new instance with no special configuration.
|
HsqlDbTestRule(File dbFolder)
Creates a new instance using the given
folder for the
internal database. |
HsqlDbTestRule(HsqlDbTestRule.DataSourceConfigurator configurator)
Creates a new instance using the given
HsqlDbTestRule.DataSourceConfigurator for
the internal database. |
HsqlDbTestRule(HsqlDbTestRule.DataSourceConfigurator configurator,
File dbFolder)
Creates a new instance using the given
HsqlDbTestRule.DataSourceConfigurator and
folder for the internal database. |
| Modifier and Type | Method and Description |
|---|---|
Connection |
getConnection()
Retrieves a new
Connection to the temporary Hypersonic SQL
database. |
File |
getDatabaseFolder()
Returns the folder where the test database is or will be created.
|
org.apache.commons.dbcp.BasicDataSource |
getDataSource()
Returns the
BasicDataSource representing the temporary Hypersonic
SQL database. |
void |
init() |
void |
shutdown() |
public static final String NAME_TEST_DB
public HsqlDbTestRule(HsqlDbTestRule.DataSourceConfigurator configurator, File dbFolder)
HsqlDbTestRule.DataSourceConfigurator and
folder for the internal database.configurator - a HsqlDbTestRule.DataSourceConfigurator for performing custom
configuration logic on the internal BasicDataSourcedbFolder - the temporary folder where the database should be set uppublic HsqlDbTestRule(HsqlDbTestRule.DataSourceConfigurator configurator)
HsqlDbTestRule.DataSourceConfigurator for
the internal database.configurator - a HsqlDbTestRule.DataSourceConfigurator for performing custom
configuration logic on the internal BasicDataSourcepublic HsqlDbTestRule(File dbFolder)
folder for the
internal database.dbFolder - the temporary folder where the database should be set uppublic HsqlDbTestRule()
public org.apache.commons.dbcp.BasicDataSource getDataSource()
BasicDataSource representing the temporary Hypersonic
SQL database.BasicDataSource representing the temporary Hypersonic
SQL databasepublic Connection getConnection() throws SQLException
Connection to the temporary Hypersonic SQL
database.Connection to the temporary Hypersonic SQL databaseSQLExceptionpublic File getDatabaseFolder()
public void shutdown()
Copyright © 2013. All Rights Reserved.