use of org.custommonkey.xmlunit.Difference in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method assertXmlEqual.
private void assertXmlEqual(String expected, String actual) throws SAXException, IOException {
XMLUnit.setIgnoreWhitespace(true);
Diff diff = new Diff(expected, actual) {
@Override
public int differenceFound(Difference difference) {
if (difference.getControlNodeDetail().getNode().getNodeName().matches("started-at|finished-at")) {
return 0;
}
return super.differenceFound(difference);
}
};
assertTrue("XML files are similar " + diff + "\nFormatterOutput = " + actual, diff.identical());
}
use of org.custommonkey.xmlunit.Difference in project opennms by OpenNMS.
the class AccessPointMonitorConfigTest method getDiff.
@SuppressWarnings("unchecked")
private DetailedDiff getDiff(StringWriter objectXML, StringBuffer exampleXML) throws SAXException, IOException {
DetailedDiff myDiff = new DetailedDiff(XMLUnit.compareXML(exampleXML.toString(), objectXML.toString()));
List<Difference> allDifferences = myDiff.getAllDifferences();
if (allDifferences.size() > 0) {
for (Difference d : allDifferences) {
System.err.println(d);
}
}
return myDiff;
}
use of org.custommonkey.xmlunit.Difference in project camel by apache.
the class XmlFixture method assertXMLIgnorePrefix.
public static void assertXMLIgnorePrefix(String aMessage, Document aExpected, Document aActual) throws Exception {
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreAttributeOrder(true);
Diff diff = new Diff(aExpected, aActual);
diff.overrideDifferenceListener(new DifferenceListener() {
public void skippedComparison(Node aArg0, Node aArg1) {
}
public int differenceFound(Difference aDifference) {
if (aDifference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
}
return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
});
try {
XMLAssert.assertXMLEqual(diff, true);
} catch (Throwable t) {
dump(aActual);
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
fail(sw.toString());
}
}
use of org.custommonkey.xmlunit.Difference in project opennms by OpenNMS.
the class XmlTest method getDifferences.
protected List<Difference> getDifferences(final String xmlA, final String xmlB) {
DetailedDiff myDiff;
try {
myDiff = new DetailedDiff(XMLUnit.compareXML(xmlA, xmlB));
} catch (final Exception e) {
throw new RuntimeException(e);
}
final List<Difference> retDifferences = new ArrayList<Difference>();
@SuppressWarnings("unchecked") final List<Difference> allDifferences = myDiff.getAllDifferences();
if (allDifferences.size() > 0) {
DIFFERENCES: for (final Difference d : allDifferences) {
final NodeDetail controlNodeDetail = d.getControlNodeDetail();
final String control = controlNodeDetail.getValue();
final NodeDetail testNodeDetail = d.getTestNodeDetail();
final String test = testNodeDetail.getValue();
if (d.getDescription().equals("namespace URI")) {
if (control != null && !"null".equals(control)) {
if (ignoreNamespace(control.toLowerCase())) {
LOG.trace("Ignoring {}: {}", d.getDescription(), d);
continue DIFFERENCES;
}
}
if (test != null && !"null".equals(test)) {
if (ignoreNamespace(test.toLowerCase())) {
LOG.trace("Ignoring {}: {}", d.getDescription(), d);
continue DIFFERENCES;
}
}
} else if (d.getDescription().equals("namespace prefix")) {
if (control != null && !"null".equals(control)) {
if (ignorePrefix(control.toLowerCase())) {
LOG.trace("Ignoring {}: {}", d.getDescription(), d);
continue DIFFERENCES;
}
}
if (test != null && !"null".equals(test)) {
if (ignorePrefix(test.toLowerCase())) {
LOG.trace("Ignoring {}: {}", d.getDescription(), d);
continue DIFFERENCES;
}
}
} else if (d.getDescription().equals("xsi:schemaLocation attribute")) {
LOG.debug("Schema location '{}' does not match. Ignoring.", controlNodeDetail.getValue() == null ? testNodeDetail.getValue() : controlNodeDetail.getValue());
continue DIFFERENCES;
}
if (ignoreDifference(d)) {
LOG.debug("ignoreDifference matched. Ignoring difference: {}: {}", d.getDescription(), d);
continue DIFFERENCES;
} else {
LOG.warn("Found difference: {}: {}", d.getDescription(), d);
retDifferences.add(d);
}
}
}
return retDifferences;
}
use of org.custommonkey.xmlunit.Difference in project opennms by OpenNMS.
the class JdbcDataCollectionConfigTest method getDiff.
@SuppressWarnings("unchecked")
private DetailedDiff getDiff(StringWriter objectXML, StringBuffer exampleXML) throws SAXException, IOException {
DetailedDiff myDiff = new DetailedDiff(XMLUnit.compareXML(exampleXML.toString(), objectXML.toString()));
List<Difference> allDifferences = myDiff.getAllDifferences();
if (allDifferences.size() > 0) {
for (Difference d : allDifferences) {
System.err.println(d);
}
}
return myDiff;
}
Aggregations