Search in sources :

Example 1 with IgnoreTextAndAttributeValuesDifferenceListener

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

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URL (java.net.URL)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EjbJar$JAXB (org.apache.openejb.jee.EjbJar$JAXB)1 DetailedDiff (org.custommonkey.xmlunit.DetailedDiff)1 Diff (org.custommonkey.xmlunit.Diff)1 Difference (org.custommonkey.xmlunit.Difference)1 IgnoreTextAndAttributeValuesDifferenceListener (org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener)1