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: * BeanLoaderTest.java
020: *
021: * JUnit based test
022: */
023:
024: package com.rift.coad.lib.deployment.bean;
025:
026: import com.rift.coad.lib.interceptor.InterceptorFactory;
027: import com.rift.coad.lib.naming.NamingDirector;
028: import com.rift.coad.lib.security.ThreadPermissionSession;
029: import com.rift.coad.lib.security.UserSession;
030: import com.rift.coad.lib.transaction.TransactionDirector;
031: import java.util.HashSet;
032: import java.util.Set;
033: import junit.framework.*;
034: import java.util.Map;
035: import java.util.HashMap;
036: import org.apache.log4j.Logger;
037: import com.rift.coad.lib.deployment.DeploymentLoader;
038: import com.rift.coad.lib.deployment.BeanInfo;
039: import org.apache.log4j.BasicConfigurator;
040:
041: // coadunation import
042: import com.rift.coad.lib.security.ThreadsPermissionContainer;
043: import com.rift.coad.lib.security.user.UserSessionManager;
044: import com.rift.coad.lib.configuration.ConfigurationFactory;
045: import com.rift.coad.lib.configuration.Configuration;
046: import com.rift.coad.lib.security.user.UserStoreManager;
047: import com.rift.coad.lib.security.ThreadsPermissionContainer;
048: import com.rift.coad.lib.security.login.handlers.PasswordInfoHandler;
049: import com.rift.coad.lib.security.SessionManager;
050: import com.rift.coad.lib.security.RoleManager;
051: import com.rift.coad.lib.security.Validator;
052: import com.rift.coad.lib.security.login.LoginManager;
053: import com.rift.coad.lib.thread.CoadunationThreadGroup;
054:
055: /**
056: *
057: * @author Brett Chaldecott
058: */
059: public class BeanLoaderTest extends TestCase {
060:
061: public BeanLoaderTest(String testName) {
062: super (testName);
063: BasicConfigurator.configure();
064: }
065:
066: protected void setUp() throws Exception {
067: }
068:
069: protected void tearDown() throws Exception {
070: }
071:
072: public static Test suite() {
073: TestSuite suite = new TestSuite(BeanLoaderTest.class);
074:
075: return suite;
076: }
077:
078: /**
079: * Test of of class com.rift.coad.lib.deployment.bean.BeanLoader.
080: */
081: public void testBeanLoader() throws Exception {
082: System.out.println("getBeans");
083: System.out.println("Jar path : "
084: + System.getProperty("test.jar"));
085:
086: // instanciate the deployment loader
087: ThreadsPermissionContainer permissionContainer = new ThreadsPermissionContainer();
088:
089: // initialize the thread permissions
090: SessionManager.init(permissionContainer);
091: UserStoreManager userStoreManager = new UserStoreManager();
092: UserSessionManager sessionManager = new UserSessionManager(
093: permissionContainer, userStoreManager);
094: LoginManager.init(sessionManager, userStoreManager);
095:
096: // add a user to the session for the current thread
097: RoleManager.getInstance();
098:
099: // instanciate the thread manager
100: CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
101: sessionManager, userStoreManager);
102:
103: // setup the interceptor factory
104: InterceptorFactory.init(permissionContainer, sessionManager,
105: userStoreManager);
106:
107: // add a new user object and add to the permission
108: Set set = new HashSet();
109: set.add("test");
110: UserSession user = new UserSession("test1", set);
111: permissionContainer.putSession(new Long(Thread.currentThread()
112: .getId()), new ThreadPermissionSession(new Long(Thread
113: .currentThread().getId()), user));
114:
115: // setup the naming
116: NamingDirector.init(threadGroup);
117:
118: // instanciate the transaction director
119: TransactionDirector transactionDirector = TransactionDirector
120: .init();
121:
122: DeploymentLoader deploymentLoader = new DeploymentLoader(
123: new java.io.File(System.getProperty("test.jar")));
124:
125: // instanciate the bean loader
126: BeanLoader instance = new BeanLoader(deploymentLoader,
127: permissionContainer, threadGroup);
128: instance.setContextClassLoader(deploymentLoader
129: .getClassLoader());
130: threadGroup.addThread(instance, "test");
131: instance.start();
132: instance.join();
133: if (!instance.wasSucessfull()) {
134: throw instance.getException();
135: }
136:
137: // retrieve the list of beans
138: Map beans = instance.getBeans();
139: if (beans.get("testbean") == null) {
140: fail("Failed to load the bean");
141: return;
142: }
143:
144: // unload
145: instance.stopThreads();
146:
147: }
148:
149: }
|