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: * WebServiceManagerTest.java
020: *
021: * JUnit based test
022: */
023:
024: package com.rift.coad.lib.deployment.webservice;
025:
026: // java imports
027: import java.util.Map;
028: import java.util.HashMap;
029: import java.util.HashSet;
030: import java.util.Set;
031: import java.util.Iterator;
032:
033: // axis includes
034: import org.apache.axis.AxisEngine;
035: import org.apache.axis.server.AxisServer;
036: import org.apache.axis.management.ServiceAdmin;
037: import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
038: import org.apache.axis.EngineConfiguration;
039:
040: // junit imports
041: import junit.framework.*;
042:
043: // coadunation imports
044: import com.rift.coad.lib.thirdparty.axis.AxisManager;
045: import com.rift.coad.lib.deployment.DeploymentLoader;
046: import com.rift.coad.lib.deployment.DeploymentLoader;
047: import com.rift.coad.lib.thirdparty.axis.AxisManager;
048: import com.rift.coad.lib.interceptor.InterceptorFactory;
049: import com.rift.coad.lib.naming.NamingDirector;
050: import com.rift.coad.lib.security.RoleManager;
051: import com.rift.coad.lib.security.SessionManager;
052: import com.rift.coad.lib.security.ThreadPermissionSession;
053: import com.rift.coad.lib.security.ThreadsPermissionContainer;
054: import com.rift.coad.lib.security.UserSession;
055: import com.rift.coad.lib.security.login.LoginManager;
056: import com.rift.coad.lib.security.user.UserSessionManager;
057: import com.rift.coad.lib.security.user.UserStoreManager;
058: import com.rift.coad.lib.thread.CoadunationThreadGroup;
059: import com.rift.coad.lib.transaction.TransactionDirector;
060:
061: /**
062: *
063: * @author Brett Chaldecott
064: */
065: public class WebServiceManagerTest extends TestCase {
066:
067: public WebServiceManagerTest(String testName) {
068: super (testName);
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(WebServiceManagerTest.class);
079:
080: return suite;
081: }
082:
083: /**
084: * Test of class com.rift.coad.lib.deployment.webservice.WebServiceManager.
085: */
086: public void testWebServiceManager() throws Exception {
087: System.out.println("testWebServiceManager");
088:
089: // init the session information
090: ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
091: SessionManager.init(permissions);
092: UserStoreManager userStoreManager = new UserStoreManager();
093: UserSessionManager sessionManager = new UserSessionManager(
094: permissions, userStoreManager);
095: LoginManager.init(sessionManager, userStoreManager);
096: // instanciate the thread manager
097: CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
098: sessionManager, userStoreManager);
099:
100: // add a user to the session for the current thread
101: RoleManager.getInstance();
102:
103: InterceptorFactory.init(permissions, 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: permissions.putSession(
111: new Long(Thread.currentThread().getId()),
112: new ThreadPermissionSession(new Long(Thread
113: .currentThread().getId()), user));
114:
115: // init the naming director
116: NamingDirector.init(threadGroup);
117:
118: // instanciate the transaction director
119: TransactionDirector transactionDirector = TransactionDirector
120: .init();
121:
122: // instanciate the deployment loader
123: DeploymentLoader deploymentLoader = new DeploymentLoader(
124: new java.io.File(System.getProperty("test.jar")));
125:
126: // instanciate the axis engine
127: AxisManager.init();
128:
129: // instanciate the web service manager
130: WebServiceManager instance = new WebServiceManager();
131:
132: // load the files
133: instance.load(deploymentLoader);
134:
135: // retrieve the keys
136: Set paths = instance.getServices();
137: if (paths.size() != 1) {
138: fail("There should be one path there are [" + paths.size()
139: + "]");
140: }
141:
142: if (paths.contains("/WebServiceTest") == false) {
143: fail("There should be one path [/WebServiceTest]");
144: }
145:
146: // retrieve the service reference
147: if (instance.getService("/WebServiceTest") == null) {
148: fail("Failed to retrieve the service reference.");
149: }
150:
151: // unload the service
152: instance.unLoad(deploymentLoader);
153:
154: paths = instance.getServices();
155: if (paths.size() != 0) {
156: fail("There should be zero paths there are ["
157: + paths.size() + "]");
158: }
159: }
160:
161: }
|