Search in sources :

Example 1 with ResourceEntityResolver

use of org.apache.maven.plugins.ear.util.ResourceEntityResolver in project maven-plugins by apache.

the class AbstractEarPluginIT method assertDeploymentDescriptors.

// Generated application.xml stuff
/**
 * Asserts that the deployment descriptors have been generated successfully.
 * <p/>
 * This test assumes that deployment descriptors are located in the <tt>expected-META-INF</tt> directory of the
 * project. Note that the <tt>MANIFEST.mf</tt> file is ignored and is not tested.
 *
 * @param baseDir the directory of the tested project
 * @param projectName the name of the project
 */
protected void assertDeploymentDescriptors(final File baseDir, final String projectName) throws IOException {
    final File earDirectory = getEarDirectory(baseDir, projectName);
    final File[] actualDeploymentDescriptors = getDeploymentDescriptors(new File(earDirectory, "META-INF"));
    final File[] expectedDeploymentDescriptors = getDeploymentDescriptors(new File(baseDir, "expected-META-INF"));
    if (expectedDeploymentDescriptors == null) {
        assertNull("No deployment descriptor was expected", actualDeploymentDescriptors);
    } else {
        assertNotNull("Missing deployment descriptor", actualDeploymentDescriptors);
        // Make sure we have the same number of files
        assertEquals("Number of Deployment descriptor(s) mismatch", expectedDeploymentDescriptors.length, actualDeploymentDescriptors.length);
        // Sort the files so that we have the same behavior here
        Arrays.sort(expectedDeploymentDescriptors);
        Arrays.sort(actualDeploymentDescriptors);
        for (int i = 0; i < expectedDeploymentDescriptors.length; i++) {
            File expectedDeploymentDescriptor = expectedDeploymentDescriptors[i];
            File actualDeploymentDescriptor = actualDeploymentDescriptors[i];
            assertEquals("File name mismatch", expectedDeploymentDescriptor.getName(), actualDeploymentDescriptor.getName());
            try {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setValidating(true);
                DocumentBuilder docBuilder = dbf.newDocumentBuilder();
                docBuilder.setEntityResolver(new ResourceEntityResolver());
                docBuilder.setErrorHandler(new DefaultHandler());
                final Diff myDiff = new Diff(docBuilder.parse(expectedDeploymentDescriptor), docBuilder.parse(actualDeploymentDescriptor));
                XMLAssert.assertXMLEqual("Wrong deployment descriptor generated for[" + expectedDeploymentDescriptor.getName() + "]", myDiff, true);
            } catch (Exception e) {
                e.printStackTrace();
                fail("Could not assert deployment descriptor " + e.getMessage());
            }
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Diff(org.custommonkey.xmlunit.Diff) ResourceEntityResolver(org.apache.maven.plugins.ear.util.ResourceEntityResolver) File(java.io.File) VerificationException(org.apache.maven.it.VerificationException) IOException(java.io.IOException) DefaultHandler(org.xml.sax.helpers.DefaultHandler)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 VerificationException (org.apache.maven.it.VerificationException)1 ResourceEntityResolver (org.apache.maven.plugins.ear.util.ResourceEntityResolver)1 Diff (org.custommonkey.xmlunit.Diff)1 DefaultHandler (org.xml.sax.helpers.DefaultHandler)1