Search in sources :

Example 6 with Difference

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

the class TcaDataCollectionConfigTest method getDiff.

/**
	 * Gets the diff.
	 *
	 * @param objectXML the object XML
	 * @param exampleXML the example XML
	 * @return the detailed diff
	 * @throws SAXException the sAX exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
@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 7 with Difference

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

Example 8 with Difference

use of org.custommonkey.xmlunit.Difference 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 9 with Difference

use of org.custommonkey.xmlunit.Difference 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 10 with Difference

use of org.custommonkey.xmlunit.Difference in project ddf by codice.

the class TestCswFilterDelegate method testRelative.

@Test
public void testRelative() throws JAXBException, SAXException, IOException {
    long duration = 92000000000L;
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
    Map<String, Object> propMap = new HashMap<>();
    propMap.put("extendedComparisonOp", "relative");
    propMap.put("duration", new Long(duration));
    String xml = getXmlProperty(localCswFilterDelegate, propertyNameModified, BETWEEN, testStartDate.toCalendar(null).getTime(), testEndDate.toCalendar(null).getTime(), propMap);
    String durationCompare = duringXml.replace(REPLACE_START_DATE, "").replace(REPLACE_END_DATE, "").replace(REPLACE_TEMPORAL_PROPERTY, modifiedDateMapping);
    String pattern = "(?i)(<ns.:Literal>)(.+?)(</ns.:Literal>)";
    String compareXml = xml.replaceAll(pattern, "<ogc:Literal xmlns:ogc=\"http://www.opengis.net/ogc\"></ogc:Literal>");
    Diff xmlDiff = new Diff(durationCompare, compareXml);
    xmlDiff.overrideElementQualifier(new ElementNameQualifier() {

        @Override
        protected boolean equalsNamespace(Node control, Node test) {
            return true;
        }
    });
    xmlDiff.overrideDifferenceListener(new DifferenceListener() {

        @Override
        public int differenceFound(Difference diff) {
            if (diff.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
                return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
            }
            return RETURN_ACCEPT_DIFFERENCE;
        }

        @Override
        public void skippedComparison(Node arg0, Node arg1) {
        }
    });
    assertXMLIdentical(xmlDiff, true);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) HashMap(java.util.HashMap) Diff(org.custommonkey.xmlunit.Diff) Node(org.w3c.dom.Node) Difference(org.custommonkey.xmlunit.Difference) DifferenceListener(org.custommonkey.xmlunit.DifferenceListener) ElementNameQualifier(org.custommonkey.xmlunit.ElementNameQualifier) Test(org.junit.Test)

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