webAppsDir, portletRegistry, entityAccess, windowAccess, portletCache, manager), portletRegistry, portletFactory );
ArrayList eventListeners = new ArrayList(2);
eventListeners.add(ddel);
eventListeners.add(dpal);
// Use a -1 delay to disable auto scan
StandardDeploymentManager autoDeployment = new StandardDeploymentManager(deploySrc.getAbsolutePath(), -1, eventListeners );
autoDeployment.start();
autoDeployment.fireDeploymentEvent();
File decoratorVm = new File(deployRootFile.getAbsolutePath() + File.separator + "generic" + File.separator + "html" + File.separator
+ "portletstd" + File.separator + "decorator.vm");
File demoAppDeployed = new File(webAppsDirFile, TEST_PORTLET_APP_NAME);
File demoApp = demoAppDeployed;
File securityApp = new File(webAppsDirFile, "TestSecurityRoles");
assertTrue(decoratorVm.getCanonicalPath() + " was not created!", decoratorVm.exists());
verifyDemoAppCreated(TEST_PORTLET_APP_NAME, demoApp);
verifyDemoAppCreated("TestSecurityRoles", securityApp);
MutablePortletApplication jetspeedApp = portletRegistry.getPortletApplicationByIdentifier("jetspeed");
assertNotNull("jetspeed was not registered into the portlet registery.", jetspeedApp);
assertFalse("local app, jetspeed, got deployed when it should have only been registered.", new File(webAppsDir
+ "/jetspeed").exists());
//make sure we can load registered app's classes
Iterator portletDefItr = jetspeedApp.getPortletDefinitions().iterator();
while (portletDefItr.hasNext())
{
PortletDefinition def = (PortletDefinition) portletDefItr.next();
try
{
Portlet portlet = JetspeedPortletFactoryProxy.loadPortletClass(def.getClassName());
assertNotNull("Could not load portlet class: "+def.getClassName(), portlet);
}
catch (Exception e)
{
assertNull("Unable to load registered portlet class, " + def.getClassName(), e);
}
}
// test undeploy
File demoWar = new File(deploySrc, "demo.war");
demoWar.delete();
autoDeployment.fireUndeploymentEvent();
verifyDemoAppDeleted(TEST_PORTLET_APP_NAME, demoApp);
// test deploy again
copyDeployables();
autoDeployment.fireDeploymentEvent();
verifyDemoAppCreated(TEST_PORTLET_APP_NAME, demoApp);
demoWar.delete();
autoDeployment.fireUndeploymentEvent();
verifyDemoAppDeleted(TEST_PORTLET_APP_NAME, demoApp);
// test redeploy
// So, first deploy the typical demo.war we have been using before.
copyDeployables();
autoDeployment.fireDeploymentEvent();
verifyDemoAppCreated(TEST_PORTLET_APP_NAME, demoApp);
DirectoryHelper demoAppDeployedDir = new DirectoryHelper(demoAppDeployed);
long beforeSize = new File(demoAppDeployedDir.getRootDirectory(), "WEB-INF/portlet.xml").length();
// Trigger re-deployment using a demo.war that has a slightly larger portlet.xml
// then the one we just deployed. We will use size comparisons as or litmus test.
File redeployDemoWar = new File("./test/deployment/redeploy/demo.war");
FileChannel srcDemoWarChannel = new FileInputStream(redeployDemoWar).getChannel();
FileChannel dstDemoWarChannel = new FileOutputStream(demoWar).getChannel();
dstDemoWarChannel.transferFrom(srcDemoWarChannel, 0, srcDemoWarChannel.size());
srcDemoWarChannel.close();
dstDemoWarChannel.close();
// Make sure the demo.war that will trigger redeploy has a larger portlet.xml then the current one
JarHelper rdDemoWar = new JarHelper(demoWar, true);
assertTrue(new File(rdDemoWar.getRootDirectory(), "WEB-INF/portlet.xml").length() > beforeSize);
// Need to slow it down so the timestamp check works
Thread.sleep(500);
demoWar.setLastModified(System.currentTimeMillis());
autoDeployment.fireRedeploymentEvent();
long afterSize = new File(demoAppDeployedDir.getRootDirectory(), "WEB-INF/portlet.xml").length();
// The portlet.xml in re-deploy has an additional portlet entry in portlet.xml, so it should be bigger
assertTrue(afterSize > beforeSize);
autoDeployment.stop();
}