use of org.custommonkey.xmlunit.DetailedDiff in project mule by mulesoft.
the class ModuleSchemaGeneratorTestCase method compareXML.
private void compareXML(String expected, String actual) throws Exception {
setNormalizeWhitespace(true);
setIgnoreWhitespace(true);
setIgnoreComments(true);
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 SunCmpConversionTest method convert.
private EntityMappings convert(final String ejbJarFileName, final String sunEjbJarFileName, final String sunCmpMappingsFileName, final String expectedFileName) throws Exception {
InputStream in = getClass().getClassLoader().getResourceAsStream(ejbJarFileName);
final EjbJar ejbJar = (EjbJar) JaxbJavaee.unmarshalJavaee(EjbJar.class, new ByteArrayInputStream(readContent(in).getBytes()));
// create and configure the module
final EjbModule ejbModule = new EjbModule(getClass().getClassLoader(), "TestModule", null, ejbJar, new OpenejbJar());
final InitEjbDeployments initEjbDeployments = new InitEjbDeployments();
initEjbDeployments.deploy(ejbModule);
final AppModule appModule = new AppModule(getClass().getClassLoader(), "TestModule");
appModule.getEjbModules().add(ejbModule);
// add the altDD
ejbModule.getAltDDs().put("sun-cmp-mappings.xml", getClass().getClassLoader().getResource(sunCmpMappingsFileName));
ejbModule.getAltDDs().put("sun-ejb-jar.xml", getClass().getClassLoader().getResource(sunEjbJarFileName));
// convert the cmp declarations into jpa entity declarations
final CmpJpaConversion cmpJpaConversion = new CmpJpaConversion();
cmpJpaConversion.deploy(appModule);
// EntityMappings entityMappings = cmpJpaConversion.generateEntityMappings(ejbModule);
// // load the sun-cmp-mappings.xml file
// String sunCmpMappingsXml = readContent(getClass().getClassLoader().getResourceAsStream(sunCmpMappingsFileName));
// SunCmpMappings sunCmpMappings = (SunCmpMappings) JaxbSun.unmarshal(SunCmpMappings.class, new ByteArrayInputStream(sunCmpMappingsXml.getBytes()));
// fill in the jpa entity declarations with database mappings from the sun-cmp-mappings.xml file
final SunConversion sunConversion = new SunConversion();
// sunCmpConversion.mergeEntityMappings(ejbModule, entityMappings);
sunConversion.deploy(appModule);
// compare the results to the expected results
if (expectedFileName != null) {
in = getClass().getClassLoader().getResourceAsStream(expectedFileName);
final String expected = readContent(in);
// Sun doen't really support generated primary keys, so we need to add them by hand here
final Set<String> generatedPks = new HashSet<>(Arrays.asList("BasicCmp2", "AOBasicCmp2", "EncCmp2", "Cmp2RmiIiop"));
final EntityMappings cmpMappings = appModule.getCmpMappings();
for (final Entity entity : cmpMappings.getEntity()) {
if (generatedPks.contains(entity.getName())) {
entity.getAttributes().getId().get(0).setGeneratedValue(new GeneratedValue(GenerationType.IDENTITY));
}
}
final String actual = toString(cmpMappings);
XMLUnit.setIgnoreWhitespace(true);
try {
final Diff myDiff = new DetailedDiff(new Diff(expected, actual));
assertTrue("Files are not similar " + myDiff, myDiff.similar());
} catch (final AssertionFailedError e) {
assertEquals(expected, actual);
}
}
return appModule.getCmpMappings();
}
use of org.custommonkey.xmlunit.DetailedDiff in project tomee by apache.
the class OpenejbJarTest method testAll.
public void testAll() throws Exception {
final JAXBContext ctx = JAXBContextFactory.newInstance(OpenejbJar.class);
final Unmarshaller unmarshaller = ctx.createUnmarshaller();
final InputStream in = this.getClass().getClassLoader().getResourceAsStream("openejb-jar.xml");
final String expected = readContent(in);
unmarshaller.setEventHandler(new TestValidationEventHandler());
final Object object = unmarshaller.unmarshal(new ByteArrayInputStream(expected.getBytes()));
assertTrue(object instanceof OpenejbJar);
final Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty("jaxb.formatted.output", true);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(object, baos);
final String actual = new String(baos.toByteArray());
XMLUnit.setIgnoreWhitespace(true);
try {
final Diff myDiff = new DetailedDiff(new Diff(expected, actual));
assertTrue("Files are not similar " + myDiff, myDiff.similar());
} catch (final AssertionFailedError e) {
e.printStackTrace();
assertEquals(expected, actual);
throw e;
}
}
use of org.custommonkey.xmlunit.DetailedDiff in project tomee by apache.
the class OpenejbJarTest method unmarshalAndMarshal.
private <T> void unmarshalAndMarshal(final Class<T> type, final java.lang.String xmlFileName, final java.lang.String expectedFile) throws Exception {
final InputStream in = getInputStream(xmlFileName);
assertNotNull(in);
final Object object = JaxbOpenejbJar2.unmarshal(type, in);
final String actual = JaxbOpenejbJar2.marshal(type, object);
final String expected;
if (xmlFileName.equals(expectedFile)) {
expected = readContent(getInputStream(xmlFileName));
} else {
expected = readContent(getInputStream(expectedFile));
}
XMLUnit.setIgnoreWhitespace(true);
try {
final Diff myDiff = new DetailedDiff(new Diff(expected, actual));
assertTrue("Files are not similar " + myDiff, myDiff.similar());
} catch (final AssertionFailedError e) {
e.printStackTrace();
assertEquals(expected, actual);
throw e;
}
}
use of org.custommonkey.xmlunit.DetailedDiff in project tomee by apache.
the class JaxbWlsTest method marshallAndUnmarshall.
public void marshallAndUnmarshall(final String xmlFile) throws Exception {
final InputStream in = this.getClass().getClassLoader().getResourceAsStream(xmlFile);
final String expected = readContent(in);
final Object object = JaxbWls.unmarshal(WeblogicEjbJar.class, new ByteArrayInputStream(expected.getBytes()));
final JAXBElement element = (JAXBElement) object;
assertTrue(element.getValue() instanceof WeblogicEjbJar);
final String actual = JaxbWls.marshal(WeblogicEjbJar.class, element);
XMLUnit.setIgnoreWhitespace(true);
try {
final Diff myDiff = new DetailedDiff(new Diff(expected, actual));
assertTrue("Files are not similar " + myDiff, myDiff.similar());
} catch (final AssertionFailedError e) {
assertEquals(expected, actual);
throw e;
}
}
Aggregations