}
public void testInfusingWebXML() throws Exception
{
File warFile = new File("./test/testdata/deploy/webapp");
PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" );
SAXBuilder builder = new SAXBuilder(false);
// Use the local dtd instead of remote dtd. This
// allows to deploy the application offline
builder.setEntityResolver(new EntityResolver()
{
public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
throws SAXException, java.io.IOException
{
if (systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd"))
{
return new InputSource(PortletApplicationWar.class.getResourceAsStream("web-app_2_3.dtd"));
}
else
return null;
}
});
FileReader srcReader = new FileReader("./test/testdata/deploy/webapp/WEB-INF/web.xml");
FileReader targetReader = null;
Document doc = builder.build(srcReader);
Element root = doc.getRootElement();
try
{
Object jetspeedServlet = XPath.selectSingleNode(root, PortletApplicationWar.JETSPEED_SERVLET_XPATH);
Object jetspeedServletMapping = XPath.selectSingleNode(root, PortletApplicationWar.JETSPEED_SERVLET_MAPPING_XPATH);
assertNull(jetspeedServlet);
assertNull(jetspeedServletMapping);
PortletApplicationWar targetWar = paWar.copyWar("./target/webapp");
targetWar.processWebXML();
targetReader = new FileReader("./target/webapp/WEB-INF/web.xml");
Document targetDoc = builder.build(targetReader);
jetspeedServlet = XPath.selectSingleNode(targetDoc, PortletApplicationWar.JETSPEED_SERVLET_XPATH);
jetspeedServletMapping = XPath.selectSingleNode(targetDoc, PortletApplicationWar.JETSPEED_SERVLET_MAPPING_XPATH);
assertNotNull(jetspeedServlet);
assertNotNull(jetspeedServletMapping);
}
finally
{
srcReader.close();
paWar.close();
if (targetReader != null)
{
targetReader.close();
}
File warFile2 = new File("./target/webapp");
if (warFile2.exists())
{
DirectoryHelper dirHelper = new DirectoryHelper(warFile2);
dirHelper.remove();
dirHelper.close();
}
}
}