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