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;
int earEntryCount = 0;
int warEntryCount = 0;
JarInputStream earIn = new JarInputStream( new FileInputStream( earFile ) );
JarEntry earEntry;
JarEntry warEntry;
while ( ( earEntry = earIn.getNextJarEntry() ) != null ) {
earEntryCount++;
if ( earEntry.getName().endsWith( ".war" ) ) {
warEntryCount++;
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 ) ) );
}
}
}
}
assertTrue( "EAR archive did not contain any entries", earEntryCount > 0 );
assertTrue( "WAR archive did not contain any entries", warEntryCount > 0 );
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 );
PortletDefinition portlet = (PortletDefinition) portletApp.getPortlets().iterator().next();
assertEquals( "Unexpected test portlet name.", testPortletName, portlet.getPortletName() );
String servletClassName = webXmlRewriter.getServletClass( portlet.getPortletName() );
assertNotNull( "web.xml does not contain assembly for test portlet", servletClassName );
assertEquals( "web.xml does not contain correct dispatch servet", Assembler.DISPATCH_SERVLET_CLASS,