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());
}
}
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());
}
}
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);
}
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());
}
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);
}
Aggregations