[jboss-cvs] JBossAS SVN: r72875 - in projects/security/security-jboss-sx/trunk/identity/src: tests/org/jboss/test/identity/impl and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 29 17:26:53 EDT 2008
Author: mmoyses
Date: 2008-04-29 17:26:53 -0400 (Tue, 29 Apr 2008)
New Revision: 72875
Modified:
projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/IdentityFactory.java
projects/security/security-jboss-sx/trunk/identity/src/tests/org/jboss/test/identity/impl/FilePersistenceStrategyUnitTestCase.java
Log:
Test cases for persistence of Identities with roles
Modified: projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/IdentityFactory.java
===================================================================
--- projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/IdentityFactory.java 2008-04-29 20:58:10 UTC (rev 72874)
+++ projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/IdentityFactory.java 2008-04-29 21:26:53 UTC (rev 72875)
@@ -26,6 +26,7 @@
import java.security.acl.Group;
import org.jboss.security.identity.Identity;
+import org.jboss.security.identity.Role;
//$Id$
@@ -64,6 +65,26 @@
return (Identity) loadClass(identityClass, name);
}
+ public static Identity createIdentityWithRole(String name, String roleName) throws Exception
+ {
+ return (Identity) loadClass(IDENTITY_CLASS, name, roleName);
+ }
+
+ public static Identity createIdentityWithRole(String identityClass, String name, String roleName) throws Exception
+ {
+ return (Identity) loadClass(identityClass, name, roleName);
+ }
+
+ public static Identity createIdentityWithRole(String name, Role role) throws Exception
+ {
+ return (Identity) loadClass(IDENTITY_CLASS, name, role);
+ }
+
+ public static Identity createIdentityWithRole(String identityClass, String name, Role role) throws Exception
+ {
+ return (Identity) loadClass(identityClass, name, role);
+ }
+
private static Object loadClass(String className, String ctorArg) throws Exception
{
Class<?> clazz = SecurityActions.getClass(className);
@@ -73,4 +94,22 @@
{ctorArg});
}
+ private static Object loadClass(String className, String ctorArg1, String ctorArg2) throws Exception
+ {
+ Class<?> clazz = SecurityActions.getClass(className);
+ Constructor<?> ctr = clazz.getConstructor(new Class[]
+ {String.class, String.class});
+ return ctr.newInstance(new Object[]
+ {ctorArg1, ctorArg2});
+ }
+
+ private static Object loadClass(String className, String ctorArg1, Role ctorArg2) throws Exception
+ {
+ Class<?> clazz = SecurityActions.getClass(className);
+ Constructor<?> ctr = clazz.getConstructor(new Class[]
+ {String.class, Role.class});
+ return ctr.newInstance(new Object[]
+ {ctorArg1, ctorArg2});
+ }
+
}
\ No newline at end of file
Modified: projects/security/security-jboss-sx/trunk/identity/src/tests/org/jboss/test/identity/impl/FilePersistenceStrategyUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/identity/src/tests/org/jboss/test/identity/impl/FilePersistenceStrategyUnitTestCase.java 2008-04-29 20:58:10 UTC (rev 72874)
+++ projects/security/security-jboss-sx/trunk/identity/src/tests/org/jboss/test/identity/impl/FilePersistenceStrategyUnitTestCase.java 2008-04-29 21:26:53 UTC (rev 72875)
@@ -26,8 +26,10 @@
import junit.framework.TestCase;
import org.jboss.security.identity.Identity;
+import org.jboss.security.identity.Role;
import org.jboss.security.identity.plugins.FilePersistenceStrategy;
import org.jboss.security.identity.plugins.IdentityFactory;
+import org.jboss.security.identity.plugins.SimpleRole;
/**
* A PersistenceStrategyUnitTestCase.
@@ -63,6 +65,36 @@
assertEquals("Objects are different", identity, restored);
}
+ public void testReadIdentityWithRole() throws Exception
+ {
+ Identity identity = IdentityFactory.createIdentityWithRole("test", "testRole");
+ FilePersistenceStrategy fps = new FilePersistenceStrategy(fileName);
+ assertFalse("File already exists", file.exists());
+ fps.persistIdentity(identity);
+ assertTrue("File was not created", file.exists());
+
+ Identity restored = fps.retrieveIdentity("test");
+ assertEquals("Objects are different", identity, restored);
+ assertEquals("Role names are different", identity.getRole().getRoleName(), restored.getRole().getRoleName());
+ }
+
+ public void testReadIdentityWithRoleAndParent() throws Exception
+ {
+ Role parent = new SimpleRole("parent");
+ Role role = new SimpleRole("testRole", parent);
+ Identity identity = IdentityFactory.createIdentityWithRole("test", role);
+ FilePersistenceStrategy fps = new FilePersistenceStrategy(fileName);
+ assertFalse("File already exists", file.exists());
+ fps.persistIdentity(identity);
+ assertTrue("File was not created", file.exists());
+
+ Identity restored = fps.retrieveIdentity("test");
+ assertEquals("Objects are different", identity, restored);
+ assertEquals("Role names are different", identity.getRole().getRoleName(), restored.getRole().getRoleName());
+ assertEquals("Parent role names are different", identity.getRole().getParent().getRoleName(), restored.getRole()
+ .getParent().getRoleName());
+ }
+
@Override
protected void tearDown() throws Exception
{
More information about the jboss-cvs-commits
mailing list