KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > webservice > WebServiceWrapperTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * WebServiceWrapperTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.webservice;
25
26 // java imports
27
import com.rift.coad.lib.interceptor.InterceptorFactory;
28 import com.rift.coad.lib.naming.NamingDirector;
29 import com.rift.coad.lib.security.RoleManager;
30 import com.rift.coad.lib.security.SessionManager;
31 import com.rift.coad.lib.security.ThreadPermissionSession;
32 import com.rift.coad.lib.security.ThreadsPermissionContainer;
33 import com.rift.coad.lib.security.UserSession;
34 import com.rift.coad.lib.security.login.LoginManager;
35 import com.rift.coad.lib.security.user.UserSessionManager;
36 import com.rift.coad.lib.security.user.UserStoreManager;
37 import com.rift.coad.lib.thread.CoadunationThreadGroup;
38 import com.rift.coad.lib.transaction.TransactionDirector;
39 import java.io.ByteArrayInputStream JavaDoc;
40 import java.util.HashSet JavaDoc;
41 import java.util.Map JavaDoc;
42 import java.util.HashMap JavaDoc;
43 import java.util.Set JavaDoc;
44 import java.util.Iterator JavaDoc;
45
46 // jaxb imports
47
import javax.xml.soap.MimeHeaders JavaDoc;
48
49
50 // axis includes
51
import org.apache.axis.AxisEngine;
52 import org.apache.axis.server.AxisServer;
53 import org.apache.axis.management.ServiceAdmin;
54 import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
55 import org.apache.axis.EngineConfiguration;
56
57 // junit imports
58
import junit.framework.*;
59
60 // coadunation imports
61
import com.rift.coad.lib.thirdparty.axis.AxisManager;
62 import com.rift.coad.lib.deployment.DeploymentLoader;
63 import com.rift.coad.lib.deployment.webservice.WebServiceManager;
64
65 /**
66  *
67  * @author mincemeat
68  */

69 public class WebServiceWrapperTest extends TestCase {
70     
71     public WebServiceWrapperTest(String JavaDoc testName) {
72         super(testName);
73     }
74
75     protected void setUp() throws Exception JavaDoc {
76     }
77
78     protected void tearDown() throws Exception JavaDoc {
79     }
80
81     public static Test suite() {
82         TestSuite suite = new TestSuite(WebServiceWrapperTest.class);
83         
84         return suite;
85     }
86
87     /**
88      * Test of class com.rift.coad.lib.deployment.webservice.WebServiceManager.
89      */

90     public void testWebServiceManager() throws Exception JavaDoc {
91         System.out.println("testWebServiceManager");
92         
93         // init the session information
94
ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
95         SessionManager.init(permissions);
96         UserStoreManager userStoreManager = new UserStoreManager();
97         UserSessionManager sessionManager = new UserSessionManager(permissions,
98                 userStoreManager);
99         LoginManager.init(sessionManager,userStoreManager);
100         // instanciate the thread manager
101
CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(sessionManager,
102             userStoreManager);
103         
104         // add a user to the session for the current thread
105
RoleManager.getInstance();
106         
107         InterceptorFactory.init(permissions,sessionManager,userStoreManager);
108         
109         // add a new user object and add to the permission
110
Set JavaDoc set = new HashSet JavaDoc();
111         set.add("test");
112         UserSession user = new UserSession("test1", set);
113         permissions.putSession(new Long JavaDoc(Thread.currentThread().getId()),
114                 new ThreadPermissionSession(
115                 new Long JavaDoc(Thread.currentThread().getId()),user));
116         
117         // init the naming director
118
NamingDirector.init(threadGroup);
119         
120         // instanciate the transaction director
121
TransactionDirector transactionDirector = TransactionDirector.init();
122         
123         // instanciate the deployment loader
124
DeploymentLoader deploymentLoader = new DeploymentLoader(
125                 new java.io.File JavaDoc(System.getProperty("test.jar")));
126         
127         // instanciate the axis engine
128
AxisManager.init();
129         
130         // instanciate the web service manager
131
WebServiceManager instance = new WebServiceManager();
132         
133         // load the files
134
instance.load(deploymentLoader);
135         
136         // retrieve the keys
137
Set JavaDoc paths = instance.getServices();
138         if (paths.size() != 1) {
139             fail("There should be one path there are [" + paths.size() + "]");
140         }
141         
142         if (paths.contains("/WebServiceTest") == false) {
143             fail("There should be one path [/WebServiceTest]");
144         }
145         
146         // retrieve the service reference
147
WebServiceWrapper webServiceWrapper =
148                 (WebServiceWrapper)instance.getService("/WebServiceTest");
149         
150         System.out.println(webServiceWrapper.generateWSDL());
151         
152         String JavaDoc xmlQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
153                 "<soapenv:Envelope xmlns:soapenv=" +
154                 "\"http://schemas.xmlsoap.org/soap/envelope/\" " +
155                 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
156                 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
157                 "<soapenv:Body><helloWorld xmlns=\"urn:WebService/wsdl\">" +
158                 "<String_1 xmlns=\"\">This is a test call</String_1>" +
159                 "</helloWorld></soapenv:Body></soapenv:Envelope>";
160         
161         String JavaDoc xmlResult1 = webServiceWrapper.processRequest(xmlQuery);
162         
163         
164         ByteArrayInputStream JavaDoc input = new ByteArrayInputStream JavaDoc(
165                 xmlQuery.getBytes());
166         String JavaDoc xmlResult2 = webServiceWrapper.processRequest(input,
167                 new MimeHeaders JavaDoc());
168         System.out.println("Result 1 [" + xmlResult1 + "]");
169         System.out.println("Result 2 [" + xmlResult2 + "]");
170         if (!xmlResult1.equals(xmlResult2)) {
171             fail("The processing requests failed.");
172         }
173         
174         // unload the service
175
instance.unLoad(deploymentLoader);
176         
177         paths = instance.getServices();
178         if (paths.size() != 0) {
179             fail("There should be zero paths there are [" + paths.size() + "]");
180         }
181     }
182     
183 }
184
Popular Tags