org.dbunit.assertion
Class DbUnitAssert

java.lang.Object
  extended by org.dbunit.assertion.DbUnitAssert

public class DbUnitAssert
extends Object

Default implementation of DbUnit assertions, based on the original methods present at Assertion

Since:
2.4.0
Version:
$Revision$ $Date$
Author:
Felipe Leme (dbunit@felipeal.net), gommma (gommma AT users.sourceforge.net)

Nested Class Summary
static class DbUnitAssert.ComparisonColumn
          Represents a single column to be used for the comparison of table data.
 
Constructor Summary
DbUnitAssert()
           
 
Method Summary
 void assertEquals(IDataSet expectedDataSet, IDataSet actualDataSet)
          Asserts that the two specified dataset are equals.
 void assertEquals(IDataSet expectedDataSet, IDataSet actualDataSet, FailureHandler failureHandler)
          Asserts that the two specified dataset are equals.
 void assertEquals(ITable expectedTable, ITable actualTable)
          Asserts that the two specified tables are equals.
 void assertEquals(ITable expectedTable, ITable actualTable, Column[] additionalColumnInfo)
          Asserts that the two specified tables are equals.
 void assertEquals(ITable expectedTable, ITable actualTable, FailureHandler failureHandler)
          Asserts that the two specified tables are equals.
 void assertEqualsByQuery(IDataSet expectedDataset, IDatabaseConnection connection, String sqlQuery, String tableName, String[] ignoreCols)
          Compare a table from a dataset with a table generated from an sql query.
 void assertEqualsByQuery(ITable expectedTable, IDatabaseConnection connection, String tableName, String sqlQuery, String[] ignoreCols)
          Compare a table with a table generated from an sql query.
 void assertEqualsIgnoreCols(IDataSet expectedDataset, IDataSet actualDataset, String tableName, String[] ignoreCols)
          Compare one table present in two datasets ignoring specified columns.
 void assertEqualsIgnoreCols(ITable expectedTable, ITable actualTable, String[] ignoreCols)
          Compare the given tables ignoring specified columns.
protected  void compareData(ITable expectedTable, ITable actualTable, DbUnitAssert.ComparisonColumn[] comparisonCols, FailureHandler failureHandler)
           
protected  DbUnitAssert.ComparisonColumn[] getComparisonColumns(String expectedTableName, Column[] expectedColumns, Column[] actualColumns, FailureHandler failureHandler)
           
protected  FailureHandler getDefaultFailureHandler()
           
protected  FailureHandler getDefaultFailureHandler(Column[] additionalColumnInfo)
           
protected  String[] getSortedUpperTableNames(IDataSet dataSet)
           
protected  boolean skipCompare(String columnName, Object expectedValue, Object actualValue)
          Method to last-minute intercept the comparison of a single expected and actual value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbUnitAssert

public DbUnitAssert()
Method Detail

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

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

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

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

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

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

getSortedUpperTableNames

protected String[] getSortedUpperTableNames(IDataSet dataSet)
                                     throws DataSetException
Throws:
DataSetException


Copyright © 2002-2012. All Rights Reserved.