directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cp...@apache.org
Subject [05/10] directory-fortress-core git commit: started adding tests
Date Mon, 28 Nov 2016 21:13:32 GMT
started adding tests


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/9f17b7cb
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/9f17b7cb
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/9f17b7cb

Branch: refs/heads/master
Commit: 9f17b7cbd016a6ab0cd311b1c353effc92ca3b99
Parents: ea5f023
Author: clp207 <clp207@psu.edu>
Authored: Mon Nov 14 11:23:08 2016 -0500
Committer: clp207 <clp207@psu.edu>
Committed: Mon Nov 14 11:23:08 2016 -0500

----------------------------------------------------------------------
 .../directory/fortress/core/GlobalIds.java      |   5 +
 .../directory/fortress/core/PropertyMgr.java    |   2 +-
 .../fortress/core/PropertyMgrFactory.java       | 111 +++++++++++++++++++
 .../fortress/core/rest/PropertyMgrRestImpl.java |  74 +++++++++++++
 .../fortress/core/impl/FortressJUnitTest.java   |   3 +
 .../fortress/core/impl/PropertyMgrImplTest.java |  73 ++++++++++++
 6 files changed, 267 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/9f17b7cb/src/main/java/org/apache/directory/fortress/core/GlobalIds.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/GlobalIds.java b/src/main/java/org/apache/directory/fortress/core/GlobalIds.java
index bc9bf08..bc542c4 100755
--- a/src/main/java/org/apache/directory/fortress/core/GlobalIds.java
+++ b/src/main/java/org/apache/directory/fortress/core/GlobalIds.java
@@ -108,6 +108,11 @@ public final class GlobalIds
      */
     public static final String GROUP_IMPLEMENTATION = "groupmgr.implementation";
 
+    /**
+     * When this optional tag, {@code propertyImplementation}, is placed in Fortress properties,
its class name will be the default {@link PropertyMgr} instance used.
+     */
+    public static final String PROPERTY_IMPLEMENTATION = "propertymgr.implementation";
+    
     // AUTHENTICATION_TYPE
     /**
      * This property is used to specify if authentication is being performed within a security
realm.

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/9f17b7cb/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java b/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
index d244546..b849c37 100644
--- a/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
+++ b/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
@@ -23,7 +23,7 @@ import java.util.Properties;
 
 import org.apache.directory.fortress.core.model.FortEntity;
 
-public interface PropertyMgr
+public interface PropertyMgr extends Manageable
 {
     /**
      * Adds properties (ftProps) to a supplied fortress entity (Group, Role, AdminRole, Permission,
PermObj) 

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/9f17b7cb/src/main/java/org/apache/directory/fortress/core/PropertyMgrFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/PropertyMgrFactory.java b/src/main/java/org/apache/directory/fortress/core/PropertyMgrFactory.java
new file mode 100644
index 0000000..8f17d81
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/PropertyMgrFactory.java
@@ -0,0 +1,111 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you 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 permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.fortress.core;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.directory.fortress.core.model.Session;
+import org.apache.directory.fortress.core.rest.PropertyMgrRestImpl;
+import org.apache.directory.fortress.core.util.ClassUtil;
+import org.apache.directory.fortress.core.util.Config;
+import org.apache.directory.fortress.core.util.VUtil;
+
+public class PropertyMgrFactory
+{
+
+    private static final String CLS_NM = PropertyMgrFactory.class.getName();
+
+    /**
+     * Create and return a reference to {@link PropertyMgr} object using HOME context.
+     *
+     * @return instance of {@link PropertyMgr}.
+     * @throws SecurityException in the event of failure during instantiation.
+     */
+    public static PropertyMgr createInstance()
+        throws SecurityException
+    {
+        return createInstance( GlobalIds.HOME );
+    }
+
+    /**
+     * Create and return a reference to {@link PropertyMgr} object.
+     *
+     * @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
+     * @return instance of {@link PropertyMgr}.
+     * @throws SecurityException in the event of failure during instantiation.
+     */
+    public static PropertyMgr createInstance(String contextId)
+        throws SecurityException
+    {
+        VUtil.assertNotNull(contextId, GlobalErrIds.CONTEXT_NULL, CLS_NM + ".createInstance");
+        
+        String propertyClassName = Config.getInstance().getProperty(GlobalIds.PROPERTY_IMPLEMENTATION);
+        
+        PropertyMgr propertyMgr;
+
+        if ( StringUtils.isEmpty( propertyClassName ) )
+        {
+            if(Config.getInstance().isRestEnabled())
+            {
+                propertyMgr = new PropertyMgrRestImpl();
+            }
+            else
+            {
+                propertyMgr = new org.apache.directory.fortress.core.impl.PropertyMgrImpl();
+            }
+        }
+        else
+        {
+            propertyMgr = ( PropertyMgr ) ClassUtil.createInstance(propertyClassName);
+        }
+
+        propertyMgr.setContextId(contextId);
+        return propertyMgr;
+    }
+
+    /**
+     * Create and return a reference to {@link PropertyMgr} object using HOME context.
+     *
+     * @param adminSess contains a valid Fortress A/RBAC Session object.
+     * @return instance of {@link PropertyMgr}.
+     * @throws SecurityException in the event of failure during instantiation.
+     */
+    public static PropertyMgr createInstance(Session adminSess)
+        throws SecurityException
+    {
+        return createInstance( GlobalIds.HOME, adminSess );
+    }
+
+    /**
+     * Create and return a reference to {@link PropertyMgr} object.
+     *
+     * @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
+     * @param adminSess contains a valid Fortress A/RBAC Session object.
+     * @return instance of {@link PropertyMgr}.
+     * @throws SecurityException in the event of failure during instantiation.
+     */
+    public static PropertyMgr createInstance(String contextId, Session adminSess)
+        throws SecurityException
+    {
+        PropertyMgr propertyMgr = createInstance(contextId);
+        propertyMgr.setAdmin(adminSess);
+        return propertyMgr;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/9f17b7cb/src/main/java/org/apache/directory/fortress/core/rest/PropertyMgrRestImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/rest/PropertyMgrRestImpl.java
b/src/main/java/org/apache/directory/fortress/core/rest/PropertyMgrRestImpl.java
new file mode 100644
index 0000000..cb39abc
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/rest/PropertyMgrRestImpl.java
@@ -0,0 +1,74 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you 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 permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.fortress.core.rest;
+
+import java.util.Properties;
+
+import org.apache.directory.fortress.core.PropertyMgr;
+import org.apache.directory.fortress.core.SecurityException;
+import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.model.Session;
+
+public class PropertyMgrRestImpl implements PropertyMgr
+{
+
+    @Override
+    public FortEntity add( FortEntity entity, Properties props ) throws SecurityException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public FortEntity update( FortEntity entity, Properties props ) throws SecurityException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void delete( FortEntity entity, Properties props ) throws SecurityException
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public Properties get( FortEntity entity ) throws SecurityException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void setAdmin( Session session )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void setContextId( String contextId )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/9f17b7cb/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 bad85dd..55d0b9e 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
@@ -219,6 +219,9 @@ public class FortressJUnitTest extends TestCase
         suite.addTest( new GroupMgrImplTest( "testGroupRoles" ) );
         suite.addTest( new GroupMgrImplTest( "testRoleGroups" ) );
 
+        // PropertyMgr APIs
+        suite.addTest( new PropertyMgrImplTest( "testAddProperties" ) );
+        
         /***********************************************************/
         /* 3. Interrogation                                        */
         /***********************************************************/

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/9f17b7cb/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
new file mode 100644
index 0000000..d1ac3f2
--- /dev/null
+++ b/src/test/java/org/apache/directory/fortress/core/impl/PropertyMgrImplTest.java
@@ -0,0 +1,73 @@
+
+package org.apache.directory.fortress.core.impl;
+
+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.FortEntity;
+import org.apache.directory.fortress.core.model.Role;
+import org.apache.directory.fortress.core.model.Session;
+import org.apache.directory.fortress.core.util.LogUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.TestCase;
+
+public class PropertyMgrImplTest extends TestCase
+{
+    private static final String CLS_NM = PropertyMgrImplTest.class.getName();
+    private static final Logger LOG = LoggerFactory.getLogger( CLS_NM );
+    private static Session adminSess = null;
+
+    public static final String[][] PROPS = {
+        {
+            "test-key",
+            "test-value"
+        }        
+    };
+    
+    public PropertyMgrImplTest( String name )
+    {
+        super( name );
+    }
+
+    public void testAddProperties(){
+        
+        Role role = RoleTestData.getRole( RoleTestData.ROLES_TR1[0] );
+        
+        addProperties( "ADD-PROP-RLE", role, PROPS[0] );        
+    }
+    
+    public static void addProperties(String msg, FortEntity entity, String[] propArray )
+    {
+        LogUtil.logIt( msg );
+        try
+        {            
+            PropertyMgr propertyMgr = getManagedPropertyMgr();
+            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 PropertyMgr getManagedPropertyMgr() throws SecurityException
+    {
+        return PropertyMgrFactory.createInstance( TestUtils.getContext(), adminSess );
+    }
+    
+    public static Properties getProperty( String[] prop )
+    {
+        Properties props = new Properties();
+        props.setProperty( prop[0], prop[1] );
+        return props;        
+    }
+}


Mime
View raw message