use of org.custommonkey.xmlunit.DetailedDiff in project mule by mulesoft.
the class ExtensionsTestUtils method compareXML.
/**
* Receives to {@link String} representation of two XML files and verify that they are semantically equivalent
*
* @param expected the reference content
* @param actual the actual content
* @throws Exception if comparison fails
*/
public static void compareXML(String expected, String actual) throws Exception {
XMLUnit.setNormalizeWhitespace(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(false);
Diff diff = XMLUnit.compareXML(expected, actual);
if (!(diff.similar() && diff.identical())) {
System.out.println(actual);
DetailedDiff detDiff = new DetailedDiff(diff);
@SuppressWarnings("rawtypes") List differences = detDiff.getAllDifferences();
StringBuilder diffLines = new StringBuilder();
for (Object object : differences) {
Difference difference = (Difference) object;
diffLines.append(difference.toString() + '\n');
}
throw new IllegalArgumentException("Actual XML differs from expected: \n" + diffLines.toString());
}
}
use of org.custommonkey.xmlunit.DetailedDiff 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.DetailedDiff 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.DetailedDiff in project cayenne by apache.
the class DbImporterMojoTest method verifyResult.
private void verifyResult(File map, File mapFileCopy) {
try {
FileReader control = new FileReader(map.getAbsolutePath() + "-result");
FileReader test = new FileReader(mapFileCopy);
Diff prototype = new Diff(control, test);
prototype.overrideElementQualifier(new ElementNameAndAttributeQualifier());
DetailedDiff diff = new DetailedDiff(prototype);
if (!diff.similar()) {
fail(diff.toString());
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations