Package org.dbunit
Class DataSourceDatabaseTester
java.lang.Object
org.dbunit.assertion.SimpleAssert
org.dbunit.AbstractDatabaseTester
org.dbunit.DataSourceDatabaseTester
- All Implemented Interfaces:
IDatabaseTester
DatabaseTester that uses a
DataSource to create connections.- Since:
- 2.2.0
- Version:
- $Revision$ $Date$
- Author:
- Andres Almiray (aalmiray@users.sourceforge.net), Felipe Leme (dbunit@felipeal.net), Last changed by: $Author$
-
Constructor Summary
ConstructorsConstructorDescriptionDataSourceDatabaseTester(DataSource dataSource) Creates a new DataSourceDatabaseTester with the specified DataSource.DataSourceDatabaseTester(DataSource dataSource, String schema) Creates a new DataSourceDatabaseTester with the specified DataSource and schema name.DataSourceDatabaseTester(DataSource dataSource, String schema, CachingConnectionProvider connectionProvider) Creates a new DataSourceDatabaseTester with the specified DataSource and schema name, reusing oneIDatabaseConnectionacross calls via the givenCachingConnectionProviderinstead of creating a new one on every call.
Share the sameconnectionProviderinstance across the testers created for each test to get reuse across test methods; pair it withIOperationListener.NO_OP_OPERATION_LISTENER(or an equivalent non-closing listener) so the cached connection is not closed after everyAbstractDatabaseTester.onSetup()/AbstractDatabaseTester.onTearDown()call.DataSourceDatabaseTester(DataSource dataSource, String schema, CachingConnectionProvider connectionProvider, DatabaseConfig databaseConfig) Creates a new DataSourceDatabaseTester with the specified DataSource, schema name, optionalCachingConnectionProvider, and optionalDatabaseConfigwhose property and feature values are applied to every connection this tester creates - for example to setDatabaseConfig.PROPERTY_DATATYPE_FACTORYfor a specific database without needing anIOperationListener. -
Method Summary
Modifier and TypeMethodDescriptionReturns the test database connection.Methods inherited from class org.dbunit.AbstractDatabaseTester
closeConnection, getDataSet, getSchema, getSetUpOperation, getTearDownOperation, onSetup, onTearDown, setDataSet, setOperationListener, setSchema, setSetUpOperation, setTearDownOperation, toStringMethods inherited from class org.dbunit.assertion.SimpleAssert
assertNotNull, assertNotNull, assertNotNullNorEmpty, assertTrue, assertTrue, fail
-
Constructor Details
-
DataSourceDatabaseTester
Creates a new DataSourceDatabaseTester with the specified DataSource.- Parameters:
dataSource- the DataSource to pull connections from
-
DataSourceDatabaseTester
Creates a new DataSourceDatabaseTester with the specified DataSource and schema name.- Parameters:
dataSource- the DataSource to pull connections fromschema- The schema name to be used for new dbunit connections- Since:
- 2.4.5
-
DataSourceDatabaseTester
public DataSourceDatabaseTester(DataSource dataSource, String schema, CachingConnectionProvider connectionProvider) Creates a new DataSourceDatabaseTester with the specified DataSource and schema name, reusing oneIDatabaseConnectionacross calls via the givenCachingConnectionProviderinstead of creating a new one on every call.
Share the sameconnectionProviderinstance across the testers created for each test to get reuse across test methods; pair it withIOperationListener.NO_OP_OPERATION_LISTENER(or an equivalent non-closing listener) so the cached connection is not closed after everyAbstractDatabaseTester.onSetup()/AbstractDatabaseTester.onTearDown()call.- Parameters:
dataSource- the DataSource to pull connections fromschema- The schema name to be used for new dbunit connections - can benullconnectionProvider- caches and validates the connection across calls - can benull, in which case a new connection is created on every call as before- Since:
- 3.4.0
-
DataSourceDatabaseTester
public DataSourceDatabaseTester(DataSource dataSource, String schema, CachingConnectionProvider connectionProvider, DatabaseConfig databaseConfig) Creates a new DataSourceDatabaseTester with the specified DataSource, schema name, optionalCachingConnectionProvider, and optionalDatabaseConfigwhose property and feature values are applied to every connection this tester creates - for example to setDatabaseConfig.PROPERTY_DATATYPE_FACTORYfor a specific database without needing anIOperationListener.- Parameters:
dataSource- The DataSource to pull connections from.schema- The schema name to be used for new dbunit connections - can benull.connectionProvider- Caches and validates the connection across calls - can benull, in which case a new connection is created on every call as before.databaseConfig- The property and feature values to apply to every connection this tester creates - can benull, in which case each connection keeps its own defaultDatabaseConfig.- Since:
- 3.5.0
-
-
Method Details
-
getConnection
Description copied from interface:IDatabaseTesterReturns the test database connection.- Returns:
- the test database connection.
- Throws:
Exception- if the connection cannot be retrieved or created.
-