directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10200 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/permissions test/org/apache/rms/je/permissions
Date Fri, 23 Apr 2004 21:19:29 GMT
Author: akarasulu
Date: Fri Apr 23 14:19:28 2004
New Revision: 10200

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionFactoryTest.java
Log:
Commit changes ...

 o fixed major bug that made the JeBitPermissionDAO.getRow(String,int) fail
 o added more methods to verify the correct operation of factory methods
 o added unit test to verify the JeBitPermissionDAO.getRow(String,int) method



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java
Fri Apr 23 14:19:28 2004
@@ -417,7 +417,7 @@
      * @throws RmsException if there are failures accessing the underlying JE
      * databases, or the application and/or the permission name does not exist
      */
-    private DatabaseEntry getRow( String appName, String name, boolean getKey ) throws RmsException
+    DatabaseEntry getRow( String appName, String name, boolean getKey ) throws RmsException
     {
         DatabaseEntry key = new DatabaseEntry() ;
         DatabaseEntry value = new DatabaseEntry() ;
@@ -514,7 +514,7 @@
      * @throws RmsException if there are failures accessing the underlying JE
      * databases, or the application and/or the permission name does not exist
      */
-    private DatabaseEntry getRow( String appName, int index, boolean getKey ) throws RmsException
+    DatabaseEntry getRow( String appName, int index, boolean getKey ) throws RmsException
     {
         DatabaseEntry key = new DatabaseEntry() ;
         DatabaseEntry value = new DatabaseEntry() ;
@@ -539,7 +539,7 @@
 
         try
         {
-            intCursor = byPermName.openSecondaryCursor( null, null ) ;
+            intCursor = byIdx.openSecondaryCursor( null, null ) ;
             appNameCursor = byAppName.openSecondaryCursor( null, null ) ;
 
             status = intCursor

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
Fri Apr 23 14:19:28 2004
@@ -20,12 +20,13 @@
 import org.apache.rms.RmsException ;
 import org.apache.rms.BitPermission;
 import org.apache.rms.je.AbstractJeTest ;
+import org.apache.rms.je.JeUtils;
 import org.apache.rms.je.sequence.Sequence ;
 import org.apache.rms.je.sequence.JeSequenceDao ;
 import org.apache.rms.je.sequence.JeSequenceFactory ;
 
-import com.sleepycat.je.DatabaseConfig ;
-import com.sleepycat.je.SecondaryConfig ;
+import com.sleepycat.je.*;
+import com.sleepycat.bind.EntryBinding;
 
 import java.util.Iterator;
 
@@ -38,8 +39,8 @@
  */
 public class JeBitPermissionDAOTest extends AbstractJeTest
 {
-    BitPermissionDAO bitPermissionDAO ;
-    BitPermissionIndexManager indexManager ;
+    JeBitPermissionDAO bitPermissionDAO ;
+    JeBitPermissionIndexManager indexManager ;
 
 
     protected void setUp() throws Exception
@@ -89,6 +90,30 @@
         super.tearDown() ;
         bitPermissionDAO = null ;
         indexManager = null ;
+    }
+
+
+    public void testGetRowStringInt() throws Exception
+    {
+        bitPermissionDAO.create( "app1", "perm1" ) ;
+        bitPermissionDAO.create( "app1", "perm2" ) ;
+        bitPermissionDAO.create( "app1", "perm3" ) ;
+        bitPermissionDAO.create( "app1", "perm4" ) ;
+
+        assertEquals( 0, bitPermissionDAO.getIndex( "app1", "perm1" ) ) ;
+        assertEquals( 1, bitPermissionDAO.getIndex( "app1", "perm2" ) ) ;
+        assertEquals( 2, bitPermissionDAO.getIndex( "app1", "perm3" ) ) ;
+        assertEquals( 3, bitPermissionDAO.getIndex( "app1", "perm4" ) ) ;
+
+        EntryBinding binding = new JeBitPermissionTupleBinding() ;
+        assertEquals( 1, JeUtils.decodeInt( bitPermissionDAO.getRow(
+                "app1", 0, true ) ) ) ;
+        assertEquals( 2, JeUtils.decodeInt( bitPermissionDAO.getRow(
+                "app1", 1, true ) ) ) ;
+        assertEquals( 3, JeUtils.decodeInt( bitPermissionDAO.getRow(
+                "app1", 2, true ) ) ) ;
+        assertEquals( 4, JeUtils.decodeInt( bitPermissionDAO.getRow(
+                "app1", 3, true ) ) ) ;
     }
 
 

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionFactoryTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionFactoryTest.java
(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionFactoryTest.java
Fri Apr 23 14:19:28 2004
@@ -23,8 +23,8 @@
 import org.apache.rms.je.AbstractJeTest;
 import org.apache.rms.RmsException;
 import org.apache.rms.BitPermission;
-import com.sleepycat.je.DatabaseConfig;
-import com.sleepycat.je.SecondaryConfig;
+import com.sleepycat.je.*;
+import com.sleepycat.bind.EntryBinding;
 
 import java.util.Iterator;
 import java.util.List;
@@ -78,6 +78,7 @@
         JeBitPermissionIndexDAO indexDAO =
                 new JeBitPermissionIndexDAO( getDb( "indexManDb" ) ) ;
         indexManager = new JeBitPermissionIndexManager( indexDAO ) ;
+        indexDAO.setMonitor( new LoggingBitPermissionIndexDAOMonitor() ) ;
         JeSequenceDao seqDAO = new JeSequenceDao( getDb( "seqDb" ) ) ;
         JeSequenceFactory seqFactory = new JeSequenceFactory( seqDAO ) ;
         Sequence seq = seqFactory.create( "indexSeq" ) ;
@@ -97,17 +98,18 @@
 
     public void testAll() throws Exception
     {
-        BitPermission perm = null ;
         factory.create( "app1", "perm1" ) ;
         factory.create( "app1", "perm2" ) ;
         factory.create( "app1", "perm3" ) ;
         factory.create( "app1", "perm4" ) ;
 
         List map = factory.getPermissionsMap( "app1" ) ;
+
         assertEquals( "perm1", ( ( BitPermission ) map.get( 0 ) ).getName() ) ;
         assertEquals( "perm2", ( ( BitPermission ) map.get( 1 ) ).getName() ) ;
         assertEquals( "perm3", ( ( BitPermission ) map.get( 2 ) ).getName() ) ;
         assertEquals( "perm4", ( ( BitPermission ) map.get( 3 ) ).getName() ) ;
+        assertEquals( 4, map.size() ) ;
 
         try
         {
@@ -118,7 +120,7 @@
         {
         }
 
-        bitPermissionDAO.delete( "app1", "perm1" ) ;
+        factory.delete( "app1", "perm1" ) ;
         try
         {
             bitPermissionDAO.getIndex( "app1", "perm1" ) ;
@@ -128,13 +130,28 @@
         {
         }
 
-        bitPermissionDAO.create( "app1", "perm5" ) ;
+        map = factory.getPermissionsMap( "app1" ) ;
+        assertEquals( null, ( ( BitPermission ) map.get( 0 ) ) ) ;
+        assertEquals( "perm2", ( ( BitPermission ) map.get( 1 ) ).getName() ) ;
+        assertEquals( "perm3", ( ( BitPermission ) map.get( 2 ) ).getName() ) ;
+        assertEquals( "perm4", ( ( BitPermission ) map.get( 3 ) ).getName() ) ;
+        assertEquals( 4, map.size() ) ;
+
+        factory.create( "app1", "perm5" ) ;
         assertEquals( 0, bitPermissionDAO.getIndex( "app1", "perm5" ) ) ;
-        bitPermissionDAO.create( "app1", "perm1" ) ;
+        factory.create( "app1", "perm1" ) ;
         assertEquals( 4, bitPermissionDAO.getIndex( "app1", "perm1" ) ) ;
-        bitPermissionDAO.rename( "app1", "perm1", "perm6" ) ;
+        factory.rename( "app1", "perm1", "perm6" ) ;
         assertEquals( 4, bitPermissionDAO.getIndex( "app1", "perm6" ) ) ;
 
+        map = factory.getPermissionsMap( "app1" ) ;
+        assertEquals( "perm5", ( ( BitPermission ) map.get( 0 ) ).getName() ) ;
+        assertEquals( "perm2", ( ( BitPermission ) map.get( 1 ) ).getName() ) ;
+        assertEquals( "perm3", ( ( BitPermission ) map.get( 2 ) ).getName() ) ;
+        assertEquals( "perm4", ( ( BitPermission ) map.get( 3 ) ).getName() ) ;
+        assertEquals( "perm6", ( ( BitPermission ) map.get( 4 ) ).getName() ) ;
+        assertEquals( 5, map.size() ) ;
+
         try
         {
             bitPermissionDAO.getIndex( "app1", "perm1" ) ;
@@ -144,44 +161,17 @@
         {
         }
 
-        assertEquals( 4, bitPermissionDAO.getPermission( "app1",
-                "perm6" ).getIndex() ) ;
-
-        bitPermissionDAO.create( "app2", "permA" ) ;
-        assertEquals( 0, bitPermissionDAO.getIndex( "app2", "permA" ) ) ;
+        factory.create( "app2", "permA" ) ;
+        map = factory.getPermissionsMap( "app1" ) ;
+        assertEquals( "perm5", ( ( BitPermission ) map.get( 0 ) ).getName() ) ;
+        assertEquals( "perm2", ( ( BitPermission ) map.get( 1 ) ).getName() ) ;
+        assertEquals( "perm3", ( ( BitPermission ) map.get( 2 ) ).getName() ) ;
+        assertEquals( "perm4", ( ( BitPermission ) map.get( 3 ) ).getName() ) ;
+        assertEquals( "perm6", ( ( BitPermission ) map.get( 4 ) ).getName() ) ;
+        assertEquals( 5, map.size() ) ;
 
-        Iterator list = null ;
-        BitPermission perm = null ;
-        String name = null ;
-
-        list = bitPermissionDAO.list() ;
-        perm = ( BitPermission ) list.next() ;
-        assertEquals( "perm2", perm.getName() ) ;
-        perm = ( BitPermission ) list.next() ;
-        assertEquals( "perm3", perm.getName() ) ;
-        perm = ( BitPermission ) list.next() ;
-        assertEquals( "perm4", perm.getName() ) ;
-        perm = ( BitPermission ) list.next() ;
-        assertEquals( "perm5", perm.getName() ) ;
-        perm = ( BitPermission ) list.next() ;
-        assertEquals( "perm6", perm.getName() ) ;
-        perm = ( BitPermission ) list.next() ;
-        assertEquals( "permA", perm.getName() ) ;
-        assertFalse( list.hasNext() ) ;
-
-        list = bitPermissionDAO.listNames() ;
-        name = ( String ) list.next() ;
-        assertEquals( "perm2", name ) ;
-        name = ( String ) list.next() ;
-        assertEquals( "perm3", name ) ;
-        name = ( String ) list.next() ;
-        assertEquals( "perm4", name ) ;
-        name = ( String ) list.next() ;
-        assertEquals( "perm5", name ) ;
-        name = ( String ) list.next() ;
-        assertEquals( "perm6", name ) ;
-        name = ( String ) list.next() ;
-        assertEquals( "permA", name ) ;
-        assertFalse( list.hasNext() ) ;
+        map = factory.getPermissionsMap( "app2" ) ;
+        assertEquals( "permA", ( ( BitPermission ) map.get( 0 ) ).getName() ) ;
+        assertEquals( 1, map.size() ) ;
     }
 }

Mime
View raw message