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: * BeanConnectorTest.java
020: *
021: * JUnit based test
022: */
023:
024: package com.rift.coad.lib.deployment.bean;
025:
026: // java imports
027: import com.rift.coad.lib.transaction.TransactionDirector;
028: import junit.framework.*;
029: import java.util.Set;
030: import java.util.HashSet;
031:
032: // coaduntion imports
033: import com.rift.coad.lib.security.ThreadsPermissionContainer;
034: import com.rift.coad.lib.deployment.DeploymentLoader;
035: import com.rift.coad.lib.cache.CacheRegistry;
036: import com.rift.coad.lib.configuration.ConfigurationFactory;
037: import com.rift.coad.lib.configuration.Configuration;
038: import com.rift.coad.lib.naming.NamingDirector;
039: import com.rift.coad.lib.security.user.UserStoreManager;
040: import com.rift.coad.lib.security.ThreadsPermissionContainer;
041: import com.rift.coad.lib.security.ThreadPermissionSession;
042: import com.rift.coad.lib.security.login.handlers.PasswordInfoHandler;
043: import com.rift.coad.lib.security.SessionManager;
044: import com.rift.coad.lib.security.UserSession;
045: import com.rift.coad.lib.security.RoleManager;
046: import com.rift.coad.lib.security.Validator;
047: import com.rift.coad.lib.security.login.LoginManager;
048: import com.rift.coad.lib.security.user.UserSessionManager;
049: import com.rift.coad.lib.thread.CoadunationThreadGroup;
050: import com.rift.coad.lib.interceptor.InterceptorFactory;
051:
052: /**
053: *
054: * @author Brett Chaldecott
055: */
056: public class BeanConnectorTest extends TestCase {
057:
058: public BeanConnectorTest(String testName) {
059: super (testName);
060: }
061:
062: protected void setUp() throws Exception {
063: }
064:
065: protected void tearDown() throws Exception {
066: }
067:
068: public static Test suite() {
069: TestSuite suite = new TestSuite(BeanConnectorTest.class);
070:
071: return suite;
072: }
073:
074: /**
075: * Test of init method, of class com.rift.coad.lib.deployment.bean.BeanConnector.
076: */
077: public void testBeanConnector() throws Exception {
078: System.out.println("testBeanConnector");
079:
080: System.out.println("Jar path : "
081: + System.getProperty("test.jar"));
082:
083: // instanciate the deployment loader
084: ThreadsPermissionContainer permissionContainer = new ThreadsPermissionContainer();
085:
086: // initialize the thread permissions
087: SessionManager.init(permissionContainer);
088: UserStoreManager userStoreManager = new UserStoreManager();
089: UserSessionManager sessionManager = new UserSessionManager(
090: permissionContainer, userStoreManager);
091: LoginManager.init(sessionManager, userStoreManager);
092:
093: // add a user to the session for the current thread
094: RoleManager.getInstance();
095:
096: // instanciate the thread manager
097: CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
098: sessionManager, userStoreManager);
099:
100: // setup the interceptor factory
101: InterceptorFactory.init(permissionContainer, sessionManager,
102: userStoreManager);
103:
104: // add a new user object and add to the permission
105: Set set = new HashSet();
106: set.add("test");
107: UserSession user = new UserSession("test1", set);
108: permissionContainer.putSession(new Long(Thread.currentThread()
109: .getId()), new ThreadPermissionSession(new Long(Thread
110: .currentThread().getId()), user));
111:
112: // setup the naming
113: NamingDirector.init(threadGroup);
114:
115: // instanciate the transaction director
116: TransactionDirector transactionDirector = TransactionDirector
117: .init();
118:
119: CacheRegistry.init(threadGroup);
120:
121: BeanManager beanManager = new BeanManager(permissionContainer,
122: threadGroup);
123:
124: BeanConnector.init(beanManager);
125:
126: // load the bean
127: DeploymentLoader deploymentLoader = new DeploymentLoader(
128: new java.io.File(System.getProperty("test.jar")));
129:
130: // load the bean
131: beanManager.load(deploymentLoader);
132:
133: // retrieve the instance to the bean
134: BeanConnector instance = BeanConnector.getInstance();
135:
136: // retrieve the list of
137: Set keys = instance.getKeys();
138: if ((keys.size() != 2) || (keys.contains("testbean") != true)) {
139: fail("Failed to load the beans");
140: }
141:
142: // retrieve a bean
143: Object bean = instance.getBean("testbean");
144: if (bean == null) {
145: fail("Failed to retrieve the testbean");
146: }
147:
148: keys = null;
149: bean = null;
150:
151: // load the bean
152: beanManager.unLoad(deploymentLoader);
153:
154: // retrieve the list of
155: keys = instance.getKeys();
156: if ((keys.size() != 0) || (keys.contains("testbean") != false)) {
157: fail("The bean is still in memory");
158: }
159:
160: CacheRegistry.getInstance().shutdown();
161:
162: NamingDirector.getInstance().shutdown();
163: }
164:
165: }
|