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: * DeploymentManagerTest.java
020: *
021: * JUnit based test
022: */
023:
024: package com.rift.coad.lib.deployment;
025:
026: // junit framework
027: import com.rift.coad.lib.transaction.TransactionDirector;
028: import junit.framework.*;
029:
030: // java imports
031: import java.io.FileWriter;
032: import java.io.File;
033: import java.util.Map;
034: import java.util.HashMap;
035: import java.util.Set;
036: import java.util.Iterator;
037: import java.util.Vector;
038: import java.util.Date;
039: import java.util.Set;
040: import java.util.HashSet;
041:
042: // axis includes
043: import org.apache.axis.AxisEngine;
044: import org.apache.axis.server.AxisServer;
045: import org.apache.axis.management.ServiceAdmin;
046: import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
047: import org.apache.axis.EngineConfiguration;
048:
049: // log 4 j imports
050: import org.apache.log4j.Logger;
051:
052: // coadunation imports
053: import com.rift.coad.lib.thread.CoadunationThreadGroup;
054: import com.rift.coad.lib.thread.BasicThread;
055: import com.rift.coad.lib.cache.CacheRegistry;
056: import com.rift.coad.lib.configuration.Configuration;
057: import com.rift.coad.lib.configuration.ConfigurationFactory;
058: import com.rift.coad.lib.deployment.bean.BeanManager;
059: import com.rift.coad.lib.deployment.jmxbean.JMXBeanManager;
060: import com.rift.coad.lib.deployment.webservice.WebServiceManager;
061: import com.rift.coad.lib.security.ThreadsPermissionContainer;
062: import com.rift.coad.lib.security.ThreadPermissionSession;
063: import com.rift.coad.lib.deployment.DeploymentLoader;
064: import com.rift.coad.lib.deployment.test.TestMonitor;
065: import com.rift.coad.lib.naming.NamingDirector;
066: import com.rift.coad.lib.security.user.UserSessionManager;
067: import com.rift.coad.lib.security.user.UserStoreManager;
068: import com.rift.coad.lib.security.login.handlers.PasswordInfoHandler;
069: import com.rift.coad.lib.security.SessionManager;
070: import com.rift.coad.lib.security.RoleManager;
071: import com.rift.coad.lib.security.UserSession;
072: import com.rift.coad.lib.security.Validator;
073: import com.rift.coad.lib.security.login.LoginManager;
074: import com.rift.coad.lib.thirdparty.axis.AxisManager;
075: import com.rift.coad.lib.interceptor.InterceptorFactory;
076:
077: /**
078: *
079: *
080: * @author Brett Chaldecott
081: */
082: public class DeploymentManagerTest extends TestCase {
083:
084: public DeploymentManagerTest(String testName) {
085: super (testName);
086: }
087:
088: protected void setUp() throws Exception {
089: }
090:
091: protected void tearDown() throws Exception {
092: }
093:
094: public static Test suite() {
095: TestSuite suite = new TestSuite(DeploymentManagerTest.class);
096:
097: return suite;
098: }
099:
100: /**
101: * This method test the deployment manager.
102: */
103: public void testDeploymentManager() throws Exception {
104:
105: // init the test jar file
106: File jarFile = new File(System.getProperty("test.jar"));
107: if (jarFile.isFile() == false) {
108: throw new Exception("Test not configured properly");
109: }
110:
111: // init the session information
112: ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
113: SessionManager.init(permissions);
114: UserStoreManager userStoreManager = new UserStoreManager();
115: UserSessionManager sessionManager = new UserSessionManager(
116: permissions, userStoreManager);
117: LoginManager.init(sessionManager, userStoreManager);
118: // instanciate the thread manager
119: CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
120: sessionManager, userStoreManager);
121:
122: // add a user to the session for the current thread
123: RoleManager.getInstance();
124:
125: InterceptorFactory.init(permissions, sessionManager,
126: userStoreManager);
127:
128: // add a new user object and add to the permission
129: Set set = new HashSet();
130: set.add("test");
131: UserSession user = new UserSession("test1", set);
132: permissions.putSession(
133: new Long(Thread.currentThread().getId()),
134: new ThreadPermissionSession(new Long(Thread
135: .currentThread().getId()), user));
136:
137: // init the naming director
138: NamingDirector.init(threadGroup);
139:
140: // instanciate the transaction director
141: TransactionDirector transactionDirector = TransactionDirector
142: .init();
143:
144: // init the database source
145: CacheRegistry.init(threadGroup);
146:
147: // instanciate the bean manager
148: BeanManager beanManager = new BeanManager(permissions,
149: threadGroup);
150: JMXBeanManager jmxBeanManager = new JMXBeanManager(permissions,
151: threadGroup);
152:
153: // instanciate the axis engine
154: AxisManager.init();
155:
156: // instanciate the web service manager
157: WebServiceManager webServiceManager = new WebServiceManager();
158:
159: // init the test
160: TestMonitor.init();
161:
162: // instanciate the thread manager
163: DeploymentManager deploymentManager = new DeploymentManager(
164: threadGroup, beanManager, jmxBeanManager,
165: webServiceManager);
166:
167: // wait on the test
168: TestMonitor.getInstance().monitor();
169:
170: // reset the test monitor
171: TestMonitor.init();
172:
173: // touch the test jar file
174: System.out.println("Set the last modified date on the file ["
175: + jarFile.getPath() + "]");
176: if (jarFile.setLastModified(new Date().getTime()) == false) {
177: fail("Failed to set the last modified time for ["
178: + jarFile.getPath() + "]");
179: }
180:
181: // wait on the test
182: TestMonitor.getInstance().monitor();
183:
184: // terminate the threads
185: deploymentManager.shutdown();
186:
187: CacheRegistry.getInstance().shutdown();
188:
189: NamingDirector.getInstance().shutdown();
190: }
191:
192: }
|