directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 57384 - in incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication: . group
Date Wed, 10 Nov 2004 21:48:37 GMT
Author: vtence
Date: Wed Nov 10 13:48:37 2004
New Revision: 57384

Added:
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/group/
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/group/GroupProviderTest.java
Log:
Group management test cases - work in progress

Added: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/group/GroupProviderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/group/GroupProviderTest.java
Wed Nov 10 13:48:37 2004
@@ -0,0 +1,109 @@
+/*
+ *   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 permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.authentication.group;
+
+import junit.framework.TestCase;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.janus.testmodel.Groups;
+import org.apache.janus.testmodel.Subjects;
+import org.apache.janus.testmodel.Usernames;
+
+import javax.security.auth.Subject;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class GroupProviderTest extends TestCase
+{
+    GroupProvider m_provider;
+
+    protected void setUp() throws Exception
+    {
+    }
+
+    /**
+     * o populates a
+     *
+     * o subject populated with sub groups
+     * o ReturnsGroupsAssociatedToPrincipal
+     * o GroupsAreOnlyAllowedOnce
+     * o ReportsDuplicatePrincipalInGroup
+     * o GroupsMustExistToAddAPrincipal
+     * o GroupMembershipIsInherited
+     * o SubGroupMustBeDefined
+     * o GrandGroupMustBeDefined
+     * o ReportsDuplicateSubGroups
+     */
+
+    public void testPopulatesSubjectWithAttributesMappedToSubjectPrincipals()
+    {
+        Subject s = Subjects.with( Usernames.joe() );
+        Collection expectedPrincipals = new ArrayList( s.getPrincipals() );
+        expectedPrincipals.add( Groups.geeks() );
+        expectedPrincipals.add( Groups.men() );
+
+        m_provider = new GroupProvider( singleMapping() );
+        m_provider.populate( s );
+
+        assertTrue( CollectionUtils.isEqualCollection( expectedPrincipals, s.getPrincipals()
));
+    }
+
+    private Map singleMapping()
+    {
+        Map mapping = new HashMap();
+        Collection groups = new ArrayList();
+        groups.add( Groups.geeks() );
+        groups.add( Groups.men() );
+        mapping.put( Usernames.joe(), groups );
+        return mapping;
+    }
+
+    public void testTakesIntoAccountMappingOfAllSubjectPrincipals()
+    {
+        Subject s = Subjects.with( Usernames.joe(), Groups.canadians() );
+        Collection expectedPrincipals = new ArrayList( s.getPrincipals() );
+        expectedPrincipals.add( Groups.geeks() );
+        expectedPrincipals.add( Groups.men() );
+
+        m_provider = new GroupProvider( dualMapping() );
+        m_provider.populate( s );
+
+        assertTrue( CollectionUtils.isEqualCollection( expectedPrincipals, s.getPrincipals()
));
+    }
+
+    private Map dualMapping()
+    {
+        Map mapping = new HashMap();
+        Collection g1 = new ArrayList();
+        g1.add( Groups.geeks() );
+        mapping.put( Usernames.joe(), g1 );
+        Collection g2 = new ArrayList();
+        g2.add( Groups.men() );
+        mapping.put( Groups.canadians(), g2 );
+        return mapping;
+    }
+
+    public void testPrincipalBelongsToNoGroupByDefault()
+    {
+        m_provider = new GroupProvider();
+        Subject s = new Subject();
+        m_provider.populate( s );
+
+        assertTrue( s.getPrincipals( GroupPrincipal.class ).isEmpty() );
+    }
+}

Mime
View raw message