org.dbunit.assertion.Difference Java Examples

The following examples show how to use org.dbunit.assertion.Difference. 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: DataSourceDBUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenInsertUnexpectedData_thenFail() throws Exception {
    try (InputStream is = getClass().getClassLoader()
        .getResourceAsStream("dbunit/expected-multiple-failures.xml")) {

        // given
        IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
        ITable expectedTable = expectedDataSet.getTable("ITEMS");
        Connection conn = getDataSource().getConnection();
        DiffCollectingFailureHandler collectingHandler = new DiffCollectingFailureHandler();

        // when
        conn.createStatement().executeUpdate("INSERT INTO ITEMS (title, price) VALUES ('Battery', '1000000')");
        ITable actualData = getConnection().createDataSet().getTable("ITEMS");

        // then
        Assertion.assertEquals(expectedTable, actualData, collectingHandler);
        if (!collectingHandler.getDiffList().isEmpty()) {
            String message = (String) collectingHandler.getDiffList().stream()
                .map(d -> formatDifference((Difference) d)).collect(joining("\n"));
            logger.error(() -> message);
        }
    }
}
 
Example #2
Source File: DataSetComparator.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
private void collectErrors(final AssertionErrorCollector errorCollector, final List<Difference> diffs) {
    for (final Difference diff : diffs) {
        final String tableName = diff.getActualTable().getTableMetaData().getTableName();
        errorCollector.collect(String.format(DIFF_ERROR, tableName, diff.getRowIndex(), diff.getColumnName(), diff.getExpectedValue(),
                diff.getActualValue()));
    }
}
 
Example #3
Source File: DataSourceDBUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
private static String formatDifference(Difference diff) {
    return "expected value in " + diff.getExpectedTable().getTableMetaData().getTableName() + "." + diff
        .getColumnName() + " row " + diff.getRowIndex() + ":" + diff.getExpectedValue() + ", but was: " + diff
        .getActualValue();
}