Search in sources :

Example 1 with ITableIterator

use of org.dbunit.dataset.ITableIterator in project sharding-jdbc by shardingjdbc.

the class SQLAssertHelper method assertResult.

public void assertResult(final Connection connection, final File file) throws MalformedURLException, SQLException, DatabaseUnitException {
    if (sql.contains("TEMP")) {
        return;
    }
    ITableIterator expectedTableIterator = new FlatXmlDataSetBuilder().build(file).iterator();
    try (Connection conn = connection) {
        while (expectedTableIterator.next()) {
            ITable expectedTable = expectedTableIterator.getTable();
            String actualTableName = expectedTable.getTableMetaData().getTableName();
            String verifySql = "SELECT * FROM " + actualTableName + " WHERE status = '" + getStatus(file) + "'" + getOrderByCondition(actualTableName);
            ITable actualTable = DBUnitUtil.getConnection(new DatabaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn).createQueryTable(actualTableName, verifySql);
            Assertion.assertEquals(expectedTable, actualTable);
        }
    }
}
Also used : DatabaseEnvironment(io.shardingjdbc.core.common.env.DatabaseEnvironment) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) ITableIterator(org.dbunit.dataset.ITableIterator) ITable(org.dbunit.dataset.ITable) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

Aggregations

DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)1 Connection (java.sql.Connection)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1 ITable (org.dbunit.dataset.ITable)1 ITableIterator (org.dbunit.dataset.ITableIterator)1 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)1