Interface PrepAndExpectedTestCase
- All Known Implementing Classes:
DefaultPrepAndExpectedTestCase
- Since:
- 2.4.8
- Version:
- $Revision$ $Date$
- Author:
- Jeff Jensen jeffjensen AT users.sourceforge.net, Last changed by: $Author$
-
Method Summary
Modifier and TypeMethodDescriptionvoidCleanup tables specified in prep and expected datasets, using the provided databaseTester.default voidClear a previously set row count check override, returning to resolving it from this test case's connection's DatabaseConfig.default voidconfigureTest(PrepAndExpectedTestData testData) Configure the test from aPrepAndExpectedTestDatabundle instead of the three separate array arguments.voidconfigureTest(VerifyTableDefinition[] verifyTableDefinitions, String[] prepDataFiles, String[] expectedDataFiles) Configure the test.default IDatabaseTesterGet the databaseTester this test case uses.Get the expected dataset, created from the expectedDataFiles.Get the prep dataset, created from the prepDataFiles.default IDatabaseConnectionReturns the connection this test case's own steps use for the current test, resolving one fromgetDatabaseTester()first if it has not already.voidpostTest()Execute all post-test steps.voidpostTest(boolean verifyData) Execute post-test steps.voidpreTest()Execute pre-test steps.default voidpreTest(PrepAndExpectedTestData testData) Convenience method to call configureTest() and preTest(), taking aPrepAndExpectedTestDatabundle instead of the three separate array arguments.voidpreTest(VerifyTableDefinition[] verifyTables, String[] prepDataFiles, String[] expectedDataFiles) Convenience method to call configureTest() and preTest().default ObjectrunTest(PrepAndExpectedTestData testData, PrepAndExpectedTestCaseSteps testSteps) Run the DbUnit test from aPrepAndExpectedTestDatabundle instead of the three separate array arguments.runTest(VerifyTableDefinition[] verifyTables, String[] prepDataFiles, String[] expectedDataFiles, PrepAndExpectedTestCaseSteps testSteps) Run the DbUnit test.default voidsetCloseConnectionAfterTest(boolean closeConnectionAfterTest) Set whether this test case closes its connection after each test.default voidsetDatabaseConfigProperties(Properties databaseConfigProperties) Set DatabaseConfig property name/value pairs for this test case to apply to its connection.default voidsetDatabaseTester(IDatabaseTester databaseTester) Set the databaseTester this test case uses.default voidsetDataFileLoader(DataFileLoader dataFileLoader) Set theDataFileLoaderthis test case uses to load prepDataFiles/expectedDataFiles.default voidsetFailureHandler(FailureHandler failureHandler) Set theFailureHandlerthis test case hands verifyData()'s assertion failures to.default voidsetRowCountCheckOverride(boolean enabled, String[] exclude) Set the enabled flag and excluded table patterns this test case resolves its row count check from, instead of its connection's DatabaseConfig.voidFor the provided VerifyTableDefinitions, verify each table's actual results are as expected.
-
Method Details
-
configureTest
void configureTest(VerifyTableDefinition[] verifyTableDefinitions, String[] prepDataFiles, String[] expectedDataFiles) throws Exception Configure the test. Call this method before performing the test steps.- Parameters:
verifyTableDefinitions- Table definitions to verify after test execution.prepDataFiles- The prep data files (as classpath resources) to load and insert contents into the database as seed data.expectedDataFiles- The expected data files (as classpath resources) to load as expected data and verify actual data matches at test end.- Throws:
Exception- if the test cannot be configured.
-
configureTest
Configure the test from aPrepAndExpectedTestDatabundle instead of the three separate array arguments. Equivalent to callingconfigureTest(VerifyTableDefinition[], String[], String[])with the bundle's three values.- Parameters:
testData- The verification definitions and prep and expected data files for this test.- Throws:
Exception- If the test cannot be configured.- Since:
- 3.6.0
-
preTest
Execute pre-test steps. Call this method before performing the test steps.- Throws:
Exception- if the pre-test steps fail.
-
preTest
void preTest(VerifyTableDefinition[] verifyTables, String[] prepDataFiles, String[] expectedDataFiles) throws Exception Convenience method to call configureTest() and preTest().- Parameters:
verifyTables- Table definitions to verify after test execution.prepDataFiles- The prep data files (as classpath resources) to load and insert contents into the database as seed data.expectedDataFiles- The expected data files (as classpath resources) to load as expected data and verify actual data matches at test end.- Throws:
Exception- if the pre-test steps fail.
-
preTest
Convenience method to call configureTest() and preTest(), taking aPrepAndExpectedTestDatabundle instead of the three separate array arguments. Equivalent to callingpreTest(VerifyTableDefinition[], String[], String[])with the bundle's three values.- Parameters:
testData- The verification definitions and prep and expected data files for this test.- Throws:
Exception- If the pre-test steps fail.- Since:
- 3.6.0
-
runTest
Object runTest(VerifyTableDefinition[] verifyTables, String[] prepDataFiles, String[] expectedDataFiles, PrepAndExpectedTestCaseSteps testSteps) throws Exception Run the DbUnit test.- Parameters:
verifyTables- Table definitions to verify after test execution.prepDataFiles- The prep data files (as classpath resources) to load and insert contents into the database as seed data.expectedDataFiles- The expected data files (as classpath resources) to load as expected data and verify actual data matches at test end.testSteps- The test steps to run.- Returns:
- User defined object from running the test steps.
- Throws:
Exception- if the test steps fail.- Since:
- 2.5.2
-
runTest
default Object runTest(PrepAndExpectedTestData testData, PrepAndExpectedTestCaseSteps testSteps) throws Exception Run the DbUnit test from aPrepAndExpectedTestDatabundle instead of the three separate array arguments. Equivalent to callingrunTest(VerifyTableDefinition[], String[], String[], PrepAndExpectedTestCaseSteps)with the bundle's three values and the given test steps.- Parameters:
testData- The verification definitions and prep and expected data files for this test.testSteps- The test steps to run.- Returns:
- The user-defined object from running the test steps.
- Throws:
Exception- If the test steps fail.- Since:
- 3.6.0
-
postTest
Execute all post-test steps. Call this method after performing the test steps.- Throws:
Exception- if the post-test steps fail.
-
postTest
Execute post-test steps. Call this method after performing the test steps.- Parameters:
verifyData- Specify true to perform verify data steps, false to not. Useful to specify false when test has failure in progress (e.g. an exception) and verifying data would fail, masking original test failure.- Throws:
Exception- if the post-test steps fail.
-
verifyData
For the provided VerifyTableDefinitions, verify each table's actual results are as expected.- Throws:
Exception- if verifying the data fails.
-
cleanupData
Cleanup tables specified in prep and expected datasets, using the provided databaseTester. SeeIDatabaseTester.onTearDown().- Throws:
Exception- if cleaning up the data fails.
-
getPrepDataset
IDataSet getPrepDataset()Get the prep dataset, created from the prepDataFiles.- Returns:
- The prep dataset.
-
getExpectedDataset
IDataSet getExpectedDataset()Get the expected dataset, created from the expectedDataFiles.- Returns:
- The expected dataset.
-
getDatabaseTester
Get the databaseTester this test case uses.Default method for binary compatibility with implementations predating this method; they report having no databaseTester of their own rather than failing to compile. An implementation backed by
setDatabaseTester(IDatabaseTester)should override this to return the value that method was last called with, the wayDefaultPrepAndExpectedTestCasedoes - doing so lets a caller resolving a tester on this test case's behalf (e.g.org.dbunit.junit.jupiter.DbUnitExtension) keep the two in sync instead of silently driving two different testers.- Returns:
- The databaseTester, or
nullif none is set or this implementation does not support reporting one. - Since:
- 3.6.0
-
setDatabaseTester
Set the databaseTester this test case uses.Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support being given a databaseTester after construction, so a caller can invoke it unconditionally regardless of implementation. Override it, alongside
getDatabaseTester(), to accept a tester resolved after construction - e.g. from a@DbUnitTesterfield or aDatabaseTesterFactory- the wayDefaultPrepAndExpectedTestCasedoes.- Parameters:
databaseTester- The databaseTester to use.- Since:
- 3.6.0
-
getReusableConnection
Returns the connection this test case's own steps use for the current test, resolving one fromgetDatabaseTester()first if it has not already.Default method for binary compatibility with implementations predating this method; its default body simply asks
getDatabaseTester()for a connection independently on every call - the same connection-identity limitation this method exists to let a caller avoid. Override it, memoizing the result the wayDefaultPrepAndExpectedTestCasedoes, so repeated calls - and a caller resolving a connection on this test case's behalf - reuse the same connection object instead of each opening a new one.org.dbunit.annotation'sAnnotatedTestExecutorcalls this - instead of askinggetDatabaseTester()for a connection of its own - to resolve aConnection/IDatabaseConnectionparameter injection on the prep/expected path, so the injected connection is the same one this test case's own setup/verify/cleanup steps use rather than a second, independently-opened one. For a tester whosegetConnection()is not itself idempotent (e.g. a plainJdbcDatabaseTester), a non-overriding implementation still returns a usable connection, just not necessarily the same physical one this test case uses internally.- Returns:
- The connection to reuse, or
nullifgetDatabaseTester()returns none. - Throws:
Exception- On dbUnit errors.- Since:
- 3.6.0
-
setDataFileLoader
Set theDataFileLoaderthis test case uses to load prepDataFiles/expectedDataFiles.Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support being given a loader after construction. Override it to receive a loader resolved after construction the way
DefaultPrepAndExpectedTestCasedoes.org.dbunit.annotation'sAnnotatedTestExecutorcalls this on a@DbUnitTestCase-injected instance whenever@DbUnitConfig.dataFileLoader()names a non-default loader, and throwsIllegalStateExceptionif this method is not overridden - a silent no-op there would otherwise leave the instance loading with whatever loader it was already constructed with.- Parameters:
dataFileLoader- The dataFileLoader to use.- Since:
- 3.6.0
-
setFailureHandler
Set theFailureHandlerthis test case hands verifyData()'s assertion failures to.Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support being given a failure handler after construction. Override it to receive a handler resolved after construction the way
DefaultPrepAndExpectedTestCasedoes.org.dbunit.annotation'sAnnotatedTestExecutorcalls this on a@DbUnitTestCase-injected instance whenever@DbUnitConfig.failureHandler()is set, and throwsIllegalStateExceptionif this method is not overridden - a silent no-op there would otherwise leave the configured handler applied nowhere.- Parameters:
failureHandler- The failureHandler to use.- Since:
- 3.6.0
-
setCloseConnectionAfterTest
default void setCloseConnectionAfterTest(boolean closeConnectionAfterTest) Set whether this test case closes its connection after each test.Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support this being set after construction. Override it to receive a value resolved after construction the way
DefaultPrepAndExpectedTestCasedoes.org.dbunit.annotation'sAnnotatedTestExecutorcalls this on a@DbUnitTestCase-injected instance whenever@DbUnitConfig.closeConnectionAfterTest()isfalse, and logs a warning if this method is not overridden - unlike the other@DbUnitConfig-driven setters this is not a complete no-op even then, since that executor's own connection (for the row count check or parameter injection) still honors the value regardless; only this test case's own connection handling might not.- Parameters:
closeConnectionAfterTest- True to close the connection after each test, false to leave it open.- Since:
- 3.6.0
-
setDatabaseConfigProperties
Set DatabaseConfig property name/value pairs for this test case to apply to its connection.Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support this being set after construction. Override it to apply properties resolved after construction the way
DefaultPrepAndExpectedTestCasedoes.org.dbunit.annotation'sAnnotatedTestExecutorcalls this on a@DbUnitTestCase-injected instance whenever@DbUnitConfig.properties()/propertiesProvider()is non-empty, and throwsIllegalStateExceptionif this method is not overridden - on the prep/expected path this is the only route to the connection at all, so a silent no-op here would otherwise apply the configured properties nowhere.- Parameters:
databaseConfigProperties- The properties to apply; null or empty applies none.- Since:
- 3.6.0
-
setRowCountCheckOverride
Set the enabled flag and excluded table patterns this test case resolves its row count check from, instead of its connection's DatabaseConfig.Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support a row count check override. Override it, alongside
clearRowCountCheckOverride(), to apply an override resolved after construction the wayDefaultPrepAndExpectedTestCasedoes.org.dbunit.annotation'sAnnotatedTestExecutorcalls this on a@DbUnitTestCase-injected instance whenever@DbUnitRowCountCheckis declared, and throwsIllegalStateExceptionif this method is not overridden - a silent no-op here would otherwise leave the check silently never running for this test at all.- Parameters:
enabled- Whether the check is enabled.exclude- The excluded table patterns; null is treated as empty (excludes none).- Since:
- 3.6.0
-
clearRowCountCheckOverride
default void clearRowCountCheckOverride()Clear a previously set row count check override, returning to resolving it from this test case's connection's DatabaseConfig.Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support a row count check override. Override it, alongside
setRowCountCheckOverride(boolean, String[]), the wayDefaultPrepAndExpectedTestCasedoes.Unlike
setRowCountCheckOverride(boolean, String[]),AnnotatedTestExecutorcalls this unconditionally whenever@DbUnitRowCountCheckis absent, regardless of whether this method is overridden - nothing was explicitly requested in that case, so there is nothing to fail loud about; it is purely defensive, resetting a test case reused across several tests (e.g. a@DbUnitTestCasestatic field) so an earlier test's override does not silently carry over.- Since:
- 3.6.0
-