001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * ThreadsPermissionContainerAccessorTest.java
020: *
021: * JUnit based test
022: */
023:
024: // package path
025: package com.rift.coad.lib.security;
026:
027: // junit imports
028: import junit.framework.*;
029:
030: // java imports
031: import java.util.Set;
032: import java.util.HashSet;
033:
034: // coadunation imports
035: import com.rift.coad.lib.configuration.ConfigurationFactory;
036: import com.rift.coad.lib.configuration.Configuration;
037:
038: /**
039: *
040: * @author Brett Chaldecott
041: */
042: public class ThreadsPermissionContainerAccessorTest extends TestCase {
043:
044: public ThreadsPermissionContainerAccessorTest(String testName) {
045: super (testName);
046: }
047:
048: protected void setUp() throws Exception {
049: }
050:
051: protected void tearDown() throws Exception {
052: }
053:
054: public static Test suite() {
055: TestSuite suite = new TestSuite(
056: ThreadsPermissionContainerAccessorTest.class);
057:
058: return suite;
059: }
060:
061: /**
062: * Test of init method, of class com.rift.coad.lib.security.ThreadsPermissionContainerAccessor.
063: */
064: public void testAccessor() throws Exception {
065: System.out.println("testAccessor");
066:
067: Class ref = null;
068: String roleName = "";
069:
070: // initialize the session manager
071: ThreadsPermissionContainer permissionContainer = new ThreadsPermissionContainer();
072: SessionManager.init(permissionContainer);
073: SessionManager.getInstance().initSession();
074:
075: // add a user to the session for the current thread
076: RoleManager.getInstance();
077:
078: // instanciate the container
079: ThreadsPermissionContainerAccessor result = ThreadsPermissionContainerAccessor
080: .init(permissionContainer);
081:
082: try {
083: ThreadsPermissionContainerAccessor.getInstance()
084: .getThreadsPermissionContainer();
085: fail("Was granted access to the permission container");
086: } catch (AuthorizationException ex) {
087: // ignore this was a success
088: }
089:
090: // add a new user object and add to the permission
091: Set set = new HashSet();
092: set.add("test");
093: UserSession user = new UserSession("testuser", set);
094: permissionContainer.putSession(new Long(Thread.currentThread()
095: .getId()), new ThreadPermissionSession(new Long(Thread
096: .currentThread().getId()), user));
097:
098: // failed to get access to the perimission container
099: try {
100: ThreadsPermissionContainerAccessor.getInstance()
101: .getThreadsPermissionContainer();
102: } catch (AuthorizationException ex) {
103: fail("Failed to get access to the permission container");
104: }
105: }
106:
107: }
|