dlestrat 2004/05/17 17:45:24
Modified: portal/src/test/org/apache/jetspeed/tools/pamanager
TestPortletDescriptorSecurityRoles.java
Log:
Added removal of the test portlet application to clean up after test is run.
Revision Changes Path
1.3 +49 -45
jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptorSecurityRoles.java
Index: TestPortletDescriptorSecurityRoles.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptorSecurityRoles.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestPortletDescriptorSecurityRoles.java 15 May 2004 02:10:19 -0000 1.2
+++ TestPortletDescriptorSecurityRoles.java 18 May 2004 00:45:24 -0000 1.3
@@ -47,8 +47,7 @@
*
* @version $Id$
*/
-public class TestPortletDescriptorSecurityRoles extends
- AbstractComponentAwareTestCase
+public class TestPortletDescriptorSecurityRoles extends
AbstractComponentAwareTestCase
{
private PortletRegistryComponent registry;
@@ -76,8 +75,7 @@
*/
public static void main(String args[])
{
- TestRunner.main(new String[]
- { TestPortletDescriptorSecurityRoles.class.getName()});
+ TestRunner.main(new String[] {
TestPortletDescriptorSecurityRoles.class.getName()});
}
public static final String LOG4J_CONFIG_FILE = "log4j.file";
@@ -99,18 +97,17 @@
try
{
p.load(new FileInputStream(log4jFile));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
e.printStackTrace();
}
PropertyConfigurator.configure(p);
- System.getProperties().setProperty(LogFactory.class.getName(),
- Log4jFactory.class.getName());
+ System.getProperties().setProperty(LogFactory.class.getName(),
Log4jFactory.class.getName());
container = (MutablePicoContainer) getContainer();
- registry = (PortletRegistryComponent) container
- .getComponentInstance(PortletRegistryComponent.class);
+ registry = (PortletRegistryComponent)
container.getComponentInstance(PortletRegistryComponent.class);
store = registry.getPersistenceStore();
}
@@ -122,31 +119,28 @@
*/
public static Test suite()
{
- ComponentAwareTestSuite suite = new ComponentAwareTestSuite(
- TestPortletDescriptorSecurityRoles.class);
- suite
-
.setScript("org/apache/jetspeed/tools/pamanager/containers/pa-container.groovy");
+ ComponentAwareTestSuite suite = new
ComponentAwareTestSuite(TestPortletDescriptorSecurityRoles.class);
+
suite.setScript("org/apache/jetspeed/tools/pamanager/containers/pa-container.groovy");
return suite;
}
public void testSecurityRoles() throws Exception
{
System.out.println("Testing securityRoles");
- MutablePortletApplication app = PortletDescriptorUtilities
- .loadPortletDescriptor(
- "./test/testdata/deploy/security-roles/portlet.xml",
- "unit-test");
+ MutablePortletApplication app =
+
PortletDescriptorUtilities.loadPortletDescriptor("./test/testdata/deploy/security-roles/portlet.xml",
"unit-test");
assertNotNull("App is null", app);
- MutableWebApplication webApp = (MutableWebApplication)
WebDescriptorUtilities
- .loadDescriptor(
- "./test/testdata/deploy/security-roles/web.xml", "/",
- Jetspeed.getDefaultLocale(), "unit-test");
+ MutableWebApplication webApp =
+ (MutableWebApplication) WebDescriptorUtilities.loadDescriptor(
+ "./test/testdata/deploy/security-roles/web.xml",
+ "/",
+ Jetspeed.getDefaultLocale(),
+ "unit-test");
assertNotNull("WebApp is null", webApp);
app.setWebApplicationDefinition(webApp);
- PortletDefinition portlet = app
- .getPortletDefinitionByName("TestPortlet");
+ PortletDefinition portlet = app.getPortletDefinitionByName("TestPortlet");
assertNotNull("TestPortlet is null", portlet);
checkWebSecurityRoles(webApp);
checkPortletSecurityRoleRefs(portlet);
@@ -154,12 +148,12 @@
try
{
PortletDescriptorUtilities.validate(app);
- } catch (PortletApplicationException e)
+ }
+ catch (PortletApplicationException e)
{
validateFailed = true;
}
- assertEquals("Invalid PortletDescriptor validation result", true,
- validateFailed);
+ assertEquals("Invalid PortletDescriptor validation result", true,
validateFailed);
SecurityRoleImpl role = new SecurityRoleImpl();
role.setRoleName("users.manager");
webApp.addSecurityRole(role);
@@ -167,11 +161,11 @@
{
PortletDescriptorUtilities.validate(app);
validateFailed = false;
- } catch (PortletApplicationException e)
+ }
+ catch (PortletApplicationException e)
{
}
- assertEquals("Invalid PortletDescriptor validation result", false,
- validateFailed);
+ assertEquals("Invalid PortletDescriptor validation result", false,
validateFailed);
// persist the app
try
@@ -179,11 +173,11 @@
store.getTransaction().begin();
registry.registerPortletApplication(app);
store.getTransaction().commit();
- } catch (Exception e)
+ }
+ catch (Exception e)
{
- String msg = "Unable to register portlet application, "
- + app.getName() + ", through the portlet registry: "
- + e.toString();
+ String msg =
+ "Unable to register portlet application, " + app.getName() + ",
through the portlet registry: " + e.toString();
store.getTransaction().rollback();
throw new Exception(msg, e);
}
@@ -197,19 +191,32 @@
{
PortletDescriptorUtilities.validate(app);
validateFailed = false;
- } catch (PortletApplicationException e)
+ }
+ catch (PortletApplicationException e)
+ {
+ }
+ assertEquals("Invalid loaded PortletDescriptor validation result", false,
validateFailed);
+
+ // remove the app
+ try
{
+ store.getTransaction().begin();
+ registry.removeApplication(app);
+ store.getTransaction().commit();
+ }
+ catch (Exception e)
+ {
+ String msg =
+ "Unable to remove portlet application, " + app.getName() + ",
through the portlet registry: " + e.toString();
+ throw new Exception(msg, e);
}
- assertEquals("Invalid loaded PortletDescriptor validation result",
- false, validateFailed);
}
private void checkWebSecurityRoles(MutableWebApplication webApp)
{
SecurityRoleSet roles = webApp.getSecurityRoles();
- assertEquals("Invalid number of security role definitions found", 1,
- roles.size());
+ assertEquals("Invalid number of security role definitions found", 1,
roles.size());
SecurityRole role = roles.get("users.admin");
assertNotNull("Role users.admin undefined", role);
}
@@ -217,15 +224,12 @@
private void checkPortletSecurityRoleRefs(PortletDefinition portlet)
{
SecurityRoleRefSet roleRefs = portlet.getInitSecurityRoleRefSet();
- assertEquals("Invalid number of security role references found", 2,
- roleRefs.size());
+ assertEquals("Invalid number of security role references found", 2,
roleRefs.size());
SecurityRoleRef roleRef = roleRefs.get("admin");
assertNotNull("Security Role Ref admin undefined", roleRef);
- assertEquals("security Role link expected", "users.admin", roleRef
- .getRoleLink());
+ assertEquals("security Role link expected", "users.admin",
roleRef.getRoleLink());
roleRef = roleRefs.get("users.manager");
assertNotNull("Security Role Ref users.manager undefined", roleRef);
- assertNull("Undefined security Role link for users.managers expected",
- roleRef.getRoleLink());
+ assertNull("Undefined security Role link for users.managers expected",
roleRef.getRoleLink());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]