001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security.spi;
018:
019: import java.util.Set;
020:
021: import org.apache.jetspeed.security.util.test.AbstractSecurityTestcase;
022:
023: import junit.framework.Test;
024: import junit.framework.TestSuite;
025:
026: /**
027: * <p>
028: * Unit testing for {@link GroupSecurityHandler}.
029: * </p>
030: *
031: * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
032: */
033: public class TestSecurityMappingHandler extends
034: AbstractSecurityTestcase {
035:
036: /**
037: * @see junit.framework.TestCase#setUp()
038: */
039: protected void setUp() throws Exception {
040: super .setUp();
041: destroyGroupUser();
042: destroyRoleUser();
043: initGroupUser();
044: initRoleUser();
045: }
046:
047: /**
048: * @see junit.framework.TestCase#tearDown()
049: */
050: public void tearDown() throws Exception {
051: destroyGroupUser();
052: destroyRoleUser();
053: super .tearDown();
054: }
055:
056: /**
057: * <p>
058: * Constructs the suite.
059: * </p>
060: *
061: * @return The {@Test}.
062: */
063: public static Test suite() {
064: return new TestSuite(TestSecurityMappingHandler.class);
065: }
066:
067: /**
068: * <p>
069: * Test <code>getRolePrincipals</code>.
070: * </p>
071: */
072: public void testGetRolePrincipals() throws Exception {
073:
074: Set principals = smh.getRolePrincipals("testuser");
075: assertNotNull(principals);
076: // Hierarchy by generalization should return 3 roles.
077: assertEquals(3, principals.size());
078:
079: }
080:
081: /**
082: * <p>
083: * Test <code>getUserPrincipal</code>.
084: * </p>
085: */
086: public void testGetGroupPrincipals() throws Exception {
087:
088: Set principals = smh.getGroupPrincipals("testuser");
089: assertNotNull(principals);
090: // Hierarchy by generalization should return 3 roles.
091: assertEquals(3, principals.size());
092:
093: }
094:
095: /**
096: * <p>
097: * Initialize user test object.
098: * </p>
099: */
100: protected void initGroupUser() throws Exception {
101: ums.addUser("testuser", "password");
102: gms.addGroup("testusertogroup1");
103: gms.addGroup("testusertogroup2.group1");
104: gms.addUserToGroup("testuser", "testusertogroup1");
105: gms.addUserToGroup("testuser", "testusertogroup2.group1");
106: }
107:
108: /**
109: * <p>
110: * Destroy user test object.
111: * </p>
112: */
113: protected void destroyGroupUser() throws Exception {
114: ums.removeUser("testuser");
115: gms.removeGroup("testusertogroup1");
116: gms.removeGroup("testusertogroup2");
117: gms.removeGroup("testusertogroup2.group1");
118: }
119:
120: /**
121: * <p>
122: * Initialize user test object.
123: * </p>
124: */
125: protected void initRoleUser() throws Exception {
126:
127: rms.addRole("testusertorole1");
128: rms.addRole("testusertorole2.role1");
129: rms.addRoleToUser("testuser", "testusertorole1");
130: rms.addRoleToUser("testuser", "testusertorole2.role1");
131: }
132:
133: /**
134: * <p>
135: * Destroy user test object.
136: * </p>
137: */
138: protected void destroyRoleUser() throws Exception {
139:
140: rms.removeRole("testusertorole1");
141: rms.removeRole("testusertorole2");
142: rms.removeRole("testusertorole2.role1");
143: }
144:
145: }
|