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