directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10378 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/role test/org/apache/rms/je/role
Date Wed, 28 Apr 2004 21:39:33 GMT
Author: akarasulu
Date: Wed Apr 28 14:39:31 2004
New Revision: 10378

Added:
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleFactoryTest.java
  (contents, props changed)
Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRole.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleFactory.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java
Log:
Commit changes ...

 o completed the JeRoleFactory
 o completed and added the unit tests for JeRoleFactory
 o made JeRole implement MutableRole - all mutable methods are not implemented



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRole.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRole.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRole.java	Wed Apr 28
14:39:31 2004
@@ -16,8 +16,14 @@
  */
 package org.apache.rms.je.role ;
 
+
 import org.apache.rms.DefaultRole ;
 import org.apache.rms.Application ;
+import org.apache.rms.RmsException ;
+import org.apache.rms.BitPermission ;
+import org.apache.rms.spi.MutableRole ;
+
+import org.apache.commons.lang.NotImplementedException ;
 
 
 /**
@@ -26,7 +32,7 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class JeRole extends DefaultRole
+public class JeRole extends DefaultRole implements MutableRole
 {
     /**
      * Creates a default Role instance.
@@ -44,5 +50,70 @@
     public byte[] getGrantBits()
     {
         return super.getGrantBits() ;
+    }
+
+
+    /**
+     * Grants a permission to this Role.
+     *
+     * @param permName the name of the permission being granted
+     * @throws org.apache.rms.RmsException if there is a problem effecting
+     * the backing store
+     */
+    public void grant( String permName ) throws RmsException
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+
+
+    /**
+     * Grants a permission to this Role.
+     *
+     * @param permission
+     * @throws org.apache.rms.RmsException if there is a problem effecting
+     * the backing store
+     */
+    public void grant( BitPermission permission ) throws RmsException
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+
+
+    /**
+     * Revokes a permission from this Role.
+     *
+     * @param permName the name of the permission being revoked
+     * @throws org.apache.rms.RmsException if there is a problem effecting
+     * the backing store
+     */
+    public void revoke( String permName ) throws RmsException
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+
+
+    /**
+     * Revokes a permission from this Role.
+     *
+     * @param permission
+     * @throws org.apache.rms.RmsException if there is a problem effecting
+     * the backing store
+     */
+    public void revoke( BitPermission permission ) throws RmsException
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+
+
+    /**
+     * Renames this Role.
+     *
+     * @param name the new name of this Role
+     * @throws org.apache.rms.RmsException if there is a problem effecting
+     * the backing store
+     */
+    public void rename( String name ) throws RmsException
+    {
+        throw new NotImplementedException( "STUB" ) ;
     }
 }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java	Wed Apr
28 14:39:31 2004
@@ -600,6 +600,28 @@
 
 
     /**
+     * Sets this Role data access object's monitor.
+     *
+     * @param monitor the event monitor callbacks are sent to
+     */
+    public void setMonitor( RoleDAOMonitor monitor )
+    {
+        this.monitor = monitor ;
+    }
+
+
+    /**
+     * Gets this Role data access object's monitor.
+     *
+     * @return the event monitor callbacks are sent to
+     */
+    public RoleDAOMonitor getMonitor()
+    {
+        return this.monitor ;
+    }
+
+
+    /**
      * Closes cursor based iterators that were created by this DAO.
      *
      * @param list the iterator to close.

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleFactory.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleFactory.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleFactory.java	Wed
Apr 28 14:39:31 2004
@@ -24,9 +24,8 @@
 import org.apache.rms.spi.RoleFactory ;
 import org.apache.rms.spi.MutableApplication ;
 
-import org.apache.commons.lang.NotImplementedException ;
-
 import java.util.Map ;
+import java.util.HashMap ;
 import java.util.Iterator ;
 
 
@@ -38,34 +37,49 @@
  */
 public class JeRoleFactory implements RoleFactory
 {
+    /** the data access object to the role database */
+    private final JeRoleDAO dao ;
+
+
+    /**
+     * Creates a Berkeley DB JE backed Role factory.
+     *
+     * @param dao the data access object to the role database
+     */
+    JeRoleFactory( JeRoleDAO dao )
+    {
+        this.dao = dao ;
+    }
+
+
     /**
      * Gets an Application's Role.
      *
-     * @param an_app     the Application the Role is defined for
-     * @param a_roleName the name of the Role
+     * @param application     the Application the Role is defined for
+     * @param roleName the name of the Role
      * @return the Role instance for application role specified or null if
      * such a Role does not exist for the application
      * @throws org.apache.rms.RmsException if there are problems accessing
      * the backing store
      */
-    public Role getRole( Application an_app, String a_roleName )
+    public Role getRole( Application application, String roleName )
             throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        return dao.get( application, roleName ) ;
     }
 
 
     /**
      * Iterates over the set of Role names for an Application.
      *
-     * @param an_appName the name of the Application
+     * @param appName the name of the Application
      * @return an Iterator of Strings
      * @throws org.apache.rms.RmsException if there are problems accessing
      * the backing store
      */
-    public Iterator getRoleNames( String an_appName ) throws RmsException
+    public Iterator getRoleNames( String appName ) throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        return dao.listNames( appName ) ;
     }
 
 
@@ -73,14 +87,22 @@
      * Gets the set of Role name Strings mapped to their respective Role
      * instance for an Application
      *
-     * @param an_app the Application the Role is defined for
+     * @param application the Application the Role is defined for
      * @return a Map of String keys of Role names mapped to values of Roles
      * @throws org.apache.rms.RmsException if there are problems accessing the
      * backing store
      */
-    public Map getRoles( Application an_app ) throws RmsException
+    public Map getRoles( Application application ) throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        Iterator list = dao.list( application.getName() ) ;
+        HashMap roles = new HashMap() ;
+        while( list.hasNext() )
+        {
+            Role role = ( Role ) list.next() ;
+            roles.put( role.getName(), role ) ;
+        }
+
+        return roles ;
     }
 
 
@@ -96,7 +118,8 @@
     public MutableRole create( MutableApplication app, String roleName )
             throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        dao.create( app, roleName ) ;
+        return new JeRole( roleName, null, app ) ;
     }
 
 
@@ -110,7 +133,7 @@
      */
     public void deleteRole( String appName, String roleName ) throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        dao.delete( appName, roleName ) ;
     }
 
 
@@ -126,7 +149,7 @@
     public void updateGrants( String appName, String roleName, byte[] grants )
             throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        dao.setGrants( appName, roleName, grants ) ;
     }
 
 
@@ -142,6 +165,6 @@
     public void renameRole( String appName, String oldName, String newName )
             throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        dao.rename( appName, oldName, newName ) ;
     }
 }

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java	(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java	Wed
Apr 28 14:39:31 2004
@@ -76,7 +76,7 @@
         JeSequenceFactory seqFactory = new JeSequenceFactory( seqDAO ) ;
         Sequence seq = seqFactory.create( "roleSeq" ) ;
         roleDAO = new JeRoleDAO( db, seq, binding ) ;
-        //roleDAO.setMonitor( new LoggingRoleDAOMonitor() ) ;
+        //dao.setMonitor( new LoggingRoleDAOMonitor() ) ;
     }
 
 

Added: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleFactoryTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleFactoryTest.java
Wed Apr 28 14:39:31 2004
@@ -0,0 +1,452 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permission and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.role ;
+
+
+import com.sleepycat.je.* ;
+
+import org.apache.rms.Role ;
+import org.apache.rms.RmsException ;
+import org.apache.rms.DefaultApplication ;
+import org.apache.rms.spi.ApplicationFactory ;
+import org.apache.rms.spi.MutableApplication ;
+
+import org.apache.rms.je.AbstractJeTest ;
+import org.apache.rms.je.sequence.Sequence ;
+import org.apache.rms.je.sequence.JeSequenceDao ;
+import org.apache.rms.je.application.JeApplication ;
+import org.apache.rms.je.sequence.JeSequenceFactory ;
+
+import org.apache.commons.lang.ArrayUtils ;
+import org.apache.commons.lang.NotImplementedException ;
+
+import java.util.Iterator ;
+import java.util.Map;
+
+
+/**
+ * Tests the JeRoleFactory class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeRoleFactoryTest extends AbstractJeTest
+{
+    JeRoleDAO dao ;
+    JeRoleFactory factory ;
+
+
+    protected void setUp() throws Exception
+    {
+        ApplicationFactory appFactory = new DummyFactory() ;
+        JeRoleBinding binding = new JeRoleBinding( appFactory ) ;
+
+        DatabaseConfig conf = new DatabaseConfig() ;
+        conf.setAllowCreate( true ) ;
+        setupDb( "seqDb", conf ) ;
+        super.setUp() ;
+
+        SecondaryConfig sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeRoleAppNameKeyCreator( binding ) ) ;
+        env.openSecondaryDatabase( null, JeRoleDAO.APP_SECDB, sconf, db ) ;
+
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeRoleNameKeyCreator( binding ) ) ;
+        env.openSecondaryDatabase( null, JeRoleDAO.ROLE_SECDB, sconf, db ) ;
+
+        JeSequenceDao seqDAO = new JeSequenceDao( getDb( "seqDb" ) ) ;
+        JeSequenceFactory seqFactory = new JeSequenceFactory( seqDAO ) ;
+        Sequence seq = seqFactory.create( "roleSeq" ) ;
+        dao = new JeRoleDAO( db, seq, binding ) ;
+        factory = new JeRoleFactory( dao ) ;
+        dao.setMonitor( new LoggingRoleDAOMonitor( binding ) ) ;
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        dao = null ;
+    }
+
+
+    public void testCreateAndGetRole() throws Exception
+    {
+        Role role = null ;
+        JeApplication application = new JeApplication( "app1" ) ;
+
+        try
+        {
+            factory.getRole( application, "roleA" ) ;
+            fail( "should never get here because of an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+
+        factory.create( application, "roleA" ) ;
+        factory.create( application, "roleB" ) ;
+        factory.create( application, "roleC" ) ;
+        factory.create( application, "roleD" ) ;
+
+        role = factory.getRole( application, "roleA" ) ;
+        assertEquals( application.getName(), role.getApplicationName() ) ;
+        assertEquals( "roleA", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = factory.getRole( application, "roleB" ) ;
+        assertEquals( application.getName(), role.getApplicationName() ) ;
+        assertEquals( "roleB", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = factory.getRole( application, "roleC" ) ;
+        assertEquals( application.getName(), role.getApplicationName() ) ;
+        assertEquals( "roleC", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = factory.getRole( application, "roleD" ) ;
+        assertEquals( application.getName(), role.getApplicationName() ) ;
+        assertEquals( "roleD", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+    }
+
+
+    public void testCreateAndDelete() throws Exception
+    {
+        Role role = null ;
+        JeApplication application = new JeApplication( "app1" ) ;
+
+        try
+        {
+            factory.getRole( application, "roleA" ) ;
+            fail( "should never get here because of an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+
+        factory.create( application, "roleA" ) ;
+        factory.create( application, "roleB" ) ;
+        factory.create( application, "roleC" ) ;
+        factory.create( application, "roleD" ) ;
+
+        role = factory.getRole( application, "roleA" ) ;
+        assertEquals( application.getName(), role.getApplicationName() ) ;
+        assertEquals( "roleA", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = factory.getRole( application, "roleB" ) ;
+        assertEquals( application.getName(), role.getApplicationName() ) ;
+        assertEquals( "roleB", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = factory.getRole( application, "roleC" ) ;
+        assertEquals( application.getName(), role.getApplicationName() ) ;
+        assertEquals( "roleC", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = factory.getRole( application, "roleD" ) ;
+        assertEquals( application.getName(), role.getApplicationName() ) ;
+        assertEquals( "roleD", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        factory.deleteRole( application.getName(), "roleA" ); ;
+        factory.deleteRole( application.getName(), "roleB" ) ;
+        factory.deleteRole( application.getName(), "roleC" ) ;
+        factory.deleteRole( application.getName(), "roleD" ) ;
+
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleB" ) ) ;
+        assertFalse( dao.has( "app1", "roleC" ) ) ;
+        assertFalse( dao.has( "app1", "roleD" ) ) ;
+
+        try
+        {
+            factory.deleteRole( application.getName(), "roleA" ); ;
+            fail( "should never get here because of an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+    }
+
+
+    public void testCreateAndRename() throws Exception
+    {
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleB" ) ) ;
+        assertFalse( dao.has( "app1", "roleC" ) ) ;
+        assertFalse( dao.has( "app1", "roleD" ) ) ;
+
+        JeApplication application = new JeApplication( "app1" ) ;
+        factory.create( application, "roleA" ) ;
+        factory.create( application, "roleB" ) ;
+        factory.create( application, "roleC" ) ;
+        factory.create( application, "roleD" ) ;
+
+        assertTrue( dao.has( "app1", "roleA" ) ) ;
+        assertTrue( dao.has( "app1", "roleB" ) ) ;
+        assertTrue( dao.has( "app1", "roleC" ) ) ;
+        assertTrue( dao.has( "app1", "roleD" ) ) ;
+
+        factory.renameRole( application.getName(), "roleA", "roleW" ); ;
+        factory.renameRole( application.getName(), "roleB", "roleX" ); ;
+        factory.renameRole( application.getName(), "roleC", "roleY" ); ;
+        factory.renameRole( application.getName(), "roleD", "roleZ" ); ;
+
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleB" ) ) ;
+        assertFalse( dao.has( "app1", "roleC" ) ) ;
+        assertFalse( dao.has( "app1", "roleD" ) ) ;
+
+        assertTrue( dao.has( "app1", "roleW" ) ) ;
+        assertTrue( dao.has( "app1", "roleX" ) ) ;
+        assertTrue( dao.has( "app1", "roleY" ) ) ;
+        assertTrue( dao.has( "app1", "roleZ" ) ) ;
+
+        try
+        {
+            factory.renameRole( application.getName(), "roleA", "roleW" ); ;
+            fail( "should never get here because of an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+    }
+
+
+    public void testCreateAndUpdateGrants() throws Exception
+    {
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleB" ) ) ;
+        assertFalse( dao.has( "app1", "roleC" ) ) ;
+        assertFalse( dao.has( "app1", "roleD" ) ) ;
+
+        JeApplication application = new JeApplication( "app1" ) ;
+        factory.create( application, "roleA" ) ;
+        factory.create( application, "roleB" ) ;
+        factory.create( application, "roleC" ) ;
+        factory.create( application, "roleD" ) ;
+
+        assertTrue( dao.has( "app1", "roleA" ) ) ;
+        assertTrue( dao.has( "app1", "roleB" ) ) ;
+        assertTrue( dao.has( "app1", "roleC" ) ) ;
+        assertTrue( dao.has( "app1", "roleD" ) ) ;
+
+        byte[] grants = null ;
+        grants = dao.getGrants( "app1", "roleA" ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+
+        grants = dao.getGrants( "app1", "roleB" ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+
+        grants = dao.getGrants( "app1", "roleC" ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+
+        grants = dao.getGrants( "app1", "roleD" ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+
+        byte[] newGrants = new byte[2] ;
+        newGrants[0] = 123 ;
+        newGrants[1] = 45 ;
+
+        factory.updateGrants( "app1", "roleA", newGrants ); ;
+        grants = dao.getGrants( "app1", "roleA" ) ;
+        assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+        assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
+
+        factory.updateGrants( "app1", "roleB", newGrants ) ;
+        grants = dao.getGrants( "app1", "roleB" ) ;
+        assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+        assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
+
+        factory.updateGrants( "app1", "roleC", newGrants ) ;
+        grants = dao.getGrants( "app1", "roleC" ) ;
+        assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+        assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
+
+        factory.updateGrants( "app1", "roleD", newGrants ) ;
+        grants = dao.getGrants( "app1", "roleD" ) ;
+        assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+        assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
+    }
+
+
+    public void testCreateAndListRoles() throws Exception
+    {
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleB" ) ) ;
+        assertFalse( dao.has( "app1", "roleC" ) ) ;
+        assertFalse( dao.has( "app1", "roleD" ) ) ;
+
+        JeApplication application = new JeApplication( "app1" ) ;
+        factory.create( application, "roleA" ) ;
+        factory.create( application, "roleB" ) ;
+        factory.create( application, "roleC" ) ;
+        factory.create( application, "roleD" ) ;
+
+        application = new JeApplication( "app2" ) ;
+        factory.create( application, "roleA" ) ;
+        factory.create( application, "roleB" ) ;
+        factory.create( application, "roleY" ) ;
+        factory.create( application, "roleZ" ) ;
+
+        assertTrue( dao.has( "app1", "roleA" ) ) ;
+        assertTrue( dao.has( "app1", "roleB" ) ) ;
+        assertTrue( dao.has( "app1", "roleC" ) ) ;
+        assertTrue( dao.has( "app1", "roleD" ) ) ;
+
+        assertTrue( dao.has( "app2", "roleA" ) ) ;
+        assertTrue( dao.has( "app2", "roleB" ) ) ;
+        assertTrue( dao.has( "app2", "roleY" ) ) ;
+        assertTrue( dao.has( "app2", "roleZ" ) ) ;
+
+        Map roles = null ;
+        JeRole role = null ;
+        roles = factory.getRoles( application ) ;
+
+        role = ( JeRole ) roles.get( "roleA" ) ;
+        assertNotNull( role ) ;
+        assertEquals( "app2", role.getApplicationName() ) ;
+        assertEquals( "roleA", role.getName() ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                role.getGrantBits() ) ) ;
+
+        role = ( JeRole ) roles.get( "roleB" ) ;
+        assertNotNull( role ) ;
+        assertEquals( "app2", role.getApplicationName() ) ;
+        assertEquals( "roleB", role.getName() ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                role.getGrantBits() ) ) ;
+
+        role = ( JeRole ) roles.get( "roleY" ) ;
+        assertNotNull( role ) ;
+        assertEquals( "app2", role.getApplicationName() ) ;
+        assertEquals( "roleY", role.getName() ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                role.getGrantBits() ) ) ;
+
+        role = ( JeRole ) roles.get( "roleZ" ) ;
+        assertNotNull( role ) ;
+        assertEquals( "app2", role.getApplicationName() ) ;
+        assertEquals( "roleZ", role.getName() ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                role.getGrantBits() ) ) ;
+
+        role = ( JeRole ) roles.get( "roleC" ) ;
+        assertNull( role ) ;
+        assertEquals( 4, roles.size() ) ;
+    }
+
+
+    public void testCreateAndGetRoleNames() throws Exception
+    {
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleB" ) ) ;
+        assertFalse( dao.has( "app1", "roleC" ) ) ;
+        assertFalse( dao.has( "app1", "roleD" ) ) ;
+
+        JeApplication application1 = new JeApplication( "app1" ) ;
+        factory.create( application1, "roleA" ) ;
+        factory.create( application1, "roleB" ) ;
+        factory.create( application1, "roleC" ) ;
+        factory.create( application1, "roleD" ) ;
+
+        JeApplication application2 = new JeApplication( "app2" ) ;
+        factory.create( application2, "roleA" ) ;
+        factory.create( application2, "roleB" ) ;
+        factory.create( application2, "roleY" ) ;
+        factory.create( application2, "roleZ" ) ;
+
+        assertTrue( dao.has( "app1", "roleA" ) ) ;
+        assertTrue( dao.has( "app1", "roleB" ) ) ;
+        assertTrue( dao.has( "app1", "roleC" ) ) ;
+        assertTrue( dao.has( "app1", "roleD" ) ) ;
+
+        assertTrue( dao.has( "app2", "roleA" ) ) ;
+        assertTrue( dao.has( "app2", "roleB" ) ) ;
+        assertTrue( dao.has( "app2", "roleY" ) ) ;
+        assertTrue( dao.has( "app2", "roleZ" ) ) ;
+
+        Iterator list = null ;
+        String roleName = null ;
+
+        list = factory.getRoleNames( "app1" ) ;
+
+        roleName = ( String ) list.next() ;
+        assertNotNull( roleName ) ;
+        assertEquals( "roleA", roleName ) ;
+
+        roleName = ( String ) list.next() ;
+        assertNotNull( roleName ) ;
+        assertEquals( "roleB", roleName ) ;
+
+        roleName = ( String ) list.next() ;
+        assertNotNull( roleName ) ;
+        assertEquals( "roleC", roleName ) ;
+
+        roleName = ( String ) list.next() ;
+        assertNotNull( roleName ) ;
+        assertEquals( "roleD", roleName ) ;
+
+        assertFalse( list.hasNext() ) ;
+    }
+
+
+    class DummyFactory implements ApplicationFactory
+    {
+        public MutableApplication getApplication( String appName )
+                throws RmsException
+        {
+            return new JeApplication( appName ) ;
+        }
+
+        public Iterator getApplicationNames() throws RmsException
+        {
+            throw new NotImplementedException( "STUB" ) ;
+        }
+
+        public MutableApplication createApplication( String appName )
+                throws RmsException
+        {
+            throw new NotImplementedException( "STUB" ) ;
+        }
+
+        public void deleteApplication( String appName ) throws RmsException
+        {
+            throw new NotImplementedException( "STUB" ) ;
+        }
+
+        public void renameApplication( String oldName, String newName )
+                throws RmsException
+        {
+            throw new NotImplementedException( "STUB" ) ;
+        }
+    }
+}
\ No newline at end of file

Mime
View raw message