KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > security > authority > AuthorityServiceTest


1 /*
2  * Copyright (C) 2006 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.security.authority;
18
19 import javax.transaction.UserTransaction JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.alfresco.repo.security.authentication.AuthenticationComponent;
24 import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
25 import org.alfresco.service.ServiceRegistry;
26 import org.alfresco.service.cmr.security.AuthenticationService;
27 import org.alfresco.service.cmr.security.AuthorityService;
28 import org.alfresco.service.cmr.security.AuthorityType;
29 import org.alfresco.service.cmr.security.PermissionService;
30 import org.alfresco.service.cmr.security.PersonService;
31 import org.alfresco.service.transaction.TransactionService;
32 import org.alfresco.util.ApplicationContextHelper;
33 import org.springframework.context.ApplicationContext;
34
35 public class AuthorityServiceTest extends TestCase
36 {
37     private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
38
39     private AuthenticationComponent authenticationComponent;
40     
41     private AuthenticationComponent authenticationComponentImpl;
42
43     private AuthenticationService authenticationService;
44     
45     private MutableAuthenticationDao authenticationDAO;
46
47     private AuthorityService authorityService;
48
49     private AuthorityService pubAuthorityService;
50
51     private PersonService personService;
52
53     private UserTransaction JavaDoc tx;
54
55     public AuthorityServiceTest()
56     {
57         super();
58
59     }
60
61     public void setUp() throws Exception JavaDoc
62     {
63         authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
64         authenticationComponentImpl = (AuthenticationComponent) ctx.getBean("authenticationComponentImpl");
65         authenticationService = (AuthenticationService) ctx.getBean("authenticationService");
66         authorityService = (AuthorityService) ctx.getBean("authorityService");
67         pubAuthorityService = (AuthorityService) ctx.getBean("AuthorityService");
68         personService = (PersonService) ctx.getBean("personService");
69         authenticationDAO = (MutableAuthenticationDao) ctx.getBean("alfDaoImpl");
70         
71         authenticationComponent.setSystemUserAsCurrentUser();
72         
73         TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE
74                 .getLocalName());
75         tx = transactionService.getUserTransaction();
76         tx.begin();
77
78         if (!authenticationDAO.userExists("andy"))
79         {
80             authenticationService.createAuthentication("andy", "andy".toCharArray());
81         }
82
83         if (!authenticationDAO.userExists("admin"))
84         {
85             authenticationService.createAuthentication("admin", "admin".toCharArray());
86         }
87
88         if (!authenticationDAO.userExists("administrator"))
89         {
90             authenticationService.createAuthentication("administrator", "administrator".toCharArray());
91         }
92         
93     }
94
95     @Override JavaDoc
96     protected void tearDown() throws Exception JavaDoc
97     {
98         authenticationComponentImpl.clearCurrentSecurityContext();
99         tx.rollback();
100         super.tearDown();
101     }
102
103     public void testNonAdminUser()
104     {
105         authenticationComponent.setCurrentUser("andy");
106         assertFalse(authorityService.hasAdminAuthority());
107         assertFalse(pubAuthorityService.hasAdminAuthority());
108         assertEquals(1, authorityService.getAuthorities().size());
109     }
110
111     public void testAdminUser()
112     {
113         authenticationComponent.setCurrentUser("admin");
114         assertTrue(authorityService.hasAdminAuthority());
115         assertTrue(pubAuthorityService.hasAdminAuthority());
116         assertEquals(2, authorityService.getAuthorities().size());
117
118         authenticationComponent.setCurrentUser("administrator");
119         assertTrue(authorityService.hasAdminAuthority());
120         assertTrue(pubAuthorityService.hasAdminAuthority());
121         assertEquals(2, authorityService.getAuthorities().size());
122     }
123
124     public void testAuthorities()
125     {
126         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.ADMIN).size());
127         assertTrue(pubAuthorityService.getAllAuthorities(AuthorityType.ADMIN).contains(
128                 PermissionService.ADMINISTRATOR_AUTHORITY));
129         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.EVERYONE).size());
130         assertTrue(pubAuthorityService.getAllAuthorities(AuthorityType.EVERYONE).contains(
131                 PermissionService.ALL_AUTHORITIES));
132         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
133         assertFalse(pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).contains(
134                 PermissionService.ALL_AUTHORITIES));
135         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.GUEST).size());
136         assertTrue(pubAuthorityService.getAllAuthorities(AuthorityType.GUEST).contains(PermissionService.GUEST_AUTHORITY));
137         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.OWNER).size());
138         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
139         assertEquals(personService.getAllPeople().size(), pubAuthorityService.getAllAuthorities(AuthorityType.USER)
140                 .size());
141
142     }
143
144     public void testCreateAdminAuth()
145     {
146         try
147         {
148             pubAuthorityService.createAuthority(AuthorityType.ADMIN, null, "woof");
149             fail("Should not be able to create an admin authority");
150         }
151         catch (AuthorityException ae)
152         {
153
154         }
155     }
156
157     public void testCreateEveryoneAuth()
158     {
159         try
160         {
161             pubAuthorityService.createAuthority(AuthorityType.EVERYONE, null, "woof");
162             fail("Should not be able to create an everyone authority");
163         }
164         catch (AuthorityException ae)
165         {
166
167         }
168     }
169
170     public void testCreateGuestAuth()
171     {
172         try
173         {
174             pubAuthorityService.createAuthority(AuthorityType.GUEST, null, "woof");
175             fail("Should not be able to create an guest authority");
176         }
177         catch (AuthorityException ae)
178         {
179
180         }
181     }
182
183     public void testCreateOwnerAuth()
184     {
185         try
186         {
187             pubAuthorityService.createAuthority(AuthorityType.OWNER, null, "woof");
188             fail("Should not be able to create an owner authority");
189         }
190         catch (AuthorityException ae)
191         {
192
193         }
194     }
195
196     public void testCreateUserAuth()
197     {
198         try
199         {
200             pubAuthorityService.createAuthority(AuthorityType.USER, null, "woof");
201             fail("Should not be able to create an user authority");
202         }
203         catch (AuthorityException ae)
204         {
205
206         }
207     }
208
209     public void testCreateRootAuth()
210     {
211         String JavaDoc auth;
212
213         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
214         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
215         auth = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "woof");
216         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
217         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
218         pubAuthorityService.deleteAuthority(auth);
219         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
220         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
221
222         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
223         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
224         auth = pubAuthorityService.createAuthority(AuthorityType.ROLE, null, "woof");
225         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
226         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
227         pubAuthorityService.deleteAuthority(auth);
228         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
229         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
230     }
231
232     public void testCreateAuth()
233     {
234         String JavaDoc auth1;
235         String JavaDoc auth2;
236         String JavaDoc auth3;
237         String JavaDoc auth4;
238         String JavaDoc auth5;
239
240         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
241         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
242         auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "one");
243         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
244         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
245         auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "two");
246         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
247         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
248         auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth1, "three");
249         assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
250         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
251         auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth1, "four");
252         assertEquals(4, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
253         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
254         auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth2, "five");
255         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
256         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
257
258         pubAuthorityService.deleteAuthority(auth5);
259         assertEquals(4, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
260         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
261         pubAuthorityService.deleteAuthority(auth4);
262         assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
263         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
264         pubAuthorityService.deleteAuthority(auth3);
265         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
266         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
267         pubAuthorityService.deleteAuthority(auth2);
268         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
269         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
270         pubAuthorityService.deleteAuthority(auth1);
271         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
272         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
273
274         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
275         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
276         auth1 = pubAuthorityService.createAuthority(AuthorityType.ROLE, null, "one");
277         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
278         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
279         auth2 = pubAuthorityService.createAuthority(AuthorityType.ROLE, null, "two");
280         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
281         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
282         auth3 = pubAuthorityService.createAuthority(AuthorityType.ROLE, auth1, "three");
283         assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
284         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
285         auth4 = pubAuthorityService.createAuthority(AuthorityType.ROLE, auth1, "four");
286         assertEquals(4, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
287         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
288         auth5 = pubAuthorityService.createAuthority(AuthorityType.ROLE, auth2, "five");
289         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
290         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
291
292         pubAuthorityService.deleteAuthority(auth5);
293         assertEquals(4, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
294         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
295         pubAuthorityService.deleteAuthority(auth4);
296         assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
297         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
298         pubAuthorityService.deleteAuthority(auth3);
299         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
300         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
301         pubAuthorityService.deleteAuthority(auth2);
302         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
303         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
304         pubAuthorityService.deleteAuthority(auth1);
305         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.ROLE).size());
306         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
307     }
308
309     public void testCreateAuthTree()
310     {
311         String JavaDoc auth1;
312         String JavaDoc auth2;
313         String JavaDoc auth3;
314         String JavaDoc auth4;
315         String JavaDoc auth5;
316
317         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
318         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
319         auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "one");
320         assertEquals("GROUP_one", auth1);
321         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
322         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
323         auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "two");
324         assertEquals("GROUP_two", auth2);
325         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
326         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
327         auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth1, "three");
328         assertEquals("GROUP_three", auth3);
329         assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
330         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
331         auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth1, "four");
332         assertEquals("GROUP_four", auth4);
333         assertEquals(4, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
334         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
335         auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth2, "five");
336         assertEquals("GROUP_five", auth5);
337         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
338         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
339
340         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
341         pubAuthorityService.addAuthority(auth5, "andy");
342         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
343         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
344         // The next call looks for people not users :-)
345
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
346         assertEquals(2, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
347         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
348         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
349         assertEquals(1, pubAuthorityService.getContainingAuthorities(null, auth5, false).size());
350         assertTrue(pubAuthorityService.getContainingAuthorities(null, auth5, false).contains(auth2));
351
352         assertEquals(2, pubAuthorityService.getContainedAuthorities(null, auth2, false).size());
353         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains(auth5));
354         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains("andy"));
355
356         assertEquals(1, pubAuthorityService.getContainedAuthorities(null, auth5, false).size());
357         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth5, false).contains("andy"));
358
359         pubAuthorityService.removeAuthority(auth5, "andy");
360         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
361         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
362         // The next call looks for people not users :-)
363
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
364         assertEquals(0, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
365         assertEquals(1, pubAuthorityService.getContainingAuthorities(null, auth5, false).size());
366         assertTrue(pubAuthorityService.getContainingAuthorities(null, auth5, false).contains(auth2));
367
368         assertEquals(1, pubAuthorityService.getContainedAuthorities(null, auth2, false).size());
369         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains(auth5));
370
371         assertEquals(0, pubAuthorityService.getContainedAuthorities(null, auth5, false).size());
372     }
373
374     public void testCreateAuthNet()
375     {
376         String JavaDoc auth1;
377         String JavaDoc auth2;
378         String JavaDoc auth3;
379         String JavaDoc auth4;
380         String JavaDoc auth5;
381
382         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
383         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
384         auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "one");
385         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
386         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
387         auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "two");
388         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
389         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
390         auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth1, "three");
391         assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
392         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
393         auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth1, "four");
394         assertEquals(4, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
395         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
396         auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth2, "five");
397         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
398         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
399
400         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
401         pubAuthorityService.addAuthority(auth5, "andy");
402         pubAuthorityService.addAuthority(auth1, "andy");
403         
404         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
405         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
406         // The next call looks for people not users :-)
407
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
408         assertEquals(3, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
409         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
410         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
411         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth1));
412         
413         assertEquals(2, pubAuthorityService.getContainedAuthorities(null, auth2, false).size());
414         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains(auth5));
415         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains("andy"));
416         assertEquals(3, pubAuthorityService.getContainedAuthorities(null, auth1, false).size());
417         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth3));
418         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth4));
419         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains("andy"));
420
421         pubAuthorityService.removeAuthority(auth1, "andy");
422         
423         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
424         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
425         // The next call looks for people not users :-)
426
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
427         assertEquals(2, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
428         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
429         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
430         
431         assertEquals(2, pubAuthorityService.getContainedAuthorities(null, auth2, false).size());
432         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains(auth5));
433         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains("andy"));
434         assertEquals(2, pubAuthorityService.getContainedAuthorities(null, auth1, false).size());
435         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth3));
436         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth4));
437     }
438     
439     public void testCreateAuthNet2()
440     {
441         String JavaDoc auth1;
442         String JavaDoc auth2;
443         String JavaDoc auth3;
444         String JavaDoc auth4;
445         String JavaDoc auth5;
446
447         assertEquals(0, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
448         assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
449         auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "one");
450         assertEquals(1, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
451         assertEquals(1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
452         auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, null, "two");
453         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
454         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
455         auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth1, "three");
456         assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
457         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
458         auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth1, "four");
459         assertEquals(4, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
460         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
461         auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, auth2, "five");
462         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
463         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
464         
465         assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
466         pubAuthorityService.addAuthority(auth5, "andy");
467         pubAuthorityService.addAuthority(auth1, "andy");
468         
469         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
470         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
471         // The next call looks for people not users :-)
472
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
473         assertEquals(3, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
474         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
475         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
476         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth1));
477         
478         assertEquals(2, pubAuthorityService.getContainedAuthorities(null, auth2, false).size());
479         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains(auth5));
480         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains("andy"));
481         assertEquals(3, pubAuthorityService.getContainedAuthorities(null, auth1, false).size());
482         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth3));
483         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth4));
484         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains("andy"));
485         
486         
487         pubAuthorityService.addAuthority(auth3, auth2);
488         
489         assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
490         assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
491         // The next call looks for people not users :-)
492
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
493         assertEquals(4, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
494         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
495         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
496         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth1));
497         assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth3));
498         
499         assertEquals(2, pubAuthorityService.getContainedAuthorities(null, auth2, false).size());
500         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains(auth5));
501         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth2, false).contains("andy"));
502         assertEquals(5, pubAuthorityService.getContainedAuthorities(null, auth1, false).size());
503         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth3));
504         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth4));
505         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth2));
506         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth5));
507         assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains("andy"));
508         
509     }
510 }
511
Popular Tags