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