Search in sources :

Example 16 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project zm-mailbox by Zimbra.

the class JaxbToElementTest method jaxBToElementTest.

@Test
public void jaxBToElementTest() throws Exception {
    for (int cnt = 1; cnt <= iterationNum; cnt++) {
        Element el = JaxbUtil.jaxbToElement(getInfoRespJaxb);
        String actual = el.prettyPrint();
        String expected = getInfoResponseXml;
        DetailedDiff myDiff = new DetailedDiff(XMLUnit.compareXML(expected, actual));
        List allDifferences = myDiff.getAllDifferences();
        if (allDifferences.size() > 0) {
            ZimbraLog.test.debug("Iteration:%s - %s differences found.  Compare below with '%s'\n%s\n", cnt, allDifferences.size(), getInfoResponseXMLfileName, actual);
            int diffnum = 0;
            for (Object obj : allDifferences) {
                ZimbraLog.test.info("Difference:%s [%s]", diffnum++, obj);
            }
            XMLAssert.assertXMLEqual(expected, actual);
        }
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) List(java.util.List) Test(org.junit.Test)

Example 17 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project cayenne by apache.

the class DbImporterTaskTest method verifyResult.

@SuppressWarnings("unchecked")
private void verifyResult(File map, File mapFileCopy) {
    try {
        FileReader control = new FileReader(map.getAbsolutePath() + "-result");
        FileReader test = new FileReader(mapFileCopy);
        DetailedDiff diff = new DetailedDiff(new Diff(control, test));
        if (!diff.similar()) {
            for (Difference d : ((List<Difference>) diff.getAllDifferences())) {
                System.out.println("-------------------------------------------");
                System.out.println(d.getTestNodeDetail().getNode());
                System.out.println(d.getControlNodeDetail().getValue());
            }
            fail(diff.toString());
        }
    } catch (SAXException | IOException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) FileReader(java.io.FileReader) Difference(org.custommonkey.xmlunit.Difference) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 18 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff 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 19 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff 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)

Example 20 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.

the class PersistenceSerializationTest method getDiff.

@SuppressWarnings("unchecked")
private static 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

DetailedDiff (org.custommonkey.xmlunit.DetailedDiff)39 Diff (org.custommonkey.xmlunit.Diff)16 Difference (org.custommonkey.xmlunit.Difference)16 Test (org.junit.Test)16 Document (org.w3c.dom.Document)7 File (java.io.File)6 List (java.util.List)6 IOException (java.io.IOException)5 StringWriter (java.io.StringWriter)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Element (org.w3c.dom.Element)5 BufferedInputStream (java.io.BufferedInputStream)4 BufferedReader (java.io.BufferedReader)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 AssertionFailedError (junit.framework.AssertionFailedError)4