Search in sources :

Example 1 with PlaceholderDifferenceEvaluator

use of io.irontest.core.assertion.PlaceholderDifferenceEvaluator in project irontest by zheng-wang.

the class XMLUtils method compareXML.

/**
 * @param control
 * @param test
 * @return differences found, in a format for print
 */
public static String compareXML(String control, String test) {
    StringBuilder differencesSB = new StringBuilder();
    Diff diff;
    try {
        diff = DiffBuilder.compare(control).withTest(test).normalizeWhitespace().withDifferenceEvaluator(DifferenceEvaluators.chain(DifferenceEvaluators.Default, new PlaceholderDifferenceEvaluator())).build();
    } catch (XMLUnitException e) {
        throw new RuntimeException(e.getCause().getMessage());
    }
    if (diff.hasDifferences()) {
        Iterator it = diff.getDifferences().iterator();
        while (it.hasNext()) {
            Difference difference = (Difference) it.next();
            if (difference.getResult() == ComparisonResult.DIFFERENT) {
                // ignore SIMILAR comparison results
                if (differencesSB.length() > 0) {
                    differencesSB.append("\n");
                }
                differencesSB.append(difference.getComparison().toString());
            }
        }
    }
    return differencesSB.toString();
}
Also used : XMLUnitException(org.xmlunit.XMLUnitException) Diff(org.xmlunit.diff.Diff) Iterator(java.util.Iterator) Difference(org.xmlunit.diff.Difference) PlaceholderDifferenceEvaluator(io.irontest.core.assertion.PlaceholderDifferenceEvaluator)

Aggregations

PlaceholderDifferenceEvaluator (io.irontest.core.assertion.PlaceholderDifferenceEvaluator)1 Iterator (java.util.Iterator)1 XMLUnitException (org.xmlunit.XMLUnitException)1 Diff (org.xmlunit.diff.Diff)1 Difference (org.xmlunit.diff.Difference)1