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