Search in sources :

Example 1 with DifferenceListener

use of org.custommonkey.xmlunit.DifferenceListener in project jbpm by kiegroup.

the class BPMN2XMLTest method testXML.

public void testXML() throws IOException, SAXException {
    SemanticModules modules = new SemanticModules();
    modules.addSemanticModule(new BPMNSemanticModule());
    modules.addSemanticModule(new BPMNDISemanticModule());
    XmlProcessReader processReader = new XmlProcessReader(modules, getClass().getClassLoader());
    for (String processName : processes) {
        String original = slurp(BPMN2XMLTest.class.getResourceAsStream("/" + processName));
        List<Process> processes = processReader.read(BPMN2XMLTest.class.getResourceAsStream("/" + processName));
        assertNotNull(processes);
        assertEquals(1, processes.size());
        RuleFlowProcess p = (RuleFlowProcess) processes.get(0);
        String result = XmlBPMNProcessDumper.INSTANCE.dump(p, XmlBPMNProcessDumper.META_DATA_USING_DI);
        // Compare original with result using XMLUnit
        Diff diff = new Diff(original, result);
        // Ignore the sequence of nodes (or children nodes) when looking at these nodes
        final HashSet<String> sequenceDoesNotMatter = new HashSet<String>();
        sequenceDoesNotMatter.add("startEvent");
        sequenceDoesNotMatter.add("scriptTask");
        sequenceDoesNotMatter.add("endEvent");
        sequenceDoesNotMatter.add("bpmndi:BPMNShape");
        diff.overrideDifferenceListener(new DifferenceListener() {

            public int differenceFound(Difference diff) {
                String nodeName = diff.getTestNodeDetail().getNode().getNodeName();
                if (sequenceDoesNotMatter.contains(nodeName) && diff.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID) {
                    return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
                }
                logger.info("! {}", diff.getTestNodeDetail().getNode().getNodeName());
                return RETURN_ACCEPT_DIFFERENCE;
            }

            public void skippedComparison(Node one, Node two) {
                logger.info("{} : {}", one.getLocalName(), two.getLocalName());
            }
        });
        // nodes should only be compared if their attributes are the same
        diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
        assertTrue("Original and generated output is not the same.", diff.identical());
    }
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Diff(org.custommonkey.xmlunit.Diff) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) Node(org.w3c.dom.Node) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Difference(org.custommonkey.xmlunit.Difference) SemanticModules(org.drools.core.xml.SemanticModules) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) ElementNameAndAttributeQualifier(org.custommonkey.xmlunit.ElementNameAndAttributeQualifier) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule) DifferenceListener(org.custommonkey.xmlunit.DifferenceListener) HashSet(java.util.HashSet)

Example 2 with DifferenceListener

use of org.custommonkey.xmlunit.DifferenceListener 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 3 with DifferenceListener

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

Example 4 with DifferenceListener

use of org.custommonkey.xmlunit.DifferenceListener 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 5 with DifferenceListener

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

the class CswFilterDelegateTest 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

Diff (org.custommonkey.xmlunit.Diff)7 Difference (org.custommonkey.xmlunit.Difference)7 DifferenceListener (org.custommonkey.xmlunit.DifferenceListener)7 Node (org.w3c.dom.Node)7 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)2 ElementNameQualifier (org.custommonkey.xmlunit.ElementNameQualifier)2 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 DetailedDiff (org.custommonkey.xmlunit.DetailedDiff)1 ElementNameAndAttributeQualifier (org.custommonkey.xmlunit.ElementNameAndAttributeQualifier)1 SemanticModules (org.drools.core.xml.SemanticModules)1