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: * WebServiceWrapperTest.java
020: *
021: * JUnit based test
022: */
023:
024: package com.rift.coad.lib.webservice;
025:
026: // java imports
027: import com.rift.coad.lib.interceptor.InterceptorFactory;
028: import com.rift.coad.lib.naming.NamingDirector;
029: import com.rift.coad.lib.security.RoleManager;
030: import com.rift.coad.lib.security.SessionManager;
031: import com.rift.coad.lib.security.ThreadPermissionSession;
032: import com.rift.coad.lib.security.ThreadsPermissionContainer;
033: import com.rift.coad.lib.security.UserSession;
034: import com.rift.coad.lib.security.login.LoginManager;
035: import com.rift.coad.lib.security.user.UserSessionManager;
036: import com.rift.coad.lib.security.user.UserStoreManager;
037: import com.rift.coad.lib.thread.CoadunationThreadGroup;
038: import com.rift.coad.lib.transaction.TransactionDirector;
039: import java.io.ByteArrayInputStream;
040: import java.util.HashSet;
041: import java.util.Map;
042: import java.util.HashMap;
043: import java.util.Set;
044: import java.util.Iterator;
045:
046: // jaxb imports
047: import javax.xml.soap.MimeHeaders;
048:
049: // axis includes
050: import org.apache.axis.AxisEngine;
051: import org.apache.axis.server.AxisServer;
052: import org.apache.axis.management.ServiceAdmin;
053: import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
054: import org.apache.axis.EngineConfiguration;
055:
056: // junit imports
057: import junit.framework.*;
058:
059: // coadunation imports
060: import com.rift.coad.lib.thirdparty.axis.AxisManager;
061: import com.rift.coad.lib.deployment.DeploymentLoader;
062: import com.rift.coad.lib.deployment.webservice.WebServiceManager;
063:
064: /**
065: *
066: * @author mincemeat
067: */
068: public class WebServiceWrapperTest extends TestCase {
069:
070: public WebServiceWrapperTest(String testName) {
071: super (testName);
072: }
073:
074: protected void setUp() throws Exception {
075: }
076:
077: protected void tearDown() throws Exception {
078: }
079:
080: public static Test suite() {
081: TestSuite suite = new TestSuite(WebServiceWrapperTest.class);
082:
083: return suite;
084: }
085:
086: /**
087: * Test of class com.rift.coad.lib.deployment.webservice.WebServiceManager.
088: */
089: public void testWebServiceManager() throws Exception {
090: System.out.println("testWebServiceManager");
091:
092: // init the session information
093: ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
094: SessionManager.init(permissions);
095: UserStoreManager userStoreManager = new UserStoreManager();
096: UserSessionManager sessionManager = new UserSessionManager(
097: permissions, userStoreManager);
098: LoginManager.init(sessionManager, userStoreManager);
099: // instanciate the thread manager
100: CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
101: sessionManager, userStoreManager);
102:
103: // add a user to the session for the current thread
104: RoleManager.getInstance();
105:
106: InterceptorFactory.init(permissions, sessionManager,
107: userStoreManager);
108:
109: // add a new user object and add to the permission
110: Set set = new HashSet();
111: set.add("test");
112: UserSession user = new UserSession("test1", set);
113: permissions.putSession(
114: new Long(Thread.currentThread().getId()),
115: new ThreadPermissionSession(new Long(Thread
116: .currentThread().getId()), user));
117:
118: // init the naming director
119: NamingDirector.init(threadGroup);
120:
121: // instanciate the transaction director
122: TransactionDirector transactionDirector = TransactionDirector
123: .init();
124:
125: // instanciate the deployment loader
126: DeploymentLoader deploymentLoader = new DeploymentLoader(
127: new java.io.File(System.getProperty("test.jar")));
128:
129: // instanciate the axis engine
130: AxisManager.init();
131:
132: // instanciate the web service manager
133: WebServiceManager instance = new WebServiceManager();
134:
135: // load the files
136: instance.load(deploymentLoader);
137:
138: // retrieve the keys
139: Set paths = instance.getServices();
140: if (paths.size() != 1) {
141: fail("There should be one path there are [" + paths.size()
142: + "]");
143: }
144:
145: if (paths.contains("/WebServiceTest") == false) {
146: fail("There should be one path [/WebServiceTest]");
147: }
148:
149: // retrieve the service reference
150: WebServiceWrapper webServiceWrapper = (WebServiceWrapper) instance
151: .getService("/WebServiceTest");
152:
153: System.out.println(webServiceWrapper.generateWSDL());
154:
155: String xmlQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
156: + "<soapenv:Envelope xmlns:soapenv="
157: + "\"http://schemas.xmlsoap.org/soap/envelope/\" "
158: + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
159: + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
160: + "<soapenv:Body><helloWorld xmlns=\"urn:WebService/wsdl\">"
161: + "<String_1 xmlns=\"\">This is a test call</String_1>"
162: + "</helloWorld></soapenv:Body></soapenv:Envelope>";
163:
164: String xmlResult1 = webServiceWrapper.processRequest(xmlQuery);
165:
166: ByteArrayInputStream input = new ByteArrayInputStream(xmlQuery
167: .getBytes());
168: String xmlResult2 = webServiceWrapper.processRequest(input,
169: new MimeHeaders());
170: System.out.println("Result 1 [" + xmlResult1 + "]");
171: System.out.println("Result 2 [" + xmlResult2 + "]");
172: if (!xmlResult1.equals(xmlResult2)) {
173: fail("The processing requests failed.");
174: }
175:
176: // unload the service
177: instance.unLoad(deploymentLoader);
178:
179: paths = instance.getServices();
180: if (paths.size() != 0) {
181: fail("There should be zero paths there are ["
182: + paths.size() + "]");
183: }
184: }
185:
186: }
|