KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > ThreadsPermissionContainerAccessorTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * ThreadsPermissionContainerAccessorTest.java
20  *
21  * JUnit based test
22  */

23
24 // package path
25
package com.rift.coad.lib.security;
26
27 // junit imports
28
import junit.framework.*;
29
30 // java imports
31
import java.util.Set JavaDoc;
32 import java.util.HashSet JavaDoc;
33
34 // coadunation imports
35
import com.rift.coad.lib.configuration.ConfigurationFactory;
36 import com.rift.coad.lib.configuration.Configuration;
37
38 /**
39  *
40  * @author Brett Chaldecott
41  */

42 public class ThreadsPermissionContainerAccessorTest extends TestCase {
43     
44     public ThreadsPermissionContainerAccessorTest(String JavaDoc testName) {
45         super(testName);
46     }
47
48     protected void setUp() throws Exception JavaDoc {
49     }
50
51     protected void tearDown() throws Exception JavaDoc {
52     }
53
54     public static Test suite() {
55         TestSuite suite = new TestSuite(ThreadsPermissionContainerAccessorTest.class);
56         
57         return suite;
58     }
59
60     /**
61      * Test of init method, of class com.rift.coad.lib.security.ThreadsPermissionContainerAccessor.
62      */

63     public void testAccessor() throws Exception JavaDoc {
64         System.out.println("testAccessor");
65         
66         Class JavaDoc ref = null;
67         String JavaDoc roleName = "";
68         
69         // initialize the session manager
70
ThreadsPermissionContainer permissionContainer =
71                 new ThreadsPermissionContainer();
72         SessionManager.init(permissionContainer);
73         SessionManager.getInstance().initSession();
74         
75         // add a user to the session for the current thread
76
RoleManager.getInstance();
77         
78         // instanciate the container
79
ThreadsPermissionContainerAccessor result =
80                 ThreadsPermissionContainerAccessor.init(permissionContainer);
81         
82         try {
83             ThreadsPermissionContainerAccessor.getInstance().
84                     getThreadsPermissionContainer();
85             fail("Was granted access to the permission container");
86         } catch (AuthorizationException ex) {
87             // ignore this was a success
88
}
89         
90         // add a new user object and add to the permission
91
Set JavaDoc set = new HashSet JavaDoc();
92         set.add("test");
93         UserSession user = new UserSession("testuser", set);
94         permissionContainer.putSession(new Long JavaDoc(Thread.currentThread().getId()),
95                 new ThreadPermissionSession(
96                 new Long JavaDoc(Thread.currentThread().getId()),user));
97         
98         // failed to get access to the perimission container
99
try {
100             ThreadsPermissionContainerAccessor.getInstance().
101                     getThreadsPermissionContainer();
102         } catch (AuthorizationException ex) {
103             fail("Failed to get access to the permission container");
104         }
105     }
106
107     
108 }
109
Popular Tags