Search in sources :

Example 1 with NodeDetail

use of org.custommonkey.xmlunit.NodeDetail 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;
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) NodeDetail(org.custommonkey.xmlunit.NodeDetail) ArrayList(java.util.ArrayList) Difference(org.custommonkey.xmlunit.Difference) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 DetailedDiff (org.custommonkey.xmlunit.DetailedDiff)1 Difference (org.custommonkey.xmlunit.Difference)1 NodeDetail (org.custommonkey.xmlunit.NodeDetail)1