Search in sources :

Example 36 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project mule by mulesoft.

the class ExtensionsTestUtils method compareXML.

/**
 * Receives to {@link String} representation of two XML files and verify that they are semantically equivalent
 *
 * @param expected the reference content
 * @param actual   the actual content
 * @throws Exception if comparison fails
 */
public static void compareXML(String expected, String actual) throws Exception {
    XMLUnit.setNormalizeWhitespace(true);
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreAttributeOrder(false);
    Diff diff = XMLUnit.compareXML(expected, actual);
    if (!(diff.similar() && diff.identical())) {
        System.out.println(actual);
        DetailedDiff detDiff = new DetailedDiff(diff);
        @SuppressWarnings("rawtypes") List differences = detDiff.getAllDifferences();
        StringBuilder diffLines = new StringBuilder();
        for (Object object : differences) {
            Difference difference = (Difference) object;
            diffLines.append(difference.toString() + '\n');
        }
        throw new IllegalArgumentException("Actual XML differs from expected: \n" + diffLines.toString());
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Difference(org.custommonkey.xmlunit.Difference)

Example 37 with DetailedDiff

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

the class ConversionTest method testConversion.

public void testConversion() throws Exception {
    final JAXBElement element = (JAXBElement) JaxbOpenejbJar2.unmarshal(OpenejbJarType.class, getInputStream("openejb-jar-2-full.xml"));
    final OpenejbJarType o2 = (OpenejbJarType) element.getValue();
    final GeronimoEjbJarType g2 = new GeronimoEjbJarType();
    g2.setEnvironment(o2.getEnvironment());
    g2.setSecurity(o2.getSecurity());
    g2.getService().addAll(o2.getService());
    g2.getMessageDestination().addAll(o2.getMessageDestination());
    for (final EnterpriseBean bean : o2.getEnterpriseBeans()) {
        g2.getAbstractNamingEntry().addAll(bean.getAbstractNamingEntry());
        g2.getPersistenceContextRef().addAll(bean.getPersistenceContextRef());
        g2.getEjbLocalRef().addAll(bean.getEjbLocalRef());
        g2.getEjbRef().addAll(bean.getEjbRef());
        g2.getResourceEnvRef().addAll(bean.getResourceEnvRef());
        g2.getResourceRef().addAll(bean.getResourceRef());
        g2.getServiceRef().addAll(bean.getServiceRef());
        if (bean instanceof RpcBean) {
            final RpcBean rpcBean = (RpcBean) bean;
            if (rpcBean.getTssLink() != null) {
                g2.getTssLink().add(new TssLinkType(rpcBean.getEjbName(), rpcBean.getTssLink(), rpcBean.getJndiName()));
            }
        }
    }
    final JAXBElement root = new JAXBElement(new QName("http://geronimo.apache.org/xml/ns/j2ee/ejb/openejb-2.0", "ejb-jar"), GeronimoEjbJarType.class, g2);
    final String result = JaxbOpenejbJar2.marshal(GeronimoEjbJarType.class, root);
    final String expected = readContent(getInputStream("geronimo-openejb-converted.xml"));
    final Diff myDiff = new DetailedDiff(new Diff(expected, result));
    // just to get an int wrapper for the test
    final AtomicInteger differenceNumber = new AtomicInteger(0);
    myDiff.overrideDifferenceListener(new DifferenceListener() {

        @Override
        public int differenceFound(final Difference difference) {
            if (!difference.isRecoverable()) {
                differenceNumber.incrementAndGet();
                System.err.println(">>> " + difference.toString());
            }
            return 0;
        }

        @Override
        public void skippedComparison(final Node node, final Node node1) {
        // no-op
        }
    });
    assertTrue("Files are not similar", myDiff.similar());
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) JAXBElement(javax.xml.bind.JAXBElement) Difference(org.custommonkey.xmlunit.Difference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DifferenceListener(org.custommonkey.xmlunit.DifferenceListener)

Example 38 with DetailedDiff

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

the class EjbJarXmlTest method testEjbJar.

/**
 * TODO Doesn't seem there are any asserts here
 *
 * @throws Exception
 */
public void testEjbJar() throws Exception {
    final String fileName = "ejb-jar-example1.xml";
    final Event test = Event.start("Test");
    final URL resource = this.getClass().getClassLoader().getResource(fileName);
    final String expected = IO.slurp(resource);
    final Event ejbJarJAXBCreate = Event.start("EjbJarJAXBCreate");
    ejbJarJAXBCreate.stop();
    final Event unmarshalEvent = Event.start("unmarshal");
    final Object value;
    final EjbJar$JAXB jaxbType = new EjbJar$JAXB();
    value = Sxc.unmarshalJavaee(resource, jaxbType);
    unmarshalEvent.stop();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final Event marshall = Event.start("marshall");
    Sxc.marshall(jaxbType, value, baos);
    marshall.stop();
    final String result = new String(baos.toByteArray(), "UTF-8");
    XMLUnit.setIgnoreComments(Boolean.TRUE);
    XMLUnit.setIgnoreWhitespace(Boolean.TRUE);
    XMLUnit.setIgnoreAttributeOrder(Boolean.TRUE);
    XMLUnit.setIgnoreDiffBetweenTextAndCDATA(Boolean.TRUE);
    final Diff diff = new Diff(expected.trim(), result.trim());
    final Diff myDiff = new DetailedDiff(diff);
    // just to get an int wrapper for the test
    final AtomicInteger differenceNumber = new AtomicInteger(0);
    myDiff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener() {

        @Override
        public int differenceFound(final Difference difference) {
            if (!difference.isRecoverable()) {
                differenceNumber.incrementAndGet();
                System.err.println(">>> " + difference.toString());
            }
            return 0;
        }
    });
    assertTrue("Files are not identical", myDiff.identical());
    test.stop();
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgnoreTextAndAttributeValuesDifferenceListener(org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Difference(org.custommonkey.xmlunit.Difference) URL(java.net.URL) EjbJar$JAXB(org.apache.openejb.jee.EjbJar$JAXB)

Example 39 with DetailedDiff

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

the class DbImporterMojoTest method verifyResult.

private void verifyResult(File map, File mapFileCopy) {
    try {
        FileReader control = new FileReader(map.getAbsolutePath() + "-result");
        FileReader test = new FileReader(mapFileCopy);
        Diff prototype = new Diff(control, test);
        prototype.overrideElementQualifier(new ElementNameAndAttributeQualifier());
        DetailedDiff diff = new DetailedDiff(prototype);
        if (!diff.similar()) {
            fail(diff.toString());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) ElementNameAndAttributeQualifier(org.custommonkey.xmlunit.ElementNameAndAttributeQualifier) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) FileReader(java.io.FileReader) SQLException(java.sql.SQLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

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