Class DbUnitAssert

java.lang.Object
org.dbunit.assertion.DbUnitAssertBase
org.dbunit.assertion.DbUnitAssert

public class DbUnitAssert extends DbUnitAssertBase
Default implementation of DbUnit assertions, based on the original methods present at Assertion. All are equality comparisons.
Since:
2.4.0
Version:
$Revision$ $Date$
Author:
Felipe Leme (dbunit@felipeal.net), gommma (gommma AT users.sourceforge.net)
  • Constructor Details

    • DbUnitAssert

      public DbUnitAssert()
  • Method Details

    • assertEqualsIgnoreCols

      public void assertEqualsIgnoreCols(IDataSet expectedDataset, IDataSet actualDataset, String tableName, String[] ignoreCols) throws DatabaseUnitException
      Compare one table present in two datasets ignoring specified columns.
      Parameters:
      expectedDataset - First dataset.
      actualDataset - Second dataset.
      tableName - Table name of the table to be compared.
      ignoreCols - Columns to be ignored in comparison.
      Throws:
      DatabaseUnitException - If an error occurs.
    • assertEqualsIgnoreCols

      public void assertEqualsIgnoreCols(ITable expectedTable, ITable actualTable, String[] ignoreCols) throws DatabaseUnitException
      Compare the given tables ignoring specified columns.
      Parameters:
      expectedTable - First table.
      actualTable - Second table.
      ignoreCols - Columns to be ignored in comparison.
      Throws:
      DatabaseUnitException - If an error occurs.
    • assertEqualsByQuery

      public void assertEqualsByQuery(IDataSet expectedDataset, IDatabaseConnection connection, String sqlQuery, String tableName, String[] ignoreCols) throws DatabaseUnitException, SQLException
      Compare a table from a dataset with a table generated from an sql query.
      Parameters:
      expectedDataset - Dataset to retrieve the first table from.
      connection - Connection to use for the SQL statement.
      sqlQuery - SQL query that will build the data in returned second table rows.
      tableName - Table name of the table to compare.
      ignoreCols - Columns to be ignored in comparison.
      Throws:
      DatabaseUnitException - If an error occurs while performing the comparison.
      SQLException - If an SQL error occurs.
    • assertEqualsByQuery

      public void assertEqualsByQuery(ITable expectedTable, IDatabaseConnection connection, String tableName, String sqlQuery, String[] ignoreCols) throws DatabaseUnitException, SQLException
      Compare a table with a table generated from an sql query.
      Parameters:
      expectedTable - Table containing all expected results.
      connection - Connection to use for the SQL statement.
      tableName - The name of the table to query from the database.
      sqlQuery - SQL query that will build the data in returned second table rows.
      ignoreCols - Columns to be ignored in comparison.
      Throws:
      DatabaseUnitException - If an error occurs while performing the comparison.
      SQLException - If an SQL error occurs.
    • assertEquals

      public void assertEquals(IDataSet expectedDataSet, IDataSet actualDataSet) throws DatabaseUnitException
      Asserts that the two specified dataset are equals. This method ignore the tables order.
      Throws:
      DatabaseUnitException
    • assertEquals

      public void assertEquals(IDataSet expectedDataSet, IDataSet actualDataSet, FailureHandler failureHandler) throws DatabaseUnitException
      Asserts that the two specified dataset are equals. This method ignore the tables order.
      Throws:
      DatabaseUnitException
      Since:
      2.4
    • compareTables

      protected void compareTables(IDataSet expectedDataSet, IDataSet actualDataSet, String[] expectedNames, FailureHandler failureHandler) throws DatabaseUnitException
      Throws:
      DatabaseUnitException
    • assertEquals

      public void assertEquals(ITable expectedTable, ITable actualTable) throws DatabaseUnitException
      Asserts that the two specified tables are equals. This method ignores the table names, the columns order, the columns data type and which columns are composing the primary keys.
      Parameters:
      expectedTable - Table containing all expected results.
      actualTable - Table containing all actual results.
      Throws:
      DatabaseUnitException
    • assertEquals

      public void assertEquals(ITable expectedTable, ITable actualTable, Column[] additionalColumnInfo) throws DatabaseUnitException
      Asserts that the two specified tables are equals. This method ignores the table names, the columns order, the columns data type and which columns are composing the primary keys.
      Example:
       ITable actualTable = ...;
       ITable expectedTable = ...;
       ITableMetaData metaData = actualTable.getTableMetaData();
       Column[] additionalInfoCols = Columns.getColumns(new String[] {"MY_PK_COLUMN"}, metaData.getColumns());
       assertEquals(expectedTable, actualTable, additionalInfoCols);
       
      Parameters:
      expectedTable - Table containing all expected results.
      actualTable - Table containing all actual results.
      additionalColumnInfo - The columns to be printed out if the assert fails because of a data mismatch. Provides some additional column values that may be useful to quickly identify the columns for which the mismatch occurred (for example a primary key column). Can be null.
      Throws:
      DatabaseUnitException
    • assertEquals

      public void assertEquals(ITable expectedTable, ITable actualTable, FailureHandler failureHandler) throws DatabaseUnitException
      Asserts that the two specified tables are equals. This method ignores the table names, the columns order, the columns data type and which columns are composing the primary keys.
      Example:
       ITable actualTable = ...;
       ITable expectedTable = ...;
       ITableMetaData metaData = actualTable.getTableMetaData();
       FailureHandler failureHandler = new DefaultFailureHandler();
       assertEquals(expectedTable, actualTable, failureHandler);
       
      Parameters:
      expectedTable - Table containing all expected results.
      actualTable - Table 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.
      Throws:
      DatabaseUnitException
      Since:
      2.4