directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cp...@apache.org
Subject [06/10] directory-fortress-core git commit: have properties crud test working
Date Mon, 28 Nov 2016 21:13:33 GMT
have properties crud test working


Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/7bf1852e
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/7bf1852e
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/7bf1852e

Branch: refs/heads/master
Commit: 7bf1852ea3a7c890047303001fc7155b111625be
Parents: 9f17b7c
Author: clp207 <clp207@psu.edu>
Authored: Tue Nov 22 13:18:12 2016 -0500
Committer: clp207 <clp207@psu.edu>
Committed: Tue Nov 22 13:18:12 2016 -0500

----------------------------------------------------------------------
 .../fortress/core/impl/AdminRoleDAO.java        |  2 +-
 .../directory/fortress/core/impl/GroupDAO.java  |  2 +-
 .../fortress/core/impl/PropertyDAO.java         |  4 +
 .../directory/fortress/core/impl/PropertyP.java |  8 +-
 .../fortress/core/impl/FortressJUnitTest.java   |  2 +-
 .../fortress/core/impl/PropertyMgrImplTest.java | 84 +++++++++++++++++++-
 6 files changed, 91 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7bf1852e/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java
index 4640f08..786ed4e 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java
@@ -699,6 +699,6 @@ final class AdminRoleDAO extends LdapDataProvider implements PropertyProvider<Ad
     @Override
     public FortEntity getEntity( AdminRole entity ) throws FinderException
     {
-        return this.getEntity( entity );
+        return this.getRole( entity );
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7bf1852e/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java
index 3dea0fe..d951834 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java
@@ -81,7 +81,7 @@ final class GroupDAO extends LdapDataProvider implements PropertyProvider<Group>
         GROUP_PROTOCOL_ATTR_IMPL = Config.getInstance().getProperty( GROUP_PROTOCOL_ATTR
);
         GROUP_PROPERTY_ATTR_IMPL = Config.getInstance().getProperty( GROUP_PROPERTY_ATTR
);
         
-        GROUP_OBJ_CLASS = new String[]{SchemaConstants.TOP_OC, GROUP_OBJECT_CLASS_IMPL };
+        GROUP_OBJ_CLASS = new String[]{SchemaConstants.TOP_OC, GROUP_OBJECT_CLASS_IMPL, GlobalIds.PROPS_AUX_OBJECT_CLASS_NAME
};
         
         GROUP_ATRS = new String[]
             {

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7bf1852e/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
index 15dcf16..99da04d 100644
--- a/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
@@ -127,6 +127,10 @@ public class PropertyDAO extends LdapDataProvider
             ld = getAdminConnection();
             Entry findEntry = read( ld, entityDn, new String[]{ GlobalIds.PROPS } );
             props = PropUtil.getProperties( getAttributes( findEntry, GlobalIds.PROPS ) );
+            
+            if( props == null ){
+                props = new Properties();
+            }
         }
         catch ( LdapNoSuchObjectException e )
         {

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7bf1852e/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
index 1b9609c..fddce56 100644
--- a/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
@@ -56,12 +56,12 @@ public class PropertyP
     }
     
     private PropertyProvider getPropertyProvider( FortEntity entity ){
-        if( entity instanceof Role ){
-            return rDAO;
-        }
-        else if( entity instanceof AdminRole ){
+        if( entity instanceof AdminRole ){
             return arDAO;
         }
+        else  if( entity instanceof Role ){
+            return rDAO;
+        }
         else if( entity instanceof Group ){
             return gDAO;
         }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7bf1852e/src/test/java/org/apache/directory/fortress/core/impl/FortressJUnitTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/directory/fortress/core/impl/FortressJUnitTest.java
b/src/test/java/org/apache/directory/fortress/core/impl/FortressJUnitTest.java
index 55d0b9e..66c071f 100755
--- a/src/test/java/org/apache/directory/fortress/core/impl/FortressJUnitTest.java
+++ b/src/test/java/org/apache/directory/fortress/core/impl/FortressJUnitTest.java
@@ -220,7 +220,7 @@ public class FortressJUnitTest extends TestCase
         suite.addTest( new GroupMgrImplTest( "testRoleGroups" ) );
 
         // PropertyMgr APIs
-        suite.addTest( new PropertyMgrImplTest( "testAddProperties" ) );
+        suite.addTest( new PropertyMgrImplTest( "testCrudProperties" ) );
         
         /***********************************************************/
         /* 3. Interrogation                                        */

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7bf1852e/src/test/java/org/apache/directory/fortress/core/impl/PropertyMgrImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/directory/fortress/core/impl/PropertyMgrImplTest.java
b/src/test/java/org/apache/directory/fortress/core/impl/PropertyMgrImplTest.java
index d1ac3f2..a3307c0 100644
--- a/src/test/java/org/apache/directory/fortress/core/impl/PropertyMgrImplTest.java
+++ b/src/test/java/org/apache/directory/fortress/core/impl/PropertyMgrImplTest.java
@@ -6,7 +6,11 @@ import java.util.Properties;
 import org.apache.directory.fortress.core.PropertyMgr;
 import org.apache.directory.fortress.core.PropertyMgrFactory;
 import org.apache.directory.fortress.core.SecurityException;
+import org.apache.directory.fortress.core.model.AdminRole;
 import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.model.Group;
+import org.apache.directory.fortress.core.model.PermObj;
+import org.apache.directory.fortress.core.model.Permission;
 import org.apache.directory.fortress.core.model.Role;
 import org.apache.directory.fortress.core.model.Session;
 import org.apache.directory.fortress.core.util.LogUtil;
@@ -25,6 +29,17 @@ public class PropertyMgrImplTest extends TestCase
         {
             "test-key",
             "test-value"
+        },
+        {
+            "test-key-2",
+            "test-value-2"
+        }        
+    };
+    
+    public static final String[][] PROPS_UPDATED = {
+        {
+            "test-key",
+            "test-value-updated"
         }        
     };
     
@@ -33,20 +48,62 @@ public class PropertyMgrImplTest extends TestCase
         super( name );
     }
 
-    public void testAddProperties(){
+    public void testCrudProperties(){
         
         Role role = RoleTestData.getRole( RoleTestData.ROLES_TR1[0] );
+        AdminRole adminRole = AdminRoleTestData.getRole( AdminRoleTestData.AROLES_TR1[0]
);
+        PermObj permObj = PermTestData.getObj( PermTestData.OBJS_TOB1[0] );
+        Permission permOp = PermTestData.getOp( permObj.getObjName(), PermTestData.OPS_TOP1[0]
);
+        Group group = GroupTestData.TEST_GROUP1;
+        
+        addProperties( "ADD-PROP-RLE", role, PROPS );        
+        addProperties( "ADD-PROP-ADMRLE", adminRole, PROPS );
+        addProperties( "ADD-PROP-POBJ", permObj, PROPS );
+        addProperties( "ADD-PROP-POP", permOp, PROPS );
+        addProperties( "ADD-PROP-GRP", group, PROPS );
+        
+        updateProperties( "UPD-PROP-RLE", role, PROPS_UPDATED[0] );        
+        updateProperties( "UPD-PROP-ADMRLE", adminRole, PROPS_UPDATED[0] );
+        updateProperties( "UPD-PROP-POBJ", permObj, PROPS_UPDATED[0] );
+        updateProperties( "UPD-PROP-POP", permOp, PROPS_UPDATED[0] );
+        updateProperties( "UPD-PROP-POP", group, PROPS_UPDATED[0] );
         
-        addProperties( "ADD-PROP-RLE", role, PROPS[0] );        
+        deleteProperties( "DEL-PROP-RLE", role, PROPS_UPDATED[0] );        
+        deleteProperties( "DEL-PROP-ADMRLE", adminRole, PROPS_UPDATED[0] );
+        deleteProperties( "DEL-PROP-POBJ", permObj, PROPS_UPDATED[0] );
+        deleteProperties( "DEL-PROP-POP", permOp, PROPS_UPDATED[0] );
+        deleteProperties( "DEL-PROP-POP", group, PROPS_UPDATED[0] );
     }
     
-    public static void addProperties(String msg, FortEntity entity, String[] propArray )
+    public static void addProperties(String msg, FortEntity entity, String[][] propArrays
)
+    {
+        LogUtil.logIt( msg );
+        try
+        {                        
+            PropertyMgr propertyMgr = getManagedPropertyMgr();
+            
+            for(String[] propArray : propArrays){
+                propertyMgr.add( entity, getProperty( propArray ) );
+            
+                Properties newAddedProps = propertyMgr.get( entity );
+                assertEquals( propArray[1],  newAddedProps.getProperty( propArray[0] ) );
+            }
+        }
+        catch ( SecurityException ex )
+        {
+            LOG.error(
+                "addProperties caught SecurityException rc=" + ex.getErrorId() + ", msg="
+ ex.getMessage(), ex );
+            fail( ex.getMessage() );
+        }
+    }
+    
+    public static void updateProperties(String msg, FortEntity entity, String[] propArray
)
     {
         LogUtil.logIt( msg );
         try
         {            
             PropertyMgr propertyMgr = getManagedPropertyMgr();
-            propertyMgr.add( entity, getProperty( propArray ) );
+            propertyMgr.update( entity, getProperty( propArray ) );
             
             Properties newAddedProps = propertyMgr.get( entity );
             assertEquals( propArray[1],  newAddedProps.getProperty( propArray[0] ) );
@@ -59,6 +116,25 @@ public class PropertyMgrImplTest extends TestCase
         }
     }
     
+    public static void deleteProperties(String msg, FortEntity entity, String[] propArray
)
+    {
+        LogUtil.logIt( msg );
+        try
+        {            
+            PropertyMgr propertyMgr = getManagedPropertyMgr();
+            propertyMgr.delete( entity, getProperty( propArray ) );
+            
+            Properties newAddedProps = propertyMgr.get( entity );
+            assertNull( newAddedProps.getProperty( propArray[0] ) );
+        }
+        catch ( SecurityException ex )
+        {
+            LOG.error(
+                "addProperties caught SecurityException rc=" + ex.getErrorId() + ", msg="
+ ex.getMessage(), ex );
+            fail( ex.getMessage() );
+        }
+    }
+    
     public static PropertyMgr getManagedPropertyMgr() throws SecurityException
     {
         return PropertyMgrFactory.createInstance( TestUtils.getContext(), adminSess );


Mime
View raw message