use of org.xmlunit.diff.Difference 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();
}
use of org.xmlunit.diff.Difference in project irontest by zheng-wang.
the class XMLUtils method compareXML.
/**
* @param control
* @param test
* @param namespaceAware
* @return differences found, in a format for print
*/
public static String compareXML(String control, String test, boolean namespaceAware) {
Object controlObject = control;
Object testObject = test;
// DiffBuilder.withDocumentBuilderFactory(factory);
if (!namespaceAware) {
try {
controlObject = xmlStringToDOM(control);
testObject = xmlStringToDOM(test);
} catch (Exception e) {
throw new RuntimeException(e.getCause().getMessage(), e);
}
}
StringBuilder differencesSB = new StringBuilder();
Diff diff;
try {
diff = DiffBuilder.compare(controlObject).withTest(testObject).normalizeWhitespace().withDifferenceEvaluator(DifferenceEvaluators.chain(DifferenceEvaluators.Default, new PlaceholderDifferenceEvaluator("#\\{", null))).build();
} catch (XMLUnitException e) {
throw new RuntimeException(e.getCause().getMessage(), e);
}
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();
}
Aggregations