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