KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

69     public void testUserStoreManagerAccessor() throws Exception JavaDoc {
70         System.out.println("testUserStoreManagerAccessor");
71         
72         
73         // initialize the session manager
74
ThreadsPermissionContainer permissionContainer =
75                 new ThreadsPermissionContainer();
76         SessionManager.init(permissionContainer);
77         SessionManager.getInstance().initSession();
78         
79         // add a user to the session for the current thread
80
RoleManager.getInstance();
81         
82         // init the user store manager
83
UserStoreManager userStoreManager = new UserStoreManager();
84         UserStoreManagerAccessor result = UserStoreManagerAccessor.init(userStoreManager);
85         
86         // first test
87
try {
88             UserStoreManagerAccessor.getInstance().getUserStoreManager();
89             fail("Got access to the user store manager");
90         } catch (AuthorizationException ex) {
91             // ignore
92
}
93         
94         // add a new user object and add to the permission
95
Set JavaDoc set = new HashSet JavaDoc();
96         set.add("test");
97         UserSession user = new UserSession("testuser", set);
98         permissionContainer.putSession(new Long JavaDoc(Thread.currentThread().getId()),
99                 new ThreadPermissionSession(
100                 new Long JavaDoc(Thread.currentThread().getId()),user));
101         
102         // second test
103
try {
104             UserStoreManagerAccessor.getInstance().getUserStoreManager();
105         } catch (AuthorizationException ex) {
106             fail("Got denied access to the user store manager");
107         }
108     }
109
110     
111 }
112
Popular Tags