Class DefaultPrepAndExpectedTestCase
- All Implemented Interfaces:
PrepAndExpectedTestCase,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.InvocationInterceptor,org.junit.jupiter.api.extension.TestInstantiationAwareExtension
configureTest(), setupData(), verifyData(), and cleanupData() share one
IDatabaseConnection for a test's lifecycle,
acquired lazily on first use and closed once by cleanupData(), instead of
each acquiring (and often closing) its own. Calling any of those methods
without an eventual cleanupData() call - e.g. testing them individually
rather than through preTest()/postTest() - leaves that connection open.
If databaseTester is configured with a
CachingConnectionProvider shared across test
methods, set setCloseConnectionAfterTest(boolean) to false so
cleanupData() does not close a connection other tests still expect to
reuse; the provider's owner is then responsible for closing it once,
itself, when the whole run finishes. Leaving the connection open, which a
no-op listener on the databaseTester does too, requires a databaseTester
that hands out the same connection on repeated calls, as one over a
CachingConnectionProvider or over one fixed connection does. With one that
hands out a new connection each time, such as a
JdbcDatabaseTester without a CachingConnectionProvider or a
DataSourceDatabaseTester over a connection pool, nothing closes the
connection left open. An instance used for one test leaves one open after
it. An instance reused across tests keeps one for its next test and leaves
another open each time a step fails, because a failing step makes this
class forget the connection so that the next step acquires another.
This class logs a warning when it detects a JdbcDatabaseTester
without a CachingConnectionProvider in that situation.
The databaseTester's own IOperationListener is told about the
connection each of setupData()'s and cleanupData()'s operations retrieves,
through IOperationListener.connectionRetrieved(org.dbunit.database.IDatabaseConnection), so a listener that
configures every connection runs here as it does when the tester drives
onSetup() and onTearDown() itself. It is never told the operations finished,
as this class decides when the shared connection closes.
The connection must be in autocommit mode. The setup and teardown
operations run here (CLEAN_INSERT, DELETE_ALL, ...) do not manage a
transaction of their own, and TransactionOperation
refuses a connection whose autocommit is already off, so on a
non-autocommit connection the prep and teardown writes are never
committed: invisible to any other connection, and - with
setCloseConnectionAfterTest(boolean) false - held as locks on a
connection the database's idle-in-transaction timeout may terminate
mid-run. This class logs a warning when it detects such a connection.
The verifyData() method hands assertion failures to
DefaultFailureHandler by default, which throws
on the first mismatch found. Set setFailureHandler(FailureHandler)
to, for example, a DiffCollectingFailureHandler
to collect every Difference instead; that is
not the default since most tests want to keep failing fast.
Not thread-safe. An instance holds the state of one test at a time: its
datasets, verify table definitions, shared connection and row count
baseline. Use one instance per concurrently running test, for example a
Spring prototype bean, or turn off parallel execution for tests that share
an instance, such as one in a static @DbUnitTestCase field.
Otherwise concurrent tests overwrite each other's datasets and close each
other's connection.
- Since:
- 2.4.8
- Version:
- $Revision$ $Date$
- Author:
- Jeff Jensen jeffjensen AT users.sourceforge.net, Last changed by: $Author$
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T>Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMessage prefix used for wrapped test failures. -
Constructor Summary
ConstructorsConstructorDescriptionCreate new instance.Create new instance with specified test case name.DefaultPrepAndExpectedTestCase(DataFileLoader dataFileLoader, IDatabaseTester databaseTester) Create new instance with specified dataFileLoader and databaseTester.DefaultPrepAndExpectedTestCase(DataFileLoader dataFileLoader, IDatabaseTester databaseTester, boolean closeConnectionAfterTest) Create new instance with specified dataFileLoader and databaseTester. -
Method Summary
Modifier and TypeMethodDescriptionapplyColumnFilters(ITable table, String[] excludeColumns, String[] includeColumns) Apply the specified exclude and include column filters to the specified table.voidCleanup tables specified in prep and expected datasets, using the provided databaseTester.voidClear a previously set enabled flag and excluded table patterns override, returning to resolving a RowCountCheck from the shared connection's DatabaseConfig.protected voidcompareData(ITable expectedTable, ITable actualTable, Column[] additionalColumnInfo, ValueComparer defaultValueComparer, Map<String, ValueComparer> columnValueComparers) Compare the tables, enables easy overriding.voidconfigureTest(VerifyTableDefinition[] verifyTableDefinitions, String[] prepDataFiles, String[] expectedDataFiles) Configure the test.Get the DatabaseConfig property name/value pairs applied to the connection shared by setupData(), verifyData() and cleanupData().Get the databaseTester.Get the dataFileLoader.Returns the test dataset.Get the expected dataset, created from the expectedDataFiles.Returns the verifier used to check that verify table definitions and the expected dataset agree.Get the failureHandler.Get the prep dataset, created from the prepDataFiles.Return the connection shared by lookupFeatureValue(), setupData(), verifyData() and cleanupData() for the current test's lifecycle, acquiring it on first use instead of a fresh connection at each step.Get the RowCountCheck in use.protected DatabaseOperationReturns the database operation executed in test setup.protected DatabaseOperationReturns the database operation executed in test cleanup.Get the tableDefs.booleanGet whether the connection lookupFeatureValue() and cleanupData() are done with is closed.loadTableDataFromDatabase(String tableName, IDatabaseConnection connection) Loads the given table's actual data from the database.loadTableDataFromDataSet(String tableName) Loads the given table's expected data from the expected dataset.protected Column[]makeAdditionalColumnInfo(String[] excludeColumns, Column[] allColumns) Don't add excluded columns to additionalColumnInfo as they are not compared.protected Column[]makeAdditionalColumnInfo(ITable expectedTable, String[] excludeColumns) Don't add excluded columns to additionalColumnInfo as they are not compared.makeCompositeDataSet(String[] dataFiles, String dataFilesName) Make aIDataSetfrom the specified files with case sensitive table names as false.makeCompositeDataSet(String[] dataFiles, String dataFilesName, boolean isCaseSensitiveTableNames) Make aIDataSetfrom the specified files.Creates a new IDatabaseTester.voidpostTest()Execute all post-test steps.voidpostTest(boolean verifyData) Execute post-test steps.voidpreTest()Execute pre-test steps.voidpreTest(VerifyTableDefinition[] tables, String[] prepDataFiles, String[] expectedDataFiles) Convenience method to call configureTest() and preTest().runTest(VerifyTableDefinition[] verifyTables, String[] prepDataFiles, String[] expectedDataFiles, PrepAndExpectedTestCaseSteps testSteps) Run the DbUnit test.protected ObjectrunTestSteps(PrepAndExpectedTestCaseSteps testSteps) Run the provided test steps.voidsetCloseConnectionAfterTest(boolean closeConnectionAfterTest) Set whether the connection lookupFeatureValue() and cleanupData() are done with is closed.voidsetDatabaseConfigProperties(Properties databaseConfigProperties) Set DatabaseConfig property name/value pairs to apply to the connection shared by setupData(), verifyData() and cleanupData(), every timeDBTestCase.getConnection()resolves it.voidsetDatabaseTester(IDatabaseTester databaseTester) Set the databaseTester.voidsetDataFileLoader(DataFileLoader dataFileLoader) Set the dataFileLoader.voidsetExpectedDataSetAndVerifyTableDefinitionVerifier(ExpectedDataSetAndVerifyTableDefinitionVerifier expectedDataSetAndVerifyTableDefinitionVerifier) Sets the verifier used to check that verify table definitions and the expected dataset agree.voidsetExpectedDs(IDataSet expectedDataSet) Set the expectedDs.voidsetFailureHandler(FailureHandler failureHandler) Set the failureHandler.voidSet the prepDs.voidsetRowCountCheck(RowCountCheck rowCountCheck) Set the RowCountCheck, overriding the one otherwise lazily built from the shared connection's DatabaseConfig.voidsetRowCountCheckOverride(boolean enabled, String[] exclude) Set the enabled flag and excluded table patterns to resolve a RowCountCheck from, instead of the shared connection's DatabaseConfig - the values an annotation such as@DbUnitRowCountCheckdeclares.protected voidsetUp()Legacy JUnit-3-era set-up hook.voidUse the provided databaseTester to prep the database with the provided prep dataset.protected voidsetUpDatabaseConfig(DatabaseConfig config) Designed to be overridden by subclasses in order to set additional configuration parameters for theIDatabaseConnection.voidsetVerifyTableDefs(VerifyTableDefinition[] verifyTableDefs) Set the tableDefs.protected voidtearDown()Legacy JUnit-3-era tear-down hook.protected voidLegacy JUnit-3-era tear-down hook for a test whose failure is already in flight.voidFor the provided VerifyTableDefinitions, verify each table's actual results are as expected.protected voidverifyData(IDatabaseConnection connection, VerifyTableDefinition verifyTableDefinition) Verifies a single table's actual data against its expected data.protected voidverifyData(ITable expectedTable, ITable actualTable, String[] excludeColumns, String[] includeColumns, ValueComparer defaultValueComparer, Map<String, ValueComparer> columnValueComparers) For the specified expected and actual tables (and excluding and including the specified columns), verify the actual data is as expected.protected voidverifyData(ITable expectedTable, ITable actualTable, String[] excludeColumns, String[] includeColumns, ValueComparer defaultValueComparer, Map<String, ValueComparer> columnValueComparers, boolean sortOnFilteredColumnsOnly) For the specified expected and actual tables (and excluding and including the specified columns), verify the actual data is as expected.Methods inherited from class org.dbunit.DBTestCase
getConnectionMethods inherited from class org.dbunit.DatabaseTestCase
closeConnection, getName, getOperationListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
interceptAfterAllMethod, interceptAfterEachMethod, interceptBeforeAllMethod, interceptBeforeEachMethod, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestMethod, interceptTestTemplateMethodMethods inherited from interface org.dbunit.PrepAndExpectedTestCase
configureTest, preTest, runTestMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Field Details
-
TEST_ERROR_MSG
Message prefix used for wrapped test failures.- See Also:
-
-
Constructor Details
-
DefaultPrepAndExpectedTestCase
public DefaultPrepAndExpectedTestCase()Create new instance. -
DefaultPrepAndExpectedTestCase
public DefaultPrepAndExpectedTestCase(DataFileLoader dataFileLoader, IDatabaseTester databaseTester) Create new instance with specified dataFileLoader and databaseTester.- Parameters:
dataFileLoader- Load to use for loading the data files.databaseTester- Tester to use for database manipulation.
-
DefaultPrepAndExpectedTestCase
public DefaultPrepAndExpectedTestCase(DataFileLoader dataFileLoader, IDatabaseTester databaseTester, boolean closeConnectionAfterTest) Create new instance with specified dataFileLoader and databaseTester.- Parameters:
dataFileLoader- Load to use for loading the data files.databaseTester- Tester to use for database manipulation.closeConnectionAfterTest- Whether or not to close the database connection after each test.- Since:
- 3.4.0
-
DefaultPrepAndExpectedTestCase
Create new instance with specified test case name.- Parameters:
name- The test case name.
-
-
Method Details
-
newDatabaseTester
Creates a new IDatabaseTester. Default implementation returns aPropertiesBasedJdbcDatabaseTester. This implementation returns the databaseTester set by the test.- Overrides:
newDatabaseTesterin classDBTestCase- Returns:
- the newly created database tester.
- Throws:
Exception- if the database tester cannot be created.
-
getDataSet
Returns the test dataset. Returns the prep dataset.- Specified by:
getDataSetin classDatabaseTestCase- Returns:
- the test dataset.
- Throws:
Exception- if the dataset cannot be retrieved or created.
-
configureTest
public void configureTest(VerifyTableDefinition[] verifyTableDefinitions, String[] prepDataFiles, String[] expectedDataFiles) throws Exception Configure the test. Call this method before performing the test steps.Executes against the connection shared with setupData(), verifyData() and cleanupData() for this test's lifecycle rather than a fresh one, and leaves it open; cleanupData() closes it. See #800.
A null argument means none. When this fails, for example because a data file is missing or invalid, this instance is left with no prep data, expected data or verify table definitions, so a cleanupData() that follows cleans nothing left over from an earlier test. The shared connection it acquired is released too; one the caller had already resolved, for example by injecting it into a test method parameter, is left open for the caller.
- Specified by:
configureTestin interfacePrepAndExpectedTestCase- Parameters:
verifyTableDefinitions- Table definitions to verify after test execution; null means none.prepDataFiles- The prep data files (as classpath resources) to load and insert contents into the database as seed data; null means none.expectedDataFiles- The expected data files (as classpath resources) to load as expected data and verify actual data matches at test end; null means none.- Throws:
Exception- if the test cannot be configured.
-
setUpDatabaseConfig
Designed to be overridden by subclasses in order to set additional configuration parameters for theIDatabaseConnection. AppliesdatabaseConfigProperties, when set - the composition-based equivalent of overriding this method, for a caller that cannot subclass to do so directly (e.g.org.dbunit.annotation's@DbUnitProperty). The values replaced are put back when this test's lifecycle ends - seecleanupData().The lifecycle retrieves its connection several times, and each retrieval calls this method. The values are applied once per
DatabaseConfiguntil they are put back, and a later call does nothing, so a property set on theDatabaseConfigdirectly in between is not overwritten. The exception is a database tester with an operation listener of its own, which may change any of the values at each set up and tear down operation: the values are applied again directly after it, so they still win.Note: a subclass overriding this method must call
super.setUpDatabaseConfig(config)to keepsetDatabaseConfigProperties(java.util.Properties)- and therefore@DbUnitPropertyon the annotation-driven path - working.- Overrides:
setUpDatabaseConfigin classDatabaseTestCase- Parameters:
config- The settings of the currentIDatabaseConnectionto be configured- Throws:
IllegalStateException- If a property value is invalid for its targetDatabaseConfigentry.
-
getReusableConnection
Return the connection shared by lookupFeatureValue(), setupData(), verifyData() and cleanupData() for the current test's lifecycle, acquiring it on first use instead of a fresh connection at each step.When
closeConnectionAfterTestis false this connection is kept across test methods, where the connection pool or the database server can close it between tests - a pool max-lifetime or reap, a bounced application context, aCachingConnectionProvider.close(). A closed one is discarded before it is handed back, so the next call re-acquires from databaseTester - letting aCachingConnectionProviderbehind it supply a live replacement - rather than this instance reusing a connection every later lifecycle step would only fail on.- Specified by:
getReusableConnectionin interfacePrepAndExpectedTestCase- Returns:
- The shared connection.
- Throws:
Exception- On dbUnit errors.- Since:
- 3.4.0
-
preTest
Execute pre-test steps. Call this method before performing the test steps.Captures the row count check baseline, if enabled, before setting up the prep data - see
RowCountCheck.capture(IDatabaseConnection).- Specified by:
preTestin interfacePrepAndExpectedTestCase- Throws:
Exception- if the pre-test steps fail.
-
preTest
public void preTest(VerifyTableDefinition[] tables, String[] prepDataFiles, String[] expectedDataFiles) throws Exception Convenience method to call configureTest() and preTest().- Specified by:
preTestin interfacePrepAndExpectedTestCase- Parameters:
tables- 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.
-
runTest
public Object runTest(VerifyTableDefinition[] verifyTables, String[] prepDataFiles, String[] expectedDataFiles, PrepAndExpectedTestCaseSteps testSteps) throws Exception Run the DbUnit test.- Specified by:
runTestin interfacePrepAndExpectedTestCase- 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.
-
runTestSteps
Run the provided test steps. Override as necessary for custom logic.- Parameters:
testSteps- The test steps to run.- Returns:
- the user-defined object returned by the test steps.
- Throws:
Exception- if the test steps fail.
-
postTest
Execute all post-test steps. Call this method after performing the test steps.- Specified by:
postTestin interfacePrepAndExpectedTestCase- Throws:
Exception- if the post-test steps fail.
-
postTest
Execute post-test steps. Call this method after performing the test steps.When
verifyDatais false - the test steps already failed - discards any captured row count check baseline, so cleanupData() skips that check too: the database is in an unknown state, so a count difference would be noise around the real failure, not a finding worth its own report. A verification failure discards it the same way, so cleanupData() does not throw a row count difference in its place: the comparison failure names what differs and is the one to fix first, while a cleanup failure still shadows it as before.- Specified by:
postTestin interfacePrepAndExpectedTestCase- 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.
-
cleanupData
Cleanup tables specified in prep and expected datasets, using the provided databaseTester. SeeIDatabaseTester.onTearDown().Runs the tear down operation against the connection shared with setupData() and verifyData() for this test's lifecycle, then closes it. See #800.
- Specified by:
cleanupDatain interfacePrepAndExpectedTestCase- Throws:
Exception- if cleaning up the data fails.
-
setUp
Legacy JUnit-3-era set-up hook. Not invoked automatically under JUnit 5; kept for subclasses that drive the lifecycle manually. RunssetupData()on the connection shared with the rest of this test's lifecycle, leaving the databaseTester's dataset and operation listener as the caller set them.- Overrides:
setUpin classDatabaseTestCase- Throws:
Exception- if the setup operation fails.
-
tearDown
Legacy JUnit-3-era tear-down hook. Not invoked automatically under JUnit 5; kept for subclasses that drive the lifecycle manually. RunscleanupData(), which tears down the prep and expected tables once and releases the shared connection. Calling it after a fullrunTest(org.dbunit.VerifyTableDefinition[], java.lang.String[], java.lang.String[], org.dbunit.PrepAndExpectedTestCaseSteps)orpostTest()cycle cleans up a second time, as both already ran cleanupData().- Overrides:
tearDownin classDatabaseTestCase- Throws:
Exception- if the tear-down operation fails.
-
tearDown
Legacy JUnit-3-era tear-down hook for a test whose failure is already in flight. RunscleanupData()the same way astearDown(), and throwstestFailureafterward, with any clean up failure attached to it as suppressed rather than replacing it.- Overrides:
tearDownin classDatabaseTestCase- Parameters:
testFailure- The throwable already in flight from the test body, ornullif there is none, in which case this behaves the same astearDown().- Throws:
Throwable- The testFailure, if notnull; otherwise a clean up failure, if one occurred.
-
setupData
Use the provided databaseTester to prep the database with the provided prep dataset. SeeIDatabaseTester.onSetup().Executes against the connection shared with verifyData() and cleanupData() for this test's lifecycle rather than a fresh one, and leaves it open; cleanupData() closes it. See #800.
- Throws:
Exception- if preparing the data fails.
-
getSetUpOperation
Description copied from class:DatabaseTestCaseReturns the database operation executed in test setup.- Overrides:
getSetUpOperationin classDatabaseTestCase- Returns:
- the database operation executed in test setup.
- Throws:
Exception- if the operation cannot be determined.
-
getTearDownOperation
Description copied from class:DatabaseTestCaseReturns the database operation executed in test cleanup.- Overrides:
getTearDownOperationin classDatabaseTestCase- Returns:
- the database operation executed in test cleanup.
- Throws:
Exception- if the operation cannot be determined.
-
verifyData
For the provided VerifyTableDefinitions, verify each table's actual results are as expected. Uses the connection from the provided databaseTester, shared with setupData() and cleanupData() for this test's lifecycle. Left open on return; cleanupData() closes it. See #800.- Specified by:
verifyDatain interfacePrepAndExpectedTestCase- Throws:
Exception- if verifying the data fails.
-
verifyData
protected void verifyData(IDatabaseConnection connection, VerifyTableDefinition verifyTableDefinition) throws Exception Verifies a single table's actual data against its expected data.- Parameters:
connection- the database connection to load the actual data from.verifyTableDefinition- the table definition to verify.- Throws:
Exception- if verifying the table fails.
-
loadTableDataFromDataSet
Loads the given table's expected data from the expected dataset.- Parameters:
tableName- the name of the table to load.- Returns:
- the table's expected data.
- Throws:
DataSetException- if loading the table fails.
-
loadTableDataFromDatabase
public ITable loadTableDataFromDatabase(String tableName, IDatabaseConnection connection) throws Exception Loads the given table's actual data from the database.- Parameters:
tableName- the name of the table to load.connection- the database connection to load the data from.- Returns:
- the table's actual data.
- Throws:
Exception- if loading the table fails.
-
verifyData
protected void verifyData(ITable expectedTable, ITable actualTable, String[] excludeColumns, String[] includeColumns, ValueComparer defaultValueComparer, Map<String, ValueComparer> columnValueComparers) throws DatabaseUnitExceptionFor the specified expected and actual tables (and excluding and including the specified columns), verify the actual data is as expected.- Parameters:
expectedTable- The expected table to compare the actual table to.actualTable- The actual table to compare to the expected table.excludeColumns- The column names to exclude from comparison. SeeDefaultColumnFilter.excludeColumn(String).includeColumns- The column names to only include in comparison. SeeDefaultColumnFilter.includeColumn(String).defaultValueComparer-ValueComparerto use with column value comparisons when the column name for the table is not in the columnValueComparersMap. Can benulland will default.columnValueComparers-MapofValueComparers to use for specific columns. Key is column name, value is theValueComparer. Can benulland will default to defaultValueComparer for all columns in all tables.- Throws:
DatabaseUnitException- if the tables' row counts, columns, or data do not match.- See Also:
-
verifyData
protected void verifyData(ITable expectedTable, ITable actualTable, String[] excludeColumns, String[] includeColumns, ValueComparer defaultValueComparer, Map<String, ValueComparer> columnValueComparers, boolean sortOnFilteredColumnsOnly) throws DatabaseUnitExceptionFor the specified expected and actual tables (and excluding and including the specified columns), verify the actual data is as expected.- Parameters:
expectedTable- The expected table to compare the actual table to.actualTable- The actual table to compare to the expected table.excludeColumns- The column names to exclude from comparison. SeeDefaultColumnFilter.excludeColumn(String).includeColumns- The column names to only include in comparison. SeeDefaultColumnFilter.includeColumn(String).defaultValueComparer-ValueComparerto use with column value comparisons when the column name for the table is not in the columnValueComparersMap. Can benulland will default.columnValueComparers-MapofValueComparers to use for specific columns. Key is column name, value is theValueComparer. Can benulland will default to defaultValueComparer for all columns in all tables.sortOnFilteredColumnsOnly- True to sort the expected and actual tables by only the columns that survive excludeColumns/includeColumns, instead of by all of the actual table's native columns; seeVerifyTableDefinition.isSortOnFilteredColumnsOnly(). When false and the expected table omits columns of the actual table, so the two sort by different columns, a failed comparison that passes when sorted by only the filtered columns carries a suppressed exception naming this as the remedy.- Throws:
DatabaseUnitException- if the tables' row counts, columns, or data do not match.- Since:
- 3.5.0
-
compareData
protected void compareData(ITable expectedTable, ITable actualTable, Column[] additionalColumnInfo, ValueComparer defaultValueComparer, Map<String, ValueComparer> columnValueComparers) throws DatabaseUnitExceptionCompare the tables, enables easy overriding.Uses
failureHandlerwhen set; otherwise defers toAssertion.assertWithValueComparer(ITable, ITable, Column[], ValueComparer, Map)'s ownDefaultFailureHandler, configured with additionalColumnInfo.- Parameters:
expectedTable- the table containing all expected results.actualTable- the table containing all actual results.additionalColumnInfo- the additional columns to include in failure messages.defaultValueComparer- the value comparer used when no more specific comparer is configured.columnValueComparers- the per-column value comparers to use.- Throws:
DatabaseUnitException- if the tables' row counts, columns, or data do not match.
-
makeAdditionalColumnInfo
protected Column[] makeAdditionalColumnInfo(ITable expectedTable, String[] excludeColumns) throws DataSetException Don't add excluded columns to additionalColumnInfo as they are not compared. The verification then drops, from what this returns, the columns the actual table does not have, for example one that was not loaded from the database, as the fail message would show a not found message for them.- Parameters:
expectedTable- Not null.excludeColumns- Nullable.- Returns:
- the additional column info, excluding excludeColumns.
- Throws:
DataSetException- if the expected table's columns cannot be retrieved.
-
makeAdditionalColumnInfo
Don't add excluded columns to additionalColumnInfo as they are not compared. The exclude patterns match the way the column filters applied to the compared tables do: without regard to case, and withDefaultColumnFilter's wildcard support. The verification then drops, from what this returns, the columns the actual table does not have, for example one that was not loaded from the database, as the fail message would show a not found message for them.- Parameters:
excludeColumns- Not null.allColumns- Not null.- Returns:
- the additional column info, excluding excludeColumns.
-
makeCompositeDataSet
public IDataSet makeCompositeDataSet(String[] dataFiles, String dataFilesName) throws DataSetException Make aIDataSetfrom the specified files with case sensitive table names as false.- Parameters:
dataFiles- Represents the array of dbUnit data files.dataFilesName- Concept name of the data files, e.g. prep, expected.- Returns:
- The composite dataset.
- Throws:
DataSetException- On dbUnit errors.
-
makeCompositeDataSet
public IDataSet makeCompositeDataSet(String[] dataFiles, String dataFilesName, boolean isCaseSensitiveTableNames) throws DataSetException Make aIDataSetfrom the specified files.- Parameters:
dataFiles- Represents the array of dbUnit data files; null is treated as none.dataFilesName- Concept name of the data files, e.g. prep, expected.isCaseSensitiveTableNames- true if case sensitive table names is on.- Returns:
- The composite dataset.
- Throws:
DataSetException- On dbUnit errors.
-
applyColumnFilters
public ITable applyColumnFilters(ITable table, String[] excludeColumns, String[] includeColumns) throws DataSetException Apply the specified exclude and include column filters to the specified table.- Parameters:
table- The table to apply the filters to.excludeColumns- The exclude filters; use null or empty array to mean exclude none.includeColumns- The include filters; use null or empty array to mean include all.- Returns:
- The filtered table.
- Throws:
DataSetException- if applying the filters fails.
-
getPrepDataset
Get the prep dataset, created from the prepDataFiles.- Specified by:
getPrepDatasetin interfacePrepAndExpectedTestCase- Returns:
- The prep dataset.
-
getExpectedDataset
Get the expected dataset, created from the expectedDataFiles.- Specified by:
getExpectedDatasetin interfacePrepAndExpectedTestCase- Returns:
- The expected dataset.
-
getDatabaseTester
Get the databaseTester.- Specified by:
getDatabaseTesterin interfacePrepAndExpectedTestCase- Overrides:
getDatabaseTesterin classDatabaseTestCase- Returns:
- The databaseTester.
- See Also:
-
setDatabaseTester
Set the databaseTester. Replacing a different one first releases the shared connection acquired from it, closing it only whencleanupData()would, and forgets what was resolved from it, so the next step acquires its connection and case sensitivity setting from the new one.- Specified by:
setDatabaseTesterin interfacePrepAndExpectedTestCase- Parameters:
databaseTester- The databaseTester to set.- See Also:
-
isCloseConnectionAfterTest
public boolean isCloseConnectionAfterTest()Get whether the connection lookupFeatureValue() and cleanupData() are done with is closed.- Specified by:
isCloseConnectionAfterTestin interfacePrepAndExpectedTestCase- Returns:
- True if it is closed, false if not.
- Since:
- 3.4.0
- See Also:
-
setCloseConnectionAfterTest
public void setCloseConnectionAfterTest(boolean closeConnectionAfterTest) Set whether the connection lookupFeatureValue() and cleanupData() are done with is closed. Default is true. Set to false when databaseTester shares aCachingConnectionProvideracross test methods, so this instance does not close a connection other tests still expect to reuse. False requires a databaseTester that hands out the same connection on repeated calls: with one that hands out a new connection each time, nothing closes the connection left open after a test, and a step that fails leaves open the connection this instance forgets. A warning is logged when databaseTester is aJdbcDatabaseTesterwithout a CachingConnectionProvider.- Specified by:
setCloseConnectionAfterTestin interfacePrepAndExpectedTestCase- Parameters:
closeConnectionAfterTest- True to close it, false to leave it open.- Since:
- 3.4.0
- See Also:
-
getDataFileLoader
Get the dataFileLoader.- Specified by:
getDataFileLoaderin interfacePrepAndExpectedTestCase- Returns:
- The dataFileLoader.
- See Also:
-
setDataFileLoader
Set the dataFileLoader.- Specified by:
setDataFileLoaderin interfacePrepAndExpectedTestCase- Parameters:
dataFileLoader- The dataFileLoader to set.- See Also:
-
setPrepDs
Set the prepDs.- Parameters:
prepDataSet- The prepDs to set.- See Also:
-
setExpectedDs
Set the expectedDs.- Parameters:
expectedDataSet- The expectedDs to set.- See Also:
-
getVerifyTableDefs
Get the tableDefs.- Returns:
- The tableDefs.
- See Also:
-
setVerifyTableDefs
Set the tableDefs.- Parameters:
verifyTableDefs- The tableDefs to set.- See Also:
-
getExpectedDataSetAndVerifyTableDefinitionVerifier
public ExpectedDataSetAndVerifyTableDefinitionVerifier getExpectedDataSetAndVerifyTableDefinitionVerifier()Returns the verifier used to check that verify table definitions and the expected dataset agree.- Returns:
- the verifier used to check that verify table definitions and the expected dataset agree.
-
setExpectedDataSetAndVerifyTableDefinitionVerifier
public void setExpectedDataSetAndVerifyTableDefinitionVerifier(ExpectedDataSetAndVerifyTableDefinitionVerifier expectedDataSetAndVerifyTableDefinitionVerifier) Sets the verifier used to check that verify table definitions and the expected dataset agree.- Parameters:
expectedDataSetAndVerifyTableDefinitionVerifier- the verifier to use.
-
getFailureHandler
Get the failureHandler.- Specified by:
getFailureHandlerin interfacePrepAndExpectedTestCase- Returns:
- The failureHandler.
- Since:
- 3.5.0
- See Also:
-
setFailureHandler
Set the failureHandler.- Specified by:
setFailureHandlerin interfacePrepAndExpectedTestCase- Parameters:
failureHandler- The failureHandler to set.- Since:
- 3.5.0
- See Also:
-
getRowCountCheck
Get the RowCountCheck in use.- Returns:
- The RowCountCheck, or null if none has been resolved or set yet.
- Since:
- 3.6.0
- See Also:
-
setRowCountCheck
Set the RowCountCheck, overriding the one otherwise lazily built from the shared connection's DatabaseConfig.- Parameters:
rowCountCheck- The RowCountCheck to use.- Since:
- 3.6.0
- See Also:
-
setRowCountCheckOverride
Set the enabled flag and excluded table patterns to resolve a RowCountCheck from, instead of the shared connection's DatabaseConfig - the values an annotation such as@DbUnitRowCountCheckdeclares.- Specified by:
setRowCountCheckOverridein interfacePrepAndExpectedTestCase- Parameters:
enabled- Whether the check is enabled.exclude- The excluded table patterns; null is treated as empty (excludes none).- Since:
- 3.6.0
- See Also:
-
clearRowCountCheckOverride
public void clearRowCountCheckOverride()Clear a previously set enabled flag and excluded table patterns override, returning to resolving a RowCountCheck from the shared connection's DatabaseConfig.A caller reusing one instance across several tests - e.g. one held by a
@DbUnitTestCasestatic field - must call this once a test that set an override is over, so that test's override does not silently carry over onto the next one.- Specified by:
clearRowCountCheckOverridein interfacePrepAndExpectedTestCase- Since:
- 3.6.0
- See Also:
-
getDatabaseConfigProperties
Get the DatabaseConfig property name/value pairs applied to the connection shared by setupData(), verifyData() and cleanupData().- Specified by:
getDatabaseConfigPropertiesin interfacePrepAndExpectedTestCase- Returns:
- A copy of the properties, or null if none are set.
- Since:
- 3.6.0
- See Also:
-
setDatabaseConfigProperties
Set DatabaseConfig property name/value pairs to apply to the connection shared by setupData(), verifyData() and cleanupData(), every timeDBTestCase.getConnection()resolves it.Puts back, first, whatever the previous properties replaced, so that changing them - as the annotation runtime does to restore an injected instance's own properties after a test - leaves nothing of the old values on a connection kept open.
- Specified by:
setDatabaseConfigPropertiesin interfacePrepAndExpectedTestCase- Parameters:
databaseConfigProperties- The properties to apply; null or empty applies none.- Since:
- 3.6.0
- See Also:
-