directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10360 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/role test/org/apache/rms/je/role
Date Wed, 28 Apr 2004 15:11:50 GMT
Author: akarasulu
Date: Wed Apr 28 08:11:48 2004
New Revision: 10360

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.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/RoleDAOMonitor.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java
Log:
Commit changes ...

 o completed JeRoleDAO get() operation
 o completed get() test case
 o added methods to monitor interface to support get() monitoring
 o added no-op monitor adapter implementations for new methods
 o found and fixed binding bug replacing use of != for ! x.equals(y)



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.java	Wed
Apr 28 08:11:48 2004
@@ -85,7 +85,7 @@
                     "The application for this thread has not been set before "
                     + " using this binding" ) ;
         }
-        else if ( application.getName() != appName )
+        else if ( ! appName.equals( application.getName() ) )
         {
             throw new IllegalStateException(
                     "Expected application by the name of " + appName

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 08:11:48 2004
@@ -20,6 +20,7 @@
 import org.apache.rms.Role ;
 import org.apache.rms.Application ;
 import org.apache.rms.RmsException ;
+import org.apache.rms.BitPermission;
 
 import org.apache.rms.je.JeUtils ;
 import org.apache.rms.je.JeRmsException ;
@@ -217,7 +218,38 @@
      */
     public Role get( Application application, String roleName ) throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        Role role = null ;
+        String appName = application.getName() ;
+        DatabaseEntry data = null ;
+
+        try
+        {
+            data = getRow( application.getName(), roleName, false ) ;
+        }
+        catch ( JeRmsException e )
+        {
+            if ( e.getStatus() == OperationStatus.NOTFOUND )
+            {
+                monitor.roleDoesNotExist( this, "get", appName, roleName ) ;
+            }
+
+            throw e ;
+        }
+
+        try
+        {
+            JeRoleBinding.setApplication( application ) ;
+            role = ( Role ) BINDING.entryToObject( data ) ;
+            JeRoleBinding.setApplication( null ) ;
+        }
+        catch ( IOException e )
+        {
+            monitor.failedRoleLookup( this, appName, roleName, e ) ;
+            throw new RmsException( "Failed to bind entry to a Role", e ) ;
+        }
+
+        monitor.roleLookedUp( this, role ) ;
+        return role ;
     }
 
 

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java	Wed
Apr 28 08:11:48 2004
@@ -16,6 +16,8 @@
  */
 package org.apache.rms.je.role ;
 
+import org.apache.rms.Role;
+
 import java.io.IOException;
 
 
@@ -80,4 +82,35 @@
      * @param roleName the name of the role
      */
     void roleExists( JeRoleDAO dao, String op, String appName, String roleName ) ;
+
+    /**
+     * Monitors events where an application role lookup fails for an operation
+     * because the role does not exist for the application.
+     *
+     * @param dao the data access object
+     * @param op the operation performed on the resource to 'cleanup'
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     */
+    void roleDoesNotExist( JeRoleDAO dao, String op, String appName,
+                           String roleName ) ;
+
+    /**
+     * Monitors events where an application role lookup fails.
+     *
+     * @param dao the data access object
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     * @param fault the fault that caused the failure
+     */
+    void failedRoleLookup( JeRoleDAO dao, String appName, String roleName,
+                           Throwable fault ) ;
+
+    /**
+     * Monitors events where an application role is successfully looked up.
+     *
+     * @param dao the data access object
+     * @param role the application role that is looked up
+     */
+    void roleLookedUp( JeRoleDAO dao, Role role ) ;
 }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
Wed Apr 28 08:11:48 2004
@@ -17,6 +17,9 @@
 package org.apache.rms.je.role ;
 
 
+import org.apache.rms.Role ;
+
+
 /**
  * A do nothing adapter for a RoleDAO monitor.  At a bare minimum this adapter
  * prints out stack traces to the console.  If this is not desired use a Logging
@@ -39,6 +42,7 @@
     {
     }
 
+
     /**
      * Monitors events where the DAO attempts to cleanup a resource but fails
      * due to some fault.
@@ -88,6 +92,7 @@
     {
     }
 
+
     /**
      * Monitors events where the DAO attempts to perform an operation but
      * fails because of the existance of an application role.
@@ -99,6 +104,50 @@
      */
     public void roleExists( JeRoleDAO dao, String op, String appName,
                             String roleName )
+    {
+    }
+
+
+    /**
+     * Monitors events where an application role lookup fails for an operation
+     * because the role does not exist for the application.
+     *
+     * @param dao      the data access object
+     * @param op       the operation performed on the resource to 'cleanup'
+     * @param appName  the name of the application
+     * @param roleName the name of the role
+     */
+    public void roleDoesNotExist( JeRoleDAO dao, String op, String appName,
+                                  String roleName )
+    {
+    }
+
+
+    /**
+     * Monitors events where an application role lookup fails.
+     *
+     * @param dao      the data access object
+     * @param appName  the name of the application
+     * @param roleName the name of the role
+     * @param fault    the fault that caused the failure
+     */
+    public void failedRoleLookup( JeRoleDAO dao, String appName, String roleName,
+                                  Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
+
+
+    /**
+     * Monitors events where an application role is successfully looked up.
+     *
+     * @param dao  the data access object
+     * @param role the application role that is looked up
+     */
+    public void roleLookedUp( JeRoleDAO dao, Role role )
     {
     }
 }

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 08:11:48 2004
@@ -20,6 +20,7 @@
 import org.apache.rms.RmsException ;
 import org.apache.rms.BitPermission ;
 import org.apache.rms.DefaultApplication;
+import org.apache.rms.Role;
 
 import org.apache.rms.je.JeUtils ;
 import org.apache.rms.je.AbstractJeTest ;
@@ -79,7 +80,7 @@
     }
 
 
-    public void testHas() throws Exception
+    public void testCreateAndHas() throws Exception
     {
         assertFalse( roleDAO.has( "app1", "roleA" ) ) ;
 
@@ -93,7 +94,47 @@
         assertTrue( roleDAO.has( "app1", "roleB" ) ) ;
         assertTrue( roleDAO.has( "app1", "roleC" ) ) ;
         assertTrue( roleDAO.has( "app1", "roleD" ) ) ;
+    }
+
+
+    public void testCreateAndGet() throws Exception
+    {
+        Role role = null ;
+
+        DefaultApplication application = new JeApplication( "app1" ) ;
+
+        try
+        {
+            role = roleDAO.get( application, "roleA" ) ;
+            fail( "should never get here because of an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+
+        roleDAO.create( application, "roleA" ) ;
+        roleDAO.create( application, "roleB" ) ;
+        roleDAO.create( application, "roleC" ) ;
+        roleDAO.create( application, "roleD" ) ;
 
-        
+        role = roleDAO.get( application, "roleA" ) ;
+        assertNotNull( role ) ;
+        assertEquals( "roleA", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = roleDAO.get( application, "roleB" ) ;
+        assertNotNull( role ) ;
+        assertEquals( "roleB", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = roleDAO.get( application, "roleC" ) ;
+        assertNotNull( role ) ;
+        assertEquals( "roleC", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
+
+        role = roleDAO.get( application, "roleD" ) ;
+        assertNotNull( role ) ;
+        assertEquals( "roleD", role.getName() ) ;
+        assertFalse( role.getGrants().hasNext() ) ;
     }
 }

Mime
View raw message