public void testSecurityRoles() throws Exception
{
System.out.println("Testing securityRoles");
File warFile = new File("./test/testdata/deploy/webapp");
PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" );
MutablePortletApplication app = paWar.createPortletApp();
assertNotNull("App is null", app);
MutableWebApplication webApp = paWar.createWebApp();
assertNotNull("WebApp is null", webApp);
app.setWebApplicationDefinition(webApp);
PortletDefinition portlet = app.getPortletDefinitionByName("TestPortlet");
assertNotNull("TestPortlet is null", portlet);
checkWebSecurityRoles(webApp);
checkPortletSecurityRoleRefs(portlet);
boolean validateFailed = false;
try
{
paWar.validate();
}
catch (PortletApplicationException e)
{
validateFailed = true;
}
assertTrue("Invalid PortletDescriptor validation result", validateFailed);
SecurityRoleImpl role = new SecurityRoleImpl();
role.setRoleName("users.manager");
webApp.addSecurityRole(role);
try
{
paWar.validate();
validateFailed = false;
}
catch (PortletApplicationException e)
{
}
assertEquals("Invalid PortletDescriptor validation result", false, validateFailed);
// persist the app
try
{
portletRegistry.registerPortletApplication(app);
}
catch (Exception e)
{
String msg = "Unable to register portlet application, " + app.getName()
+ ", through the portlet registry: " + e.toString();
throw new Exception(msg, e);
}
// clear cache
// read back in
app = portletRegistry.getPortletApplication("unit-test");
validateFailed = true;
try
{
paWar.validate();
validateFailed = false;
}
catch (PortletApplicationException e)
{
}