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

public class DefaultPrepAndExpectedTestCase extends DBTestCase implements PrepAndExpectedTestCase
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:
  • invalid reference
    org.dbunit.DefaultPrepAndExpectedTestCaseDiIT
  • invalid reference
    org.dbunit.DefaultPrepAndExpectedTestCaseExtIT
  • Field Details

  • 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(String name)
      Create new instance with specified test case name.
      Parameters:
      name - The test case name.
  • Method Details

    • newDatabaseTester

      public IDatabaseTester newDatabaseTester() throws Exception
      Creates a new IDatabaseTester. Default implementation returns a PropertiesBasedJdbcDatabaseTester. This implementation returns the databaseTester set by the test.
      Overrides:
      newDatabaseTester in class DBTestCase
      Throws:
      Exception
    • getDataSet

      public IDataSet getDataSet() throws Exception
      Returns the test dataset. Returns the prep dataset.
      Specified by:
      getDataSet in class DatabaseTestCase
      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:
      configureTest in interface PrepAndExpectedTestCase
      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

      public void preTest() throws Exception
      Execute pre-test steps. Call this method before performing the test steps.
      Specified by:
      preTest in interface PrepAndExpectedTestCase
      Throws:
      Exception
    • preTest

      public void preTest(VerifyTableDefinition[] tables, String[] prepDataFiles, String[] expectedDataFiles) throws Exception
      Convenience method to call configureTest() and preTest().
      Specified by:
      preTest in interface PrepAndExpectedTestCase
      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:
      runTest in interface PrepAndExpectedTestCase
      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

      protected Object runTestSteps(PrepAndExpectedTestCaseSteps testSteps) throws Exception
      Run the provided test steps. Override as necessary for custom logic.
      Parameters:
      testSteps - The test steps to run.
      Throws:
      Exception
    • postTest

      public void postTest() throws Exception
      Execute all post-test steps. Call this method after performing the test steps.
      Specified by:
      postTest in interface PrepAndExpectedTestCase
      Throws:
      Exception
    • postTest

      public void postTest(boolean verifyData) throws Exception
      Execute post-test steps. Call this method after performing the test steps.
      Specified by:
      postTest in interface PrepAndExpectedTestCase
      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

      public void cleanupData() throws Exception
      Cleanup tables specified in prep and expected datasets, using the provided databaseTester. See IDatabaseTester.onTearDown().
      Specified by:
      cleanupData in interface PrepAndExpectedTestCase
      Throws:
      Exception
    • tearDown

      protected void tearDown() throws Exception
      Overrides:
      tearDown in class DatabaseTestCase
      Throws:
      Exception
    • setupData

      public void setupData() throws Exception
      Use the provided databaseTester to prep the database with the provided prep dataset. See IDatabaseTester.onSetup().
      Throws:
      Exception
    • getSetUpOperation

      protected DatabaseOperation getSetUpOperation() throws Exception
      Description copied from class: DatabaseTestCase
      Returns the database operation executed in test setup.
      Overrides:
      getSetUpOperation in class DatabaseTestCase
      Throws:
      Exception
    • getTearDownOperation

      protected DatabaseOperation getTearDownOperation() throws Exception
      Description copied from class: DatabaseTestCase
      Returns the database operation executed in test cleanup.
      Overrides:
      getTearDownOperation in class DatabaseTestCase
      Throws:
      Exception
    • verifyData

      public void verifyData() throws Exception
      For the provided VerifyTableDefinitions, verify each table's actual results are as expected. Uses the connection from the provided databaseTester.
      Specified by:
      verifyData in interface PrepAndExpectedTestCase
      Throws:
      Exception
    • verifyData

      protected void verifyData(IDatabaseConnection connection, VerifyTableDefinition verifyTableDefinition) throws Exception
      Throws:
      Exception
    • loadTableDataFromDataSet

      public ITable loadTableDataFromDataSet(String tableName) throws DataSetException
      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 DatabaseUnitException
      For 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. See DefaultColumnFilter.excludeColumn(String) .
      includeColumns - The column names to only include in comparison. See DefaultColumnFilter.includeColumn(String) .
      defaultValueComparer - ValueComparer to use with column value comparisons when the column name for the table is not in the columnValueComparers Map. Can be null and will default.
      columnValueComparers - Map of ValueComparers to use for specific columns. Key is column name, value is the ValueComparer. Can be null and 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 DatabaseUnitException
      Compare 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

      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.
      Parameters:
      excludeColumns - Not null.
      expectedTable - Not null.
    • makeCompositeDataSet

      public IDataSet makeCompositeDataSet(String[] dataFiles, String dataFilesName) throws DataSetException
      Make a IDataSet from 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 a IDataSet from 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

      public IDataSet getPrepDataset()
      Get the prep dataset, created from the prepDataFiles.
      Specified by:
      getPrepDataset in interface PrepAndExpectedTestCase
      Returns:
      The prep dataset.
    • getExpectedDataset

      public IDataSet getExpectedDataset()
      Get the expected dataset, created from the expectedDataFiles.
      Specified by:
      getExpectedDataset in interface PrepAndExpectedTestCase
      Returns:
      The expected dataset.
    • getDatabaseTester

      public IDatabaseTester getDatabaseTester()
      Get the databaseTester.
      Overrides:
      getDatabaseTester in class DatabaseTestCase
      Returns:
      The databaseTester.
    • setDatabaseTester

      public void setDatabaseTester(IDatabaseTester databaseTester)
      Set the databaseTester.
      Parameters:
      databaseTester - The databaseTester to set.
    • getDataFileLoader

      public DataFileLoader getDataFileLoader()
      Get the dataFileLoader.
      Returns:
      The dataFileLoader.
    • setDataFileLoader

      public void setDataFileLoader(DataFileLoader dataFileLoader)
      Set the dataFileLoader.
      Parameters:
      dataFileLoader - The dataFileLoader to set.
    • setPrepDs

      public void setPrepDs(IDataSet prepDataSet)
      Set the prepDs.
      Parameters:
      prepDataSet - The prepDs to set.
    • setExpectedDs

      public void setExpectedDs(IDataSet expectedDataSet)
      Set the expectedDs.
      Parameters:
      expectedDataSet - The expectedDs to set.
    • getVerifyTableDefs

      public VerifyTableDefinition[] getVerifyTableDefs()
      Get the tableDefs.
      Returns:
      The tableDefs.
    • setVerifyTableDefs

      public void setVerifyTableDefs(VerifyTableDefinition[] verifyTableDefs)
      Set the tableDefs.
      Parameters:
      verifyTableDefs - The tableDefs to set.
    • getExpectedDataSetAndVerifyTableDefinitionVerifier

      public ExpectedDataSetAndVerifyTableDefinitionVerifier getExpectedDataSetAndVerifyTableDefinitionVerifier()
    • setExpectedDataSetAndVerifyTableDefinitionVerifier

      public void setExpectedDataSetAndVerifyTableDefinitionVerifier(ExpectedDataSetAndVerifyTableDefinitionVerifier expectedDataSetAndVerifyTableDefinitionVerifier)