Source Code Cross Referenced for RPCProxyTests.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » proxy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services AXIS2 » jax ws » org.apache.axis2.jaxws.proxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.jaxws.proxy;
020:
021:        import java.io.File;
022:        import java.math.BigInteger;
023:        import java.net.MalformedURLException;
024:        import java.net.URL;
025:
026:        import javax.xml.bind.JAXBContext;
027:        import javax.xml.bind.JAXBElement;
028:        import javax.xml.bind.Marshaller;
029:        import javax.xml.datatype.XMLGregorianCalendar;
030:        import javax.xml.namespace.QName;
031:        import javax.xml.ws.BindingProvider;
032:        import javax.xml.ws.Dispatch;
033:        import javax.xml.ws.Holder;
034:        import javax.xml.ws.Service;
035:        import javax.xml.ws.WebServiceException;
036:
037:        import junit.framework.TestCase;
038:        import org.apache.axis2.jaxws.proxy.rpclit.RPCLitImpl;
039:        import org.apache.axis2.jaxws.proxy.rpclit.sei.RPCFault;
040:        import org.apache.axis2.jaxws.proxy.rpclit.sei.RPCLit;
041:        import org.apache.axis2.jaxws.TestLogger;
042:        import org.test.proxy.rpclit.ComplexAll;
043:        import org.test.proxy.rpclit.Enum;
044:
045:        public class RPCProxyTests extends TestCase {
046:
047:            private QName serviceName = new QName(
048:                    "http://org.apache.axis2.jaxws.proxy.rpclit",
049:                    "RPCLitService");
050:            private String axisEndpoint = "http://localhost:8080/axis2/services/RPCLitService";
051:            private QName portName = new QName(
052:                    "http://org.apache.axis2.jaxws.proxy.rpclit", "RPCLit");
053:            private String wsdlLocation = System.getProperty("basedir", ".")
054:                    + "/"
055:                    + "test/org/apache/axis2/jaxws/proxy/rpclit/META-INF/RPCLit.wsdl";
056:
057:            /**
058:             * Utility method to get the proxy
059:             * @return RPCLit proxy
060:             * @throws MalformedURLException
061:             */
062:            public RPCLit getProxy() throws MalformedURLException {
063:                File wsdl = new File(wsdlLocation);
064:                URL wsdlUrl = wsdl.toURL();
065:                Service service = Service.create(null, serviceName);
066:                Object proxy = service.getPort(portName, RPCLit.class);
067:                BindingProvider p = (BindingProvider) proxy;
068:                p.getRequestContext()
069:                        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
070:                                axisEndpoint);
071:
072:                return (RPCLit) proxy;
073:            }
074:
075:            /**
076:             * Utility Method to get a Dispatch<String>
077:             * @return
078:             * @throws MalformedURLException
079:             */
080:            public Dispatch<String> getDispatch() throws MalformedURLException {
081:                File wsdl = new File(wsdlLocation);
082:                URL wsdlUrl = wsdl.toURL();
083:                Service service = Service.create(null, serviceName);
084:                service.addPort(portName, null, axisEndpoint);
085:                Dispatch<String> dispatch = service.createDispatch(portName,
086:                        String.class, Service.Mode.PAYLOAD);
087:                return dispatch;
088:            }
089:
090:            /**
091:             * Simple test that ensures that we can echo a string to an rpc/lit web service
092:             */
093:            public void testSimple() throws Exception {
094:                try {
095:                    RPCLit proxy = getProxy();
096:                    String request = "This is a test...";
097:
098:                    String response = proxy.testSimple(request);
099:                    assertTrue(response != null);
100:                    assertTrue(response.equals(request));
101:                } catch (Exception e) {
102:                    e.printStackTrace();
103:                    fail("Exception received" + e);
104:                }
105:            }
106:
107:            /**
108:             * Simple test that ensures that we can echo a string to an rpc/lit web service
109:             */
110:            public void testSimpleInOut() throws Exception {
111:                try {
112:                    RPCLit proxy = getProxy();
113:                    String request = "This is a test...";
114:                    Holder<String> requestParam = new Holder<String>();
115:                    requestParam.value = request;
116:
117:                    String response = proxy.testSimpleInOut(requestParam);
118:                    assertTrue(response != null);
119:                    assertTrue(response.equals(request));
120:                    assertTrue(requestParam.value.equals(request));
121:                } catch (Exception e) {
122:                    e.printStackTrace();
123:                    fail("Exception received" + e);
124:                }
125:            }
126:
127:            /**
128:             * Simple test that ensures that we can echo a string to an rpc/lit web service
129:             */
130:            public void testSimple2() throws Exception {
131:                try {
132:                    RPCLit proxy = getProxy();
133:                    String request1 = "hello";
134:                    String request2 = "world";
135:
136:                    String response = proxy.testSimple2(request1, request2);
137:                    assertTrue(response != null);
138:                    assertTrue(response.equals("helloworld"));
139:                } catch (Exception e) {
140:                    e.printStackTrace();
141:                    fail("Exception received" + e);
142:                }
143:            }
144:
145:            /**
146:             * Simple test that ensures that we can echo a string to an rpc/lit web service.
147:             * This test passes the information in headers
148:             */
149:            public void testHeader() throws Exception {
150:                RPCLit proxy = getProxy();
151:                String request1 = "hello";
152:                String request2 = "world";
153:
154:                String response = proxy.testHeader(request1, request2);
155:                assertTrue(response != null);
156:                assertTrue(response.equals("helloworld"));
157:
158:            }
159:
160:            /**
161:             * Simple test that ensures that a service fault is thrown correctly
162:             */
163:            public void testFault() throws Exception {
164:                try {
165:                    RPCLit proxy = getProxy();
166:
167:                    proxy.testFault();
168:                    fail("Expected RPCFault");
169:                } catch (RPCFault rpcFault) {
170:                    assertTrue(rpcFault.getMessage().equals("Throw RPCFault"));
171:                    assertTrue(rpcFault.getFaultInfo() == 123);
172:                } catch (Exception e) {
173:                    e.printStackTrace();
174:                    fail("Exception received" + e);
175:                }
176:            }
177:
178:            /**
179:             * Simple test that ensures that we can echo a string to an rpc/lit web service
180:             */
181:            public void testForNull() throws Exception {
182:                try {
183:                    RPCLit proxy = getProxy();
184:                    String request = null;
185:
186:                    String response = proxy.testSimple(request);
187:                    fail("RPC/LIT should throw webserviceException when operation is invoked with null input parameter");
188:                } catch (Exception e) {
189:                    assertTrue(e instanceof  WebServiceException);
190:                    TestLogger.logger.debug(e.getMessage());
191:                }
192:            }
193:
194:            /**
195:             * Simple test that ensures that we can echo a string to an rpc/lit web service
196:             */
197:            public void testForNullReturn() throws Exception {
198:                try {
199:                    RPCLit proxy = getProxy();
200:
201:                    String response = proxy.testSimple("returnNull");
202:                    fail("RPC/LIT should throw webserviceException when operation is invoked with null out parameter");
203:                } catch (Exception e) {
204:                    assertTrue(e instanceof  WebServiceException);
205:                    TestLogger.logger.debug(e.getMessage());
206:                }
207:            }
208:
209:            public void testSimple_Dispatch() throws Exception {
210:                // Send a payload that simulates
211:                // the rpc message
212:                String request = "<tns:testSimple xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit'>"
213:                        + "<simpleIn xsi:type='xsd:string' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"
214:                        + "PAYLOAD WITH XSI:TYPE"
215:                        + "</simpleIn></tns:testSimple>";
216:                Dispatch<String> dispatch = getDispatch();
217:                String response = dispatch.invoke(request);
218:
219:                assertNotNull("dispatch invoke returned null", response);
220:                TestLogger.logger.debug(response);
221:
222:                // Check to make sure the content is correct
223:                assertTrue(!response.contains("soap"));
224:                assertTrue(!response.contains("Envelope"));
225:                assertTrue(!response.contains("Body"));
226:                assertTrue(!response.contains("Fault"));
227:                assertTrue(response.contains("simpleOut"));
228:                assertTrue(!response.contains(":simpleOut")); // Make sure simple out is not namespace qualified
229:                assertTrue(response.contains(":testSimpleResponse")); // Make sure response is namespace qualified  
230:                assertTrue(response.contains("PAYLOAD WITH XSI:TYPE"));
231:            }
232:
233:            public void testSimple2_DispatchWithoutXSIType() throws Exception {
234:                // Send a payload that simulates
235:                // the rpc message
236:                String request = "<tns:testSimple2 xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit'>"
237:                        + "<simple2In1>"
238:                        + "HELLO"
239:                        + "</simple2In1>"
240:                        + "<simple2In2>"
241:                        + "WORLD"
242:                        + "</simple2In2></tns:testSimple2>";
243:                Dispatch<String> dispatch = getDispatch();
244:                String response = dispatch.invoke(request);
245:
246:                assertNotNull("dispatch invoke returned null", response);
247:                TestLogger.logger.debug(response);
248:
249:                // Check to make sure the content is correct
250:                assertTrue(!response.contains("soap"));
251:                assertTrue(!response.contains("Envelope"));
252:                assertTrue(!response.contains("Body"));
253:                assertTrue(!response.contains("Fault"));
254:                assertTrue(response.contains("simple2Out"));
255:                assertTrue(!response.contains(":simple2Out"));// Make sure simpleOut is not namespace qualified
256:                assertTrue(response.contains(":testSimple2Response"));
257:                assertTrue(response.contains("HELLOWORLD"));
258:            }
259:
260:            public void testSimple_DispatchWithoutXSIType() throws Exception {
261:                // Send a payload that simulates
262:                // the rpc message
263:                String request = "<tns:testSimple xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit'>"
264:                        + "<simpleIn>"
265:                        + "PAYLOAD WITHOUT XSI:TYPE"
266:                        + "</simpleIn></tns:testSimple>";
267:                Dispatch<String> dispatch = getDispatch();
268:                String response = dispatch.invoke(request);
269:
270:                assertNotNull("dispatch invoke returned null", response);
271:                TestLogger.logger.debug(response);
272:
273:                // Check to make sure the content is correct
274:                assertTrue(!response.contains("soap"));
275:                assertTrue(!response.contains("Envelope"));
276:                assertTrue(!response.contains("Body"));
277:                assertTrue(!response.contains("Fault"));
278:                assertTrue(response.contains("simpleOut"));
279:                assertTrue(!response.contains(":simpleOut")); // Make sure simpleOut is not namespace qualified
280:                assertTrue(response.contains(":testSimpleResponse"));
281:                assertTrue(response.contains("PAYLOAD WITHOUT XSI:TYPE"));
282:            }
283:
284:            /**
285:             * Simple test that ensures that we can echo a string to an rpc/lit web service.
286:             */
287:            public void testStringList() throws Exception {
288:                try {
289:                    RPCLit proxy = getProxy();
290:                    String[] request = new String[] { "Hello", "World" };
291:
292:                    String[] response = proxy.testStringList2(request);
293:                    assertTrue(response != null);
294:                    assertTrue(response.length == 2);
295:                    assertTrue(response[0].equals("Hello"));
296:                    assertTrue(response[1].equals("World"));
297:                } catch (Exception e) {
298:                    e.printStackTrace();
299:                    fail("Exception received" + e);
300:                }
301:            }
302:
303:            public void testStringList_Dispatch() throws Exception {
304:                // Send a payload that simulates
305:                // the rpc message
306:                String request = "<tns:testStringList2 xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit'>"
307:                        +
308:                        //"<tns:arg_2_0 xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='tns:StringList' >" +
309:                        "<tns:arg_2_0>"
310:                        + "Hello World"
311:                        + "</tns:arg_2_0></tns:testStringList2>";
312:                Dispatch<String> dispatch = getDispatch();
313:                String response = dispatch.invoke(request);
314:
315:                assertNotNull("dispatch invoke returned null", response);
316:                TestLogger.logger.debug(response);
317:
318:                // Check to make sure the content is correct
319:                assertTrue(!response.contains("soap"));
320:                assertTrue(!response.contains("Envelope"));
321:                assertTrue(!response.contains("Body"));
322:                assertTrue(!response.contains("Fault"));
323:                assertTrue(response.contains("testStringList2Return"));
324:                assertTrue(response.contains("testStringList2Response"));
325:                assertTrue(response.contains("Hello World"));
326:            }
327:
328:            /**
329:             * Currently not enabled due to problems with 
330:             * marshaling an xsd:list of QName.
331:             * 
332:             * Users should use document/literal processing if they 
333:             * need such complicated scenarios.
334:             */
335:            public void _testLists() {
336:                try {
337:                    RPCLit proxy = getProxy();
338:                    QName[] request = new QName[] { RPCLitImpl.qname1,
339:                            RPCLitImpl.qname2 };
340:
341:                    QName[] qNames = proxy.testLists(request,
342:                            new XMLGregorianCalendar[0], new String[0],
343:                            new BigInteger[0], new Long[0], new Enum[0],
344:                            new String[0], new ComplexAll());
345:                    assertTrue(qNames.length == 2);
346:                    assertTrue(qNames[0].equals(RPCLitImpl.qname1));
347:                    assertTrue(qNames[1].equals(RPCLitImpl.qname2));
348:                } catch (Exception e) {
349:                    e.printStackTrace();
350:                    fail("Exception received" + e);
351:                }
352:            }
353:
354:            /**
355:             * Currently not enabled due to problems marshalling/unmarshalling
356:             * an xsd:list of XMLGregorianCalendar.
357:             * 
358:             * Users should use document/literal processing if they 
359:             * need such complicated scenarios.
360:             */
361:            public void _testCalendars() {
362:                try {
363:                    RPCLit proxy = getProxy();
364:                    XMLGregorianCalendar[] request = new XMLGregorianCalendar[] {
365:                            RPCLitImpl.bday, RPCLitImpl.holiday };
366:
367:                    XMLGregorianCalendar[] cals = proxy
368:                            .testCalendarList1(request);
369:                    assertTrue(cals.length == 2);
370:                    assertTrue(cals[0].compare(RPCLitImpl.bday) == 0);
371:                    assertTrue(cals[1].compare(RPCLitImpl.holiday) == 0);
372:                } catch (Exception e) {
373:                    e.printStackTrace();
374:                    fail("Exception received" + e);
375:                }
376:            }
377:
378:            public void testBigIntegers() {
379:                try {
380:                    RPCLit proxy = getProxy();
381:                    BigInteger[] request = new BigInteger[] {
382:                            RPCLitImpl.bigInt1, RPCLitImpl.bigInt2 };
383:
384:                    BigInteger[] ints = proxy.testBigIntegerList3(request);
385:                    assertTrue(ints.length == 2);
386:                    assertTrue(ints[0].compareTo(RPCLitImpl.bigInt1) == 0);
387:                    assertTrue(ints[1].compareTo(RPCLitImpl.bigInt2) == 0);
388:                } catch (Exception e) {
389:                    e.printStackTrace();
390:                    fail("Exception received" + e);
391:                }
392:            }
393:
394:            public void testLongs() {
395:                try {
396:                    RPCLit proxy = getProxy();
397:                    Long[] request = new Long[] { new Long(0), new Long(1),
398:                            new Long(2) };
399:
400:                    Long[] longs = proxy.testLongList4(request);
401:                    assertTrue(longs.length == 3);
402:                    assertTrue(longs[0] == 0);
403:                    assertTrue(longs[1] == 1);
404:                    assertTrue(longs[2] == 2);
405:                } catch (Exception e) {
406:                    e.printStackTrace();
407:                    fail("Exception received" + e);
408:                }
409:            }
410:
411:            public void testEnums() {
412:                try {
413:                    RPCLit proxy = getProxy();
414:                    Enum[] request = new Enum[] { Enum.ONE, Enum.TWO,
415:                            Enum.THREE };
416:
417:                    Enum[] enums = proxy.testEnumList5(request);
418:                    assertTrue(enums.length == 3);
419:                    assertTrue(enums[0] == Enum.ONE);
420:                    assertTrue(enums[1] == Enum.TWO);
421:                    assertTrue(enums[2] == Enum.THREE);
422:                } catch (Exception e) {
423:                    e.printStackTrace();
424:                    fail("Exception received" + e);
425:                }
426:            }
427:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.