KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > user > UserSessionManagerAccessorTest


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  * UserSessionManagerAccessorTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.security.user;
25
26 // java imports
27
import java.util.Set JavaDoc;
28 import java.util.HashSet JavaDoc;
29
30 // junit imports
31
import junit.framework.*;
32
33 // coadunation imports
34
import com.rift.coad.lib.configuration.Configuration;
35 import com.rift.coad.lib.configuration.ConfigurationFactory;
36 import com.rift.coad.lib.security.Validator;
37 import com.rift.coad.lib.security.AuthorizationException;
38 import com.rift.coad.lib.security.SecurityException;
39 import com.rift.coad.lib.security.SessionManager;
40 import com.rift.coad.lib.security.ThreadsPermissionContainer;
41 import com.rift.coad.lib.security.ThreadPermissionSession;
42 import com.rift.coad.lib.security.RoleManager;
43 import com.rift.coad.lib.security.UserSession;
44
45 /**
46  * This object is responsible for testing the accessor class.
47  *
48  * @author Brett Chaldecott
49  */

50 public class UserSessionManagerAccessorTest extends TestCase {
51     
52     public UserSessionManagerAccessorTest(String JavaDoc testName) {
53         super(testName);
54     }
55
56     protected void setUp() throws Exception JavaDoc {
57     }
58
59     protected void tearDown() throws Exception JavaDoc {
60     }
61
62     public static Test suite() {
63         TestSuite suite = new TestSuite(UserSessionManagerAccessorTest.class);
64         
65         return suite;
66     }
67
68     /**
69      * Test of init method, of class com.rift.coad.lib.security.user.UserSessionManagerAccessor.
70      */

71     public void testUserSessionManagerAccessor() throws Exception JavaDoc {
72         System.out.println("testUserSessionManagerAccessor");
73         
74         // initialize the session manager
75
ThreadsPermissionContainer permissionContainer =
76                 new ThreadsPermissionContainer();
77         SessionManager.init(permissionContainer);
78         SessionManager.getInstance().initSession();
79         
80         // add a user to the session for the current thread
81
RoleManager.getInstance();
82         
83         // init the user session manager
84
UserStoreManager userStoreManager = new UserStoreManager();
85         UserSessionManager userSessionManager = new UserSessionManager(
86                 permissionContainer,userStoreManager);
87         
88         // init the user session manager accessor
89
UserSessionManagerAccessor userSessionManagerAccessor =
90                 UserSessionManagerAccessor.init(userSessionManager);
91         
92         // get the user session manager
93
try {
94             userSessionManagerAccessor.getUserSessionManager();
95             fail("Was granted access to the user session manager");
96         } catch (AuthorizationException ex) {
97             // ignore
98
}
99         
100         // add a new user object and add to the permission
101
Set JavaDoc set = new HashSet JavaDoc();
102         set.add("test");
103         UserSession user = new UserSession("testuser", set);
104         permissionContainer.putSession(new Long JavaDoc(Thread.currentThread().getId()),
105                 new ThreadPermissionSession(
106                 new Long JavaDoc(Thread.currentThread().getId()),user));
107         
108         // get the user session manager
109
try {
110             userSessionManagerAccessor.getUserSessionManager();
111         } catch (AuthorizationException ex) {
112             fail("Was not granted access to the user session manager accessor");
113         }
114     }
115
116     
117     
118 }
119
Popular Tags