Search in sources :

Example 1 with Difference

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());
}
Also used : Diff(org.custommonkey.xmlunit.Diff) Difference(org.custommonkey.xmlunit.Difference)

Example 2 with Difference

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;
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Difference(org.custommonkey.xmlunit.Difference)

Example 3 with Difference

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());
    }
}
Also used : StringWriter(java.io.StringWriter) Diff(org.custommonkey.xmlunit.Diff) Node(org.w3c.dom.Node) DifferenceListener(org.custommonkey.xmlunit.DifferenceListener) Difference(org.custommonkey.xmlunit.Difference) PrintWriter(java.io.PrintWriter)

Example 4 with Difference

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;
}
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)

Example 5 with Difference

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;
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Difference(org.custommonkey.xmlunit.Difference)

Aggregations

Difference (org.custommonkey.xmlunit.Difference)10 DetailedDiff (org.custommonkey.xmlunit.DetailedDiff)7 Diff (org.custommonkey.xmlunit.Diff)5 DifferenceListener (org.custommonkey.xmlunit.DifferenceListener)3 Node (org.w3c.dom.Node)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 EjbJar$JAXB (org.apache.openejb.jee.EjbJar$JAXB)1 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)1 ElementNameQualifier (org.custommonkey.xmlunit.ElementNameQualifier)1 IgnoreTextAndAttributeValuesDifferenceListener (org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener)1