org.dbunit.assertion.FailureHandler Java Examples

The following examples show how to use org.dbunit.assertion.FailureHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HackedDbUnitAssert.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void compareDataContains(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler) throws DataSetException {
    logger.debug("compareData(expectedTable={}, actualTable={}, " + "comparisonCols={}, failureHandler={}) - start", new Object[] { expectedTable, actualTable, comparisonCols, failureHandler });

    if (expectedTable == null) {
        throw new NullPointerException("The parameter 'expectedTable' must not be null");
    }
    if (actualTable == null) {
        throw new NullPointerException("The parameter 'actualTable' must not be null");
    }
    if (comparisonCols == null) {
        throw new NullPointerException("The parameter 'comparisonCols' must not be null");
    }
    if (failureHandler == null) {
        throw new NullPointerException("The parameter 'failureHandler' must not be null");
    }

    for (int index = 0; index < actualTable.getRowCount(); index++) {
        if (!findRowInExpectedTable(expectedTable, actualTable, comparisonCols, failureHandler, index)) {
            throw new IllegalStateException();
        }
    }

}
 
Example #2
Source File: HackedDbUnitAssert.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void compareDataContains(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler) throws DataSetException {
    logger.debug("compareData(expectedTable={}, actualTable={}, " + "comparisonCols={}, failureHandler={}) - start", new Object[] { expectedTable, actualTable, comparisonCols, failureHandler });

    if (expectedTable == null) {
        throw new NullPointerException("The parameter 'expectedTable' must not be null");
    }
    if (actualTable == null) {
        throw new NullPointerException("The parameter 'actualTable' must not be null");
    }
    if (comparisonCols == null) {
        throw new NullPointerException("The parameter 'comparisonCols' must not be null");
    }
    if (failureHandler == null) {
        throw new NullPointerException("The parameter 'failureHandler' must not be null");
    }

    for (int index = 0; index < actualTable.getRowCount(); index++) {
        if (!findRowInExpectedTable(expectedTable, actualTable, comparisonCols, failureHandler, index)) {
            throw new IllegalStateException();
        }
    }

}
 
Example #3
Source File: HackedDbUnitAssert.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ComparisonColumn[] getComparisonColumns(String expectedTableName, Column[] expectedColumns, Column[] actualColumns, FailureHandler failureHandler) {
    ComparisonColumn[] result = new ComparisonColumn[expectedColumns.length];

    for (int j = 0; j < expectedColumns.length; j++) {
        Column expectedColumn = expectedColumns[j];
        Column actualColumn = actualColumns[j];
        result[j] = new HackedComparisonColumn(expectedTableName, expectedColumn, actualColumn, failureHandler);
    }
    return result;
}
 
Example #4
Source File: HackedDbUnitAssert.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public HackedComparisonColumn(String tableName, Column expectedColumn, Column actualColumn, FailureHandler failureHandler) {
    
    // super class is actually useless, all public methods are overridden below
    super(tableName, expectedColumn, expectedColumn, failureHandler);
    
    this.columnName = expectedColumn.getColumnName();
    this.dataType = getComparisonDataType(tableName, expectedColumn, actualColumn, failureHandler);
}
 
Example #5
Source File: HackedDbUnitAssert.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private DataType getComparisonDataType(String tableName, Column expectedColumn, Column actualColumn, FailureHandler failureHandler) {
    if (logger.isDebugEnabled())
        logger.debug("getComparisonDataType(tableName={}, expectedColumn={}, actualColumn={}, failureHandler={}) - start", new Object[] { tableName, expectedColumn, actualColumn, failureHandler });

    DataType expectedDataType = expectedColumn.getDataType();
    DataType actualDataType = actualColumn.getDataType();

    // The two columns have different data type
    if (!expectedDataType.getClass().isInstance(actualDataType)) {
        // Expected column data type is unknown, use actual column data type
        if (expectedDataType instanceof UnknownDataType) {
            return actualDataType;
        }

        // Actual column data type is unknown, use expected column data type
        if (actualDataType instanceof UnknownDataType) {
            return expectedDataType;
        }
        
        if (hackIgnoreIntBigIntMismatch) {
            if (expectedDataType instanceof IntegerDataType && actualDataType instanceof BigIntegerDataType)
                return actualDataType;
        }

        // Impossible to determine which data type to use
        String msg = "Incompatible data types: (table=" + tableName + ", col=" + expectedColumn.getColumnName() + ")";
        throw failureHandler.createFailure(msg, String.valueOf(expectedDataType), String.valueOf(actualDataType));
    }

    // Both columns have same data type, return any one of them
    return expectedDataType;
}
 
Example #6
Source File: HackedDbUnitAssert.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected ComparisonColumn[] getComparisonColumns(String expectedTableName, Column[] expectedColumns, Column[] actualColumns, FailureHandler failureHandler) {
    ComparisonColumn[] result = new ComparisonColumn[expectedColumns.length];

    for (int j = 0; j < expectedColumns.length; j++) {
        Column expectedColumn = expectedColumns[j];
        Column actualColumn = actualColumns[j];
        result[j] = new HackedComparisonColumn(expectedTableName, expectedColumn, actualColumn, failureHandler);
    }
    return result;
}
 
Example #7
Source File: HackedDbUnitAssert.java    From kylin with Apache License 2.0 5 votes vote down vote up
public HackedComparisonColumn(String tableName, Column expectedColumn, Column actualColumn, FailureHandler failureHandler) {
    
    // super class is actually useless, all public methods are overridden below
    super(tableName, expectedColumn, expectedColumn, failureHandler);
    
    this.columnName = expectedColumn.getColumnName();
    this.dataType = getComparisonDataType(tableName, expectedColumn, actualColumn, failureHandler);
}
 
Example #8
Source File: HackedDbUnitAssert.java    From kylin with Apache License 2.0 5 votes vote down vote up
private DataType getComparisonDataType(String tableName, Column expectedColumn, Column actualColumn, FailureHandler failureHandler) {
    if (logger.isDebugEnabled())
        logger.debug("getComparisonDataType(tableName={}, expectedColumn={}, actualColumn={}, failureHandler={}) - start", new Object[] { tableName, expectedColumn, actualColumn, failureHandler });

    DataType expectedDataType = expectedColumn.getDataType();
    DataType actualDataType = actualColumn.getDataType();

    // The two columns have different data type
    if (!expectedDataType.getClass().isInstance(actualDataType)) {
        // Expected column data type is unknown, use actual column data type
        if (expectedDataType instanceof UnknownDataType) {
            return actualDataType;
        }

        // Actual column data type is unknown, use expected column data type
        if (actualDataType instanceof UnknownDataType) {
            return expectedDataType;
        }
        
        if (hackIgnoreIntBigIntMismatch) {
            if (expectedDataType instanceof IntegerDataType && actualDataType instanceof BigIntegerDataType)
                return actualDataType;
        }

        // Impossible to determine which data type to use
        String msg = "Incompatible data types: (table=" + tableName + ", col=" + expectedColumn.getColumnName() + ")";
        throw failureHandler.createFailure(msg, String.valueOf(expectedDataType), String.valueOf(actualDataType));
    }

    // Both columns have same data type, return any one of them
    return expectedDataType;
}
 
Example #9
Source File: HackedDbUnitAssert.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
private boolean findRowInExpectedTable(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler, int index) throws DataSetException {

        // iterate over all rows
        for (int i = 0; i < expectedTable.getRowCount(); i++) {

            // iterate over all columns of the current row
            for (int j = 0; j < comparisonCols.length; j++) {
                ComparisonColumn compareColumn = comparisonCols[j];

                String columnName = compareColumn.getColumnName();
                DataType dataType = compareColumn.getDataType();

                Object expectedValue = expectedTable.getValue(i, columnName);
                Object actualValue = actualTable.getValue(index, columnName);

                // Compare the values
                if (skipCompare(columnName, expectedValue, actualValue)) {
                    if (logger.isTraceEnabled()) {
                        logger.trace("ignoring comparison " + expectedValue + "=" + actualValue + " on column " + columnName);
                    }
                    continue;
                }

                if (dataType.compare(expectedValue, actualValue) != 0) {
                    break;

                    //                    Difference diff = new Difference(expectedTable, actualTable, i, columnName, expectedValue, actualValue);
                    //
                    //                    // Handle the difference (throw error immediately or something else)
                    //                    failureHandler.handle(diff);
                } else {
                    if (j == comparisonCols.length - 1) {
                        return true;
                    } else {
                        continue;
                    }
                }
            }
        }
        return false;
    }
 
Example #10
Source File: HackedDbUnitAssert.java    From kylin with Apache License 2.0 4 votes vote down vote up
private boolean findRowInExpectedTable(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler, int index) throws DataSetException {

        // iterate over all rows
        for (int i = 0; i < expectedTable.getRowCount(); i++) {

            // iterate over all columns of the current row
            for (int j = 0; j < comparisonCols.length; j++) {
                ComparisonColumn compareColumn = comparisonCols[j];

                String columnName = compareColumn.getColumnName();
                DataType dataType = compareColumn.getDataType();

                Object expectedValue = expectedTable.getValue(i, columnName);
                Object actualValue = actualTable.getValue(index, columnName);

                // Compare the values
                if (skipCompare(columnName, expectedValue, actualValue)) {
                    if (logger.isTraceEnabled()) {
                        logger.trace("ignoring comparison " + expectedValue + "=" + actualValue + " on column " + columnName);
                    }
                    continue;
                }

                if (dataType.compare(expectedValue, actualValue) != 0) {
                    break;

                    //                    Difference diff = new Difference(expectedTable, actualTable, i, columnName, expectedValue, actualValue);
                    //
                    //                    // Handle the difference (throw error immediately or something else)
                    //                    failureHandler.handle(diff);
                } else {
                    if (j == comparisonCols.length - 1) {
                        return true;
                    } else {
                        continue;
                    }
                }
            }
        }
        return false;
    }