protected void validateEarAssembly( File earFile ) throws Exception {
assertTrue( "EAR archive [" + earFile.getAbsolutePath() + "] cannot be found or cannot be read",
earFile.exists() && earFile.canRead() );
PortletAppDescriptorService portletSvc = new PortletAppDescriptorServiceImpl();
PortletApplicationDefinition portletApp = null;
PlutoWebXmlRewriter webXmlRewriter = null;
List<String> portletWarEntries = Arrays.asList( testWarEntryNames );
List<String> unassembledWarEntries = Arrays.asList( unassembledWarEntryName );
List<String> testPortlets = Arrays.asList( testPortletNames );
int earEntryCount = 0;
int totalWarEntryCount = 0;
int portletWarEntryCount = 0;
JarInputStream earIn = new JarInputStream( new FileInputStream( earFile ) );
JarEntry earEntry;
JarEntry warEntry;
while ( ( earEntry = earIn.getNextJarEntry() ) != null ) {
earEntryCount++;
if ( earEntry.getName().endsWith( ".war" ) ) {
totalWarEntryCount++;
JarInputStream warIn = new JarInputStream( earIn );
while ( ( warEntry = warIn.getNextJarEntry() ) != null ) {
if ( Assembler.PORTLET_XML.equals( warEntry.getName() ) ) {
portletApp = portletSvc.read( "test", "/test",
new ByteArrayInputStream( IOUtils.toByteArray( warIn ) ) );
}
if ( Assembler.SERVLET_XML.equals( warEntry.getName() ) ) {
webXmlRewriter = new PlutoWebXmlRewriter( new ByteArrayInputStream( IOUtils.toByteArray( warIn ) ) );
}
}
if ( portletWarEntries.contains( earEntry.getName() ) ) {
portletWarEntryCount++;
assertNotNull( "WAR archive did not contain a portlet.xml", portletApp );
assertNotNull( "WAR archive did not contain a servlet.xml", webXmlRewriter );
assertTrue( "WAR archive did not contain any servlets", webXmlRewriter.hasServlets() );
assertTrue( "WAR archive did not contain any servlet mappings", webXmlRewriter.hasServletMappings() );
assertTrue( "WAR archive did not contain any portlets", portletApp.getPortlets().size() > 0 );
for ( Iterator<? extends PortletDefinition> iter = portletApp.getPortlets().iterator(); iter.hasNext(); ) {
PortletDefinition portlet = iter.next();
if (! testPortlets.contains( portlet.getPortletName() ) ) {
fail( "Unexpected test portlet name encountered: [" + portlet.getPortletName() + "]" );
}
String servletClassName = webXmlRewriter.getServletClass( portlet.getPortletName() );