Example usage for org.apache.commons.beanutils DynaBean toString

List of usage examples for org.apache.commons.beanutils DynaBean toString

Introduction

In this page you can find the example usage for org.apache.commons.beanutils DynaBean toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.apache.ddlutils.DatabaseTestHelper.java

/**
 * Asserts that the data in the tables described by the given model is the same in the
 * database accessed by the second platform as is in the database accessed by the first platform.
 * Note that it is not tested whether the second database has more data.<br/>
 * All differences will be printed via logging in DEBUG level.
 * //from ww w .  j av a  2s  .  c o m
 * @param failureMsg        The failure message to issue if the data is not the same
 * @param model             The database model to check
 * @param origDbPlatform    The first platform
 * @param testedDbPlatform  The second platform
 */
public void assertHasSameData(String failureMsg, Database model, Platform origDbPlatform,
        Platform testedDbPlatform) {
    boolean hasError = false;

    for (int idx = 0; idx < model.getTableCount(); idx++) {
        Table table = model.getTable(idx);
        Column[] pkCols = table.getPrimaryKeyColumns();

        for (Iterator it = origDbPlatform.query(model, buildQueryString(origDbPlatform, table, null, null),
                new Table[] { table }); it.hasNext();) {
            DynaBean obj = (DynaBean) it.next();
            Collection result = testedDbPlatform.fetch(model,
                    buildQueryString(origDbPlatform, table, pkCols, obj), new Table[] { table });

            if (result.isEmpty()) {
                if (_log.isDebugEnabled()) {
                    hasError = true;
                    _log.debug("Row " + obj.toString() + " is not present in second database");
                } else {
                    throw new AssertionFailedError(failureMsg);
                }
            } else if (result.size() > 1) {
                if (_log.isDebugEnabled()) {
                    hasError = true;

                    StringBuffer debugMsg = new StringBuffer();

                    debugMsg.append("Row ");
                    debugMsg.append(obj.toString());
                    debugMsg.append(" is present more than once in the second database:\n");
                    for (Iterator resultIt = result.iterator(); resultIt.hasNext();) {
                        debugMsg.append("  ");
                        debugMsg.append(resultIt.next().toString());
                    }
                    _log.debug(debugMsg.toString());
                } else {
                    throw new AssertionFailedError(failureMsg);
                }
            } else {
                DynaBean otherObj = (DynaBean) result.iterator().next();

                if (!obj.equals(otherObj)) {
                    if (_log.isDebugEnabled()) {
                        hasError = true;

                        _log.debug("Row " + obj.toString() + " is different in the second database: "
                                + otherObj.toString());
                    } else {
                        throw new AssertionFailedError(failureMsg);
                    }
                }
            }
        }
    }
    if (hasError) {
        throw new AssertionFailedError(failureMsg);
    }
}