Class DbUnitAssertBase

java.lang.Object
org.dbunit.assertion.DbUnitAssertBase
Direct Known Subclasses:
DbUnitAssert, DbUnitValueComparerAssert

public class DbUnitAssertBase extends Object
Base class for DbUnit assert classes containing common methods.
Since:
2.6.0
Author:
Jeff Jensen
  • Field Details

  • Constructor Details

    • DbUnitAssertBase

      public DbUnitAssertBase()
  • Method Details

    • getDefaultFailureHandler

      protected FailureHandler getDefaultFailureHandler()
      Returns:
      The default failure handler
      Since:
      2.4
    • getDefaultFailureHandler

      protected FailureHandler getDefaultFailureHandler(Column[] additionalColumnInfo)
      Returns:
      The default failure handler
      Since:
      2.4
    • getComparisonColumns

      protected DbUnitAssert.ComparisonColumn[] getComparisonColumns(String expectedTableName, Column[] expectedColumns, Column[] actualColumns, FailureHandler failureHandler)
      Parameters:
      expectedTableName -
      expectedColumns -
      actualColumns -
      failureHandler - The FailureHandler to be used when no datatype can be determined
      Returns:
      The columns to be used for the assertion, including the correct datatype
      Since:
      2.4
    • skipCompare

      protected boolean skipCompare(String columnName, Object expectedValue, Object actualValue)
      Method to last-minute intercept the comparison of a single expected and actual value. Designed to be overridden in order to skip cell comparison by specific cell values.
      Parameters:
      columnName - The column being compared
      expectedValue - The expected value to be compared
      actualValue - The actual value to be compared
      Returns:
      false always so that the comparison is never skipped
      Since:
      2.4
    • determineFailureHandler

      protected FailureHandler determineFailureHandler(FailureHandler failureHandler)
    • compareRowCounts

      protected boolean compareRowCounts(ITable expectedTable, ITable actualTable, FailureHandler failureHandler, String expectedTableName) throws Error
      Throws:
      Error
    • compareColumns

      protected void compareColumns(Column[] expectedColumns, Column[] actualColumns, ITableMetaData expectedMetaData, ITableMetaData actualMetaData, FailureHandler failureHandler) throws DataSetException, Error
      Throws:
      DataSetException
      Error
    • compareTableCounts

      protected void compareTableCounts(String[] expectedNames, String[] actualNames, FailureHandler failureHandler) throws Error
      Throws:
      Error
    • compareTableNames

      protected void compareTableNames(String[] expectedNames, String[] actualNames, FailureHandler failureHandler) throws Error
      Throws:
      Error
    • getSortedTableNames

      protected String[] getSortedTableNames(IDataSet dataSet) throws DataSetException
      Throws:
      DataSetException
    • assertWithValueComparer

      public void assertWithValueComparer(IDataSet expectedDataSet, IDataSet actualDataSet, FailureHandler failureHandler, ValueComparer defaultValueComparer, Map<String,Map<String,ValueComparer>> tableColumnValueComparers) throws DatabaseUnitException
      Asserts the two specified IDataSets comparing their columns using the specified columnValueComparers or defaultValueComparer and handles failures using the specified failureHandler. This method ignores the table names, the columns order, the columns data type, and which columns are composing the primary keys.
      Parameters:
      expectedDataSet - IDataSet containing all expected results.
      actualDataSet - IDataSet containing all actual results.
      failureHandler - The failure handler used if the assert fails because of a data mismatch. Provides some additional information that may be useful to quickly identify the rows for which the mismatch occurred (for example by printing an additional primary key column). Can be null.
      defaultValueComparer - ValueComparer to use with column value comparisons when the column name for the table is not in the tableColumnValueComparers Map. Can be null and will default to
      invalid reference
      #getDefaultValueComparer()
      .
      tableColumnValueComparers - Map of ValueComparers to use for specific tables and columns. Key is table name, value is Map of column name in the table to ValueComparers. Can be null and will default to using
      invalid reference
      #getDefaultColumnValueComparerMapForTable(String)
      or, if that is empty, defaultValueComparer for all columns in all tables.
      Throws:
      DatabaseUnitException
    • compareTables

      protected void compareTables(IDataSet expectedDataSet, IDataSet actualDataSet, String[] expectedNames, FailureHandler failureHandler, ValueComparer defaultValueComparer, Map<String,Map<String,ValueComparer>> tableColumnValueComparers) throws DatabaseUnitException
      Throws:
      DatabaseUnitException
    • assertWithValueComparer

      public void assertWithValueComparer(ITable expectedTable, ITable actualTable, FailureHandler failureHandler, ValueComparer defaultValueComparer, Map<String,ValueComparer> columnValueComparers) throws DatabaseUnitException
      Asserts the two specified ITables comparing their columns using the specified columnValueComparers or defaultValueComparer and handles failures using the specified failureHandler. This method ignores the table names, the columns order, the columns data type, and which columns are composing the primary keys.
      Parameters:
      expectedTable - ITable containing all expected results.
      actualTable - ITable containing all actual results.
      failureHandler - The failure handler used if the assert fails because of a data mismatch. Provides some additional information that may be useful to quickly identify the rows for which the mismatch occurred (for example by printing an additional primary key column). Can be null.
      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 to
      invalid reference
      #getDefaultValueComparer()
      .
      columnValueComparers - Map of ValueComparers to use for specific columns. Key is column name in the table, value is ValueComparer to use in comparing expected to actual column values. Can be null and will default to using
      invalid reference
      #getDefaultColumnValueComparerMapForTable(String)
      or, if that is empty, defaultValueComparer for all columns in the table.
      Throws:
      DatabaseUnitException
    • compareData

      protected void compareData(ITable expectedTable, ITable actualTable, DbUnitAssert.ComparisonColumn[] comparisonCols, FailureHandler failureHandler) throws DataSetException
      Parameters:
      expectedTable - Table containing all expected results.
      actualTable - Table containing all actual results.
      comparisonCols - The columns to be compared, also including the correct DataTypes for comparison
      failureHandler - The failure handler used if the assert fails because of a data mismatch. Provides some additional information that may be useful to quickly identify the rows for which the mismatch occurred (for example by printing an additional primary key column). Must not be null at this stage
      Throws:
      DataSetException
      Since:
      2.4
    • compareData

      protected void compareData(ITable expectedTable, ITable actualTable, DbUnitAssert.ComparisonColumn[] comparisonCols, FailureHandler failureHandler, ValueComparer defaultValueComparer, Map<String,ValueComparer> columnValueComparers) throws DatabaseUnitException
      Parameters:
      expectedTable - ITable containing all expected results.
      actualTable - ITable containing all actual results.
      comparisonCols - The columns to be compared, also including the correct DataTypes for comparison
      failureHandler - The failure handler used if the assert fails because of a data mismatch. Provides some additional information that may be useful to quickly identify the rows for which the mismatch occurred (for example by printing an additional primary key column). Must not be null at this stage.
      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 to
      invalid reference
      #getDefaultValueComparer()
      .
      columnValueComparers - Map of ValueComparers to use for specific columns. Key is column name in the table, value is ValueComparer to use in comparing expected to actual column values. Can be null and will default to using
      invalid reference
      #getDefaultColumnValueComparerMapForTable(String)
      or, if that is empty, defaultValueComparer for all columns in the table.
      Throws:
      DataSetException
      DatabaseUnitException
      Since:
      2.4, 2.6.0
    • compareData

      protected void compareData(ITable expectedTable, ITable actualTable, DbUnitAssert.ComparisonColumn[] comparisonCols, FailureHandler failureHandler, ValueComparer defaultValueComparer, Map<String,ValueComparer> columnValueComparers, int rowNum, int columnNum) throws DatabaseUnitException
      Throws:
      DatabaseUnitException
    • failIfNecessary

      protected void failIfNecessary(ITable expectedTable, ITable actualTable, FailureHandler failureHandler, int rowNum, String columnName, Object expectedValue, Object actualValue, String failMessage)
    • determineValueComparer

      protected ValueComparer determineValueComparer(String columnName, ValueComparer defaultValueComparer, Map<String,ValueComparer> columnValueComparers)
    • determineValidDefaultValueComparer

      protected ValueComparer determineValidDefaultValueComparer(ValueComparer defaultValueComparer)
    • determineValidTableColumnValueComparers

      protected Map<String,Map<String,ValueComparer>> determineValidTableColumnValueComparers(Map<String,Map<String,ValueComparer>> tableColumnValueComparers)
    • determineValidColumnValueComparers

      protected Map<String,ValueComparer> determineValidColumnValueComparers(Map<String,ValueComparer> columnValueComparers, String tableName)
    • setValueComparerDefaults

      public void setValueComparerDefaults(ValueComparerDefaults valueComparerDefaults)