1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.spi;
18
19 import java.util.Set;
20
21 import org.apache.jetspeed.security.util.test.AbstractSecurityTestcase;
22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 /***
27 * <p>
28 * Unit testing for {@link GroupSecurityHandler}.
29 * </p>
30 *
31 * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
32 */
33 public class TestSecurityMappingHandler extends AbstractSecurityTestcase
34 {
35
36
37
38 /***
39 * @see junit.framework.TestCase#setUp()
40 */
41 protected void setUp() throws Exception
42 {
43 super.setUp();
44 destroyGroupUser();
45 destroyRoleUser();
46 initGroupUser();
47 initRoleUser();
48 }
49
50 /***
51 * @see junit.framework.TestCase#tearDown()
52 */
53 public void tearDown() throws Exception
54 {
55 destroyGroupUser();
56 destroyRoleUser();
57 super.tearDown();
58 }
59
60 /***
61 * <p>
62 * Constructs the suite.
63 * </p>
64 *
65 * @return The {@Test}.
66 */
67 public static Test suite()
68 {
69 return new TestSuite(TestSecurityMappingHandler.class);
70 }
71
72 /***
73 * <p>
74 * Test <code>getRolePrincipals</code>.
75 * </p>
76 */
77 public void testGetRolePrincipals() throws Exception
78 {
79
80 Set principals = smh.getRolePrincipals("testuser");
81 assertNotNull(principals);
82
83 assertEquals(3, principals.size());
84
85 }
86
87 /***
88 * <p>
89 * Test <code>getUserPrincipal</code>.
90 * </p>
91 */
92 public void testGetGroupPrincipals() throws Exception
93 {
94
95 Set principals = smh.getGroupPrincipals("testuser");
96 assertNotNull(principals);
97
98 assertEquals(3, principals.size());
99
100 }
101
102 /***
103 * <p>
104 * Initialize user test object.
105 * </p>
106 */
107 protected void initGroupUser() throws Exception
108 {
109 ums.addUser("testuser", "password");
110 gms.addGroup("testusertogroup1");
111 gms.addGroup("testusertogroup2.group1");
112 gms.addUserToGroup("testuser", "testusertogroup1");
113 gms.addUserToGroup("testuser", "testusertogroup2.group1");
114 }
115
116 /***
117 * <p>
118 * Destroy user test object.
119 * </p>
120 */
121 protected void destroyGroupUser() throws Exception
122 {
123 ums.removeUser("testuser");
124 gms.removeGroup("testusertogroup1");
125 gms.removeGroup("testusertogroup2");
126 gms.removeGroup("testusertogroup2.group1");
127 }
128
129 /***
130 * <p>
131 * Initialize user test object.
132 * </p>
133 */
134 protected void initRoleUser() throws Exception
135 {
136
137 rms.addRole("testusertorole1");
138 rms.addRole("testusertorole2.role1");
139 rms.addRoleToUser("testuser", "testusertorole1");
140 rms.addRoleToUser("testuser", "testusertorole2.role1");
141 }
142
143 /***
144 * <p>
145 * Destroy user test object.
146 * </p>
147 */
148 protected void destroyRoleUser() throws Exception
149 {
150
151 rms.removeRole("testusertorole1");
152 rms.removeRole("testusertorole2");
153 rms.removeRole("testusertorole2.role1");
154 }
155
156 }