Search in sources :

Example 11 with DetailedDiff

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());
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Difference(org.custommonkey.xmlunit.Difference)

Example 12 with DetailedDiff

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();
}
Also used : Entity(org.apache.openejb.jee.jpa.Entity) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GeneratedValue(org.apache.openejb.jee.jpa.GeneratedValue) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityMappings(org.apache.openejb.jee.jpa.EntityMappings) AssertionFailedError(junit.framework.AssertionFailedError) EjbJar(org.apache.openejb.jee.EjbJar) HashSet(java.util.HashSet)

Example 13 with DetailedDiff

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;
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Unmarshaller(javax.xml.bind.Unmarshaller) AssertionFailedError(junit.framework.AssertionFailedError)

Example 14 with DetailedDiff

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;
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) String(java.lang.String) AssertionFailedError(junit.framework.AssertionFailedError)

Example 15 with DetailedDiff

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;
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) ByteArrayInputStream(java.io.ByteArrayInputStream) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBElement(javax.xml.bind.JAXBElement) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

DetailedDiff (org.custommonkey.xmlunit.DetailedDiff)39 Diff (org.custommonkey.xmlunit.Diff)16 Difference (org.custommonkey.xmlunit.Difference)16 Test (org.junit.Test)16 Document (org.w3c.dom.Document)7 File (java.io.File)6 List (java.util.List)6 IOException (java.io.IOException)5 StringWriter (java.io.StringWriter)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Element (org.w3c.dom.Element)5 BufferedInputStream (java.io.BufferedInputStream)4 BufferedReader (java.io.BufferedReader)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 AssertionFailedError (junit.framework.AssertionFailedError)4