Package org.dbunit
Class DefaultPrepAndExpectedTestCase
java.lang.Object
org.dbunit.DatabaseTestCase
org.dbunit.DBTestCase
org.dbunit.DefaultPrepAndExpectedTestCase
- All Implemented Interfaces:
PrepAndExpectedTestCase,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.InvocationInterceptor,org.junit.jupiter.api.extension.TestInstantiationAwareExtension
Test case base class supporting prep data and expected data. Prep data is the
data needed for the test to run. Expected data is the data needed to compare
if the test ran successfully.
- 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
Fields -
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. -
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.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 databaseTester.Get the dataFileLoader.Returns the test dataset.Get the expected dataset, created from the expectedDataFiles.Get the prep dataset, created from the prepDataFiles.protected DatabaseOperationReturns the database operation executed in test setup.protected DatabaseOperationReturns the database operation executed in test cleanup.Get the tableDefs.loadTableDataFromDatabase(String tableName, IDatabaseConnection connection) loadTableDataFromDataSet(String tableName) protected Column[]makeAdditionalColumnInfo(String[] excludeColumns, Column[] allColumns) Don't add excluded columns to additionalColumnInfo as they are not found and generate a not found message in the fail message.protected Column[]makeAdditionalColumnInfo(ITable expectedTable, String[] excludeColumns) Don't add excluded columns to additionalColumnInfo as they are not found and generate a not found message in the fail message.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.voidsetDatabaseTester(IDatabaseTester databaseTester) Set the databaseTester.voidsetDataFileLoader(DataFileLoader dataFileLoader) Set the dataFileLoader.voidsetExpectedDataSetAndVerifyTableDefinitionVerifier(ExpectedDataSetAndVerifyTableDefinitionVerifier expectedDataSetAndVerifyTableDefinitionVerifier) voidsetExpectedDs(IDataSet expectedDataSet) Set the expectedDs.voidSet the prepDs.voidUse the provided databaseTester to prep the database with the provided prep dataset.voidsetVerifyTableDefs(VerifyTableDefinition[] verifyTableDefs) Set the tableDefs.protected voidtearDown()voidFor the provided VerifyTableDefinitions, verify each table's actual results are as expected.protected voidverifyData(IDatabaseConnection connection, VerifyTableDefinition verifyTableDefinition) 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.Methods inherited from class org.dbunit.DBTestCase
getConnectionMethods inherited from class org.dbunit.DatabaseTestCase
closeConnection, getName, getOperationListener, setUp, setUpDatabaseConfigMethods 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.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Field Details
-
TEST_ERROR_MSG
- 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
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- Throws:
Exception
-
getDataSet
Returns the test dataset. Returns the prep dataset.- Specified by:
getDataSetin classDatabaseTestCase- Throws:
Exception
-
configureTest
public void configureTest(VerifyTableDefinition[] verifyTableDefinitions, String[] prepDataFiles, String[] expectedDataFiles) throws Exception Configure the test. Call this method before performing the test steps.- Specified by:
configureTestin interfacePrepAndExpectedTestCase- 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
-
preTest
Execute pre-test steps. Call this method before performing the test steps.- Specified by:
preTestin interfacePrepAndExpectedTestCase- Throws:
Exception
-
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
-
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
-
runTestSteps
Run the provided test steps. Override as necessary for custom logic.- Parameters:
testSteps- The test steps to run.- Throws:
Exception
-
postTest
Execute all post-test steps. Call this method after performing the test steps.- Specified by:
postTestin interfacePrepAndExpectedTestCase- Throws:
Exception
-
postTest
Execute post-test steps. Call this method after performing the test steps.- 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
-
cleanupData
Cleanup tables specified in prep and expected datasets, using the provided databaseTester. SeeIDatabaseTester.onTearDown().- Specified by:
cleanupDatain interfacePrepAndExpectedTestCase- Throws:
Exception
-
tearDown
- Overrides:
tearDownin classDatabaseTestCase- Throws:
Exception
-
setupData
Use the provided databaseTester to prep the database with the provided prep dataset. SeeIDatabaseTester.onSetup().- Throws:
Exception
-
getSetUpOperation
Description copied from class:DatabaseTestCaseReturns the database operation executed in test setup.- Overrides:
getSetUpOperationin classDatabaseTestCase- Throws:
Exception
-
getTearDownOperation
Description copied from class:DatabaseTestCaseReturns the database operation executed in test cleanup.- Overrides:
getTearDownOperationin classDatabaseTestCase- Throws:
Exception
-
verifyData
For the provided VerifyTableDefinitions, verify each table's actual results are as expected. Uses the connection from the provided databaseTester.- Specified by:
verifyDatain interfacePrepAndExpectedTestCase- Throws:
Exception
-
verifyData
protected void verifyData(IDatabaseConnection connection, VerifyTableDefinition verifyTableDefinition) throws Exception - Throws:
Exception
-
loadTableDataFromDataSet
- Throws:
DataSetException
-
loadTableDataFromDatabase
public ITable loadTableDataFromDatabase(String tableName, IDatabaseConnection connection) throws Exception - Throws:
Exception
-
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
-
compareData
protected void compareData(ITable expectedTable, ITable actualTable, Column[] additionalColumnInfo, ValueComparer defaultValueComparer, Map<String, ValueComparer> columnValueComparers) throws DatabaseUnitExceptionCompare the tables, enables easy overriding.- Throws:
DatabaseUnitException
-
makeAdditionalColumnInfo
protected Column[] makeAdditionalColumnInfo(ITable expectedTable, String[] excludeColumns) throws DataSetException Don't add excluded columns to additionalColumnInfo as they are not found and generate a not found message in the fail message.- Parameters:
expectedTable- Not null.excludeColumns- Nullable.- Throws:
DataSetException
-
makeAdditionalColumnInfo
Don't add excluded columns to additionalColumnInfo as they are not found and generate a not found message in the fail message.- Parameters:
excludeColumns- Not null.expectedTable- Not null.
-
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.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 to mean include all.- Returns:
- The filtered table.
- Throws:
DataSetException
-
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.- Overrides:
getDatabaseTesterin classDatabaseTestCase- Returns:
- The databaseTester.
-
setDatabaseTester
Set the databaseTester.- Parameters:
databaseTester- The databaseTester to set.
-
getDataFileLoader
Get the dataFileLoader.- Returns:
- The dataFileLoader.
-
setDataFileLoader
Set the dataFileLoader.- Parameters:
dataFileLoader- The dataFileLoader to set.
-
setPrepDs
Set the prepDs.- Parameters:
prepDataSet- The prepDs to set.
-
setExpectedDs
Set the expectedDs.- Parameters:
expectedDataSet- The expectedDs to set.
-
getVerifyTableDefs
Get the tableDefs.- Returns:
- The tableDefs.
-
setVerifyTableDefs
Set the tableDefs.- Parameters:
verifyTableDefs- The tableDefs to set.
-
getExpectedDataSetAndVerifyTableDefinitionVerifier
public ExpectedDataSetAndVerifyTableDefinitionVerifier getExpectedDataSetAndVerifyTableDefinitionVerifier() -
setExpectedDataSetAndVerifyTableDefinitionVerifier
public void setExpectedDataSetAndVerifyTableDefinitionVerifier(ExpectedDataSetAndVerifyTableDefinitionVerifier expectedDataSetAndVerifyTableDefinitionVerifier)
-