Package org.dbunit
Class JdbcDatabaseTester
java.lang.Object
org.dbunit.assertion.SimpleAssert
org.dbunit.AbstractDatabaseTester
org.dbunit.JdbcDatabaseTester
- All Implemented Interfaces:
IDatabaseTester
- Direct Known Subclasses:
PropertiesBasedJdbcDatabaseTester
DatabaseTester that uses JDBC's Driver Manager to create connections.
- Since:
- 2.2
- Version:
- $Revision$
- Author:
- Andres Almiray (aalmiray@users.sourceforge.net), Felipe Leme (dbunit@felipeal.net)
-
Constructor Summary
ConstructorsConstructorDescriptionJdbcDatabaseTester(String driverClass, String connectionUrl) Creates a new JdbcDatabaseTester with the specified properties.
Username and Password are set to null.JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password) Creates a new JdbcDatabaseTester with the specified properties.JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password, String schema) Creates a new JdbcDatabaseTester with the specified properties.JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password, String schema, CachingConnectionProvider connectionProvider) Creates a new JdbcDatabaseTester with the specified properties, 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. -
Method Summary
Modifier and TypeMethodDescriptionReturns the test database connection.booleanReturns whethergetConnection()hands out one connection, cached by theCachingConnectionProviderthis tester was built with, instead of creating a new connection on every call.toString()Methods inherited from class org.dbunit.AbstractDatabaseTester
closeConnection, getDataSet, getOperationListener, getSchema, getSetUpOperation, getTearDownOperation, onSetup, onTearDown, setDataSet, setOperationListener, setSchema, setSetUpOperation, setTearDownOperationMethods inherited from class org.dbunit.assertion.SimpleAssert
assertNotNull, assertNotNull, assertNotNullNorEmpty, assertTrue, assertTrue, fail
-
Constructor Details
-
JdbcDatabaseTester
Creates a new JdbcDatabaseTester with the specified properties.
Username and Password are set to null.- Parameters:
driverClass- the classname of the JDBC driver to useconnectionUrl- the connection url- Throws:
ClassNotFoundException- If the givendriverClasswas not found
-
JdbcDatabaseTester
public JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password) throws ClassNotFoundException Creates a new JdbcDatabaseTester with the specified properties.- Parameters:
driverClass- the classname of the JDBC driver to useconnectionUrl- the connection urlusername- a username that can has access to the databasepassword- the user's password- Throws:
ClassNotFoundException- If the givendriverClasswas not found
-
JdbcDatabaseTester
public JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password, String schema) throws ClassNotFoundException Creates a new JdbcDatabaseTester with the specified properties.- Parameters:
driverClass- the classname of the JDBC driver to useconnectionUrl- the connection urlusername- a username that can has access to the database - can benullpassword- the user's password - can benullschema- the database schema to be tested - can benull- Throws:
ClassNotFoundException- If the givendriverClasswas not found- Since:
- 2.4.3
-
JdbcDatabaseTester
public JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password, String schema, CachingConnectionProvider connectionProvider) throws ClassNotFoundException Creates a new JdbcDatabaseTester with the specified properties, 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:
driverClass- the classname of the JDBC driver to useconnectionUrl- the connection urlusername- a username that can has access to the database - can benullpassword- the user's password - can benullschema- the database schema to be tested - can benullconnectionProvider- caches and validates the connection across calls - can benull, in which case a new connection is created on every call as before- Throws:
ClassNotFoundException- If the givendriverClasswas not found- Since:
- 3.4.0
-
-
Method Details
-
isReusingConnection
public boolean isReusingConnection()Returns whethergetConnection()hands out one connection, cached by theCachingConnectionProviderthis tester was built with, instead of creating a new connection on every call. A caller that leaves a connection open for its owner to close can rely on a tester that reuses its connection; with one that creates a new connection on every call, nothing closes the connection left open.A subclass that overrides
getConnection()to reuse a connection overrides this method to say so.- Returns:
truewhen this tester was built with aCachingConnectionProvider.- Since:
- 3.6.0
-
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.
-
toString
- Overrides:
toStringin classAbstractDatabaseTester
-