Source Code Cross Referenced for GorillaDLWProxyTests.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.net.MalformedURLException;
023:        import java.net.URL;
024:        import java.util.ArrayList;
025:        import java.util.List;
026:
027:        import javax.xml.bind.JAXBContext;
028:        import javax.xml.bind.JAXBElement;
029:        import javax.xml.bind.Marshaller;
030:        import javax.xml.namespace.QName;
031:        import javax.xml.ws.BindingProvider;
032:        import javax.xml.ws.Dispatch;
033:        import javax.xml.ws.Service;
034:
035:        import junit.framework.TestCase;
036:        import org.apache.axis2.jaxws.proxy.gorilla_dlw.sei.GorillaInterface;
037:        import org.apache.axis2.jaxws.TestLogger;
038:
039:        public class GorillaDLWProxyTests extends TestCase {
040:
041:            private QName serviceName = new QName(
042:                    "http://org.apache.axis2.jaxws.proxy.gorilla_dlw",
043:                    "GorillaService");
044:            private String axisEndpoint = "http://localhost:8080/axis2/services/GorillaService";
045:            private QName portName = new QName(
046:                    "http://org.apache.axis2.jaxws.proxy.rpclit", "GorillaPort");
047:            private String wsdlLocation = System.getProperty("basedir", ".")
048:                    + "/"
049:                    + "test/org/apache/axis2/jaxws/proxy/gorilla_dlw/META-INF/gorilla_dlw.wsdl";
050:
051:            /**
052:             * Utility method to get the proxy
053:             * @return GorillaInterface proxy
054:             * @throws MalformedURLException
055:             */
056:            public GorillaInterface getProxy() throws MalformedURLException {
057:                File wsdl = new File(wsdlLocation);
058:                URL wsdlUrl = wsdl.toURL();
059:                Service service = Service.create(null, serviceName);
060:                Object proxy = service
061:                        .getPort(portName, GorillaInterface.class);
062:                BindingProvider p = (BindingProvider) proxy;
063:                p.getRequestContext()
064:                        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
065:                                axisEndpoint);
066:
067:                return (GorillaInterface) proxy;
068:            }
069:
070:            /**
071:             * Utility Method to get a Dispatch<String>
072:             * @return
073:             * @throws MalformedURLException
074:             */
075:            public Dispatch<String> getDispatch() throws MalformedURLException {
076:                File wsdl = new File(wsdlLocation);
077:                URL wsdlUrl = wsdl.toURL();
078:                Service service = Service.create(null, serviceName);
079:                service.addPort(portName, null, axisEndpoint);
080:                Dispatch<String> dispatch = service.createDispatch(portName,
081:                        String.class, Service.Mode.PAYLOAD);
082:                return dispatch;
083:            }
084:
085:            /**
086:             * Simple test that ensures that we can echo a string.
087:             * If this test fails, it usually means that there are connection
088:             * problems or deploy problems.
089:             */
090:            public void testEchoString() throws Exception {
091:                try {
092:                    GorillaInterface proxy = getProxy();
093:
094:                    // Straight Forward Test
095:                    String request = "Hello World";
096:
097:                    String response = proxy.echoString(request);
098:                    assertTrue(response != null);
099:                    assertEquals(response, request);
100:
101:                } catch (Exception e) {
102:                    e.printStackTrace();
103:                    fail("Exception received" + e);
104:                }
105:            }
106:
107:            /**
108:             * Tests that we can echo a null
109:             */
110:            public void testEchoStringNull() throws Exception {
111:                try {
112:                    GorillaInterface proxy = getProxy();
113:                    String request = null; // Null is an appropriate input
114:
115:                    String response = proxy.echoString(request);
116:                    assertTrue(response == null);
117:                } catch (Exception e) {
118:                    e.printStackTrace();
119:                    fail("Exception received" + e);
120:                }
121:            }
122:
123:            /**
124:             * Testing of StringList (xsd:list of string)
125:             */
126:            public void testEchoStringList() throws Exception {
127:                try {
128:                    GorillaInterface proxy = getProxy();
129:
130:                    // Test sending Hello World
131:                    List<String> request1 = new ArrayList<String>();
132:                    request1.add("Hello");
133:                    request1.add("World");
134:                    List<String> response1 = proxy.echoStringList(request1);
135:                    assertTrue(response1 != null);
136:                    assertTrue(compareLists(request1, response1));
137:
138:                    // Test with empty list
139:                    List<String> request2 = new ArrayList<String>();
140:                    List<String> response2 = proxy.echoStringList(request2);
141:                    assertTrue(response2 != null);
142:                    assertTrue(compareLists(request2, response2));
143:
144:                    // Test with null
145:                    // Note that the response will be an empty array because
146:                    // the JAXB bean will never represent List<String> as a null.  This is expected.
147:                    List<String> request3 = null;
148:                    List<String> response3 = proxy.echoStringList(request3);
149:                    assertTrue(response3 != null && response3.size() == 0);
150:
151:                    // Test sending Hello null World
152:                    // Note that the null is purged by JAXB.  This is expected.
153:                    List<String> request4 = new ArrayList<String>();
154:                    request4.add("Hello");
155:                    request4.add(null);
156:                    request4.add("World");
157:                    List<String> response4 = proxy.echoStringList(request4);
158:                    assertTrue(response4 != null);
159:                    assertTrue(compareLists(request1, response4)); // Response 4 should be the same as Request 1
160:
161:                    // Test sending "Hello World"
162:                    // Note that the Hello World is divided into two items.
163:                    // This is due to the xsd:list serialization. This is expected.
164:                    List<String> request5 = new ArrayList<String>();
165:                    request5.add("Hello World");
166:                    List<String> response5 = proxy.echoStringList(request5);
167:                    assertTrue(response5 != null);
168:                    assertTrue(compareLists(request1, response5)); // Response 5 should be the same as Request 1
169:                } catch (Exception e) {
170:                    e.printStackTrace();
171:                    fail("Exception received" + e);
172:                }
173:            }
174:
175:            /**
176:             * Testing of StringList (xsd:list of string)
177:             * SEI is mapped to String[] instead of List<String>
178:             */
179:            public void testEchoStringListAlt() throws Exception {
180:                try {
181:                    GorillaInterface proxy = getProxy();
182:
183:                    // Test sending Hello World
184:                    String[] request1 = new String[] { "Hello", "World" };
185:                    String[] response1 = proxy.echoStringListAlt(request1);
186:                    assertTrue(response1 != null);
187:                    assertTrue(compareArrays(request1, response1));
188:
189:                    // Test with empty array
190:                    String[] request2 = new String[] {};
191:                    String[] response2 = proxy.echoStringListAlt(request2);
192:                    assertTrue(response2 != null);
193:                    assertTrue(compareArrays(request2, response2));
194:
195:                    // Test with null
196:                    // Note that the response will be an empty array because
197:                    // the JAXB bean will never represent List<String> as a null.  This is expected.
198:                    String[] request3 = null;
199:                    String[] response3 = proxy.echoStringListAlt(request3);
200:                    assertTrue(response3 != null && response3.length == 0);
201:
202:                    // Test sending Hello null World
203:                    // Note that the null is purged by JAXB.  This is expected.
204:                    String[] request4 = new String[] { "Hello", null, "World" };
205:                    String[] response4 = proxy.echoStringListAlt(request4);
206:                    assertTrue(response4 != null);
207:                    assertTrue(compareArrays(request1, response4)); // Response 4 should be the same as Request 1
208:
209:                    // Test sending "Hello World"
210:                    // Note that the Hello World is divided into two items.
211:                    // This is due to the xsd:list serialization. This is expected.
212:                    String[] request5 = new String[] { "Hello World" };
213:                    String[] response5 = proxy.echoStringListAlt(request5);
214:                    assertTrue(response5 != null);
215:                    assertTrue(compareArrays(request1, response5)); // Response 5 should be the same as Request 1
216:                } catch (Exception e) {
217:                    e.printStackTrace();
218:                    fail("Exception received" + e);
219:                }
220:            }
221:
222:            /**
223:             * Test of String Array (string maxOccurs=unbounded)
224:             * @throws Exception
225:             */
226:            public void testEchoIndexedStringArray() throws Exception {
227:                try {
228:                    GorillaInterface proxy = getProxy();
229:
230:                    // Test sending Hello World
231:                    List<String> request1 = new ArrayList<String>();
232:                    request1.add("Hello");
233:                    request1.add("World");
234:                    List<String> response1 = proxy
235:                            .echoIndexedStringArray(request1);
236:                    assertTrue(response1 != null);
237:                    assertTrue(compareLists(request1, response1));
238:
239:                    // Test with empty list
240:                    List<String> request2 = new ArrayList<String>();
241:                    List<String> response2 = proxy
242:                            .echoIndexedStringArray(request2);
243:                    assertTrue(response2 != null);
244:                    assertTrue(compareLists(request2, response2));
245:
246:                    // Test with null
247:                    // Note that the response will be an empty array because
248:                    // the JAXB bean will never represent List<String> as a null.  This is expected.
249:                    List<String> request3 = null;
250:                    List<String> response3 = proxy
251:                            .echoIndexedStringArray(request3);
252:                    assertTrue(response3 != null && response3.size() == 0);
253:
254:                    // Test sending Hello null World
255:                    // Note that the null is preserved and the request and response
256:                    // are the same..note that this is different than the xsd:list processing (see testStringList above)
257:                    // This is expected.
258:                    List<String> request4 = new ArrayList<String>();
259:                    request4.add("Hello");
260:                    request4.add(null);
261:                    request4.add("World");
262:                    List<String> response4 = proxy
263:                            .echoIndexedStringArray(request4);
264:                    assertTrue(response4 != null);
265:                    assertTrue(compareLists(request4, response4)); // Response 4 should be the same as Request 1
266:
267:                    // Test sending "Hello World"
268:                    // Note that the Hello World remains one item.
269:                    List<String> request5 = new ArrayList<String>();
270:                    request5.add("Hello World");
271:                    List<String> response5 = proxy
272:                            .echoIndexedStringArray(request5);
273:                    assertTrue(response5 != null);
274:                    assertTrue(compareLists(request5, response5)); // Response 5 should be the same as Request 1
275:                } catch (Exception e) {
276:                    e.printStackTrace();
277:                    fail("Exception received" + e);
278:                }
279:            }
280:
281:            /**
282:             * Test of String Array (string maxOccurs=unbounded)
283:             * @throws Exception
284:             */
285:            public void testEchoStringArray() throws Exception {
286:                try {
287:                    GorillaInterface proxy = getProxy();
288:
289:                    // Test sending Hello World
290:                    List<String> request1 = new ArrayList<String>();
291:                    request1.add("Hello");
292:                    request1.add("World");
293:                    List<String> response1 = proxy.echoStringArray(request1);
294:                    assertTrue(response1 != null);
295:                    assertTrue(compareLists(request1, response1));
296:
297:                    // Test with empty list
298:                    List<String> request2 = new ArrayList<String>();
299:                    List<String> response2 = proxy.echoStringArray(request2);
300:                    assertTrue(response2 != null);
301:                    assertTrue(compareLists(request2, response2));
302:
303:                    // Test with null
304:                    // Note that the response will be an empty array because
305:                    // the JAXB bean will never represent List<String> as a null.  This is expected.
306:                    List<String> request3 = null;
307:                    List<String> response3 = proxy.echoStringArray(request3);
308:                    assertTrue(response3 != null && response3.size() == 0);
309:
310:                    // Test sending Hello null World
311:                    // Note that the null is preserved and the request and response
312:                    // are the same..note that this is different than the xsd:list processing (see testStringList above)
313:                    // This is expected.
314:                    List<String> request4 = new ArrayList<String>();
315:                    request4.add("Hello");
316:                    request4.add(null);
317:                    request4.add("World");
318:                    List<String> response4 = proxy.echoStringArray(request4);
319:                    assertTrue(response4 != null);
320:                    assertTrue(compareLists(request4, response4)); // Response 4 should be the same as Request 1
321:
322:                    // Test sending "Hello World"
323:                    // Note that the Hello World remains one item.
324:                    List<String> request5 = new ArrayList<String>();
325:                    request5.add("Hello World");
326:                    List<String> response5 = proxy.echoStringArray(request5);
327:                    assertTrue(response5 != null);
328:                    assertTrue(compareLists(request5, response5)); // Response 5 should be the same as Request 1
329:                } catch (Exception e) {
330:                    e.printStackTrace();
331:                    fail("Exception received" + e);
332:                }
333:            }
334:
335:            /**
336:             * Test of String Array (string maxOccurs=unbounded) which is mapped to String[]
337:             * @throws Exception
338:             */
339:            public void testEchoStringArrayAlt() throws Exception {
340:                try {
341:                    GorillaInterface proxy = getProxy();
342:
343:                    // Test sending Hello World
344:                    String[] request1 = new String[] { "Hello", "World" };
345:                    String[] response1 = proxy.echoStringArrayAlt(request1);
346:                    assertTrue(response1 != null);
347:                    assertTrue(compareArrays(request1, response1));
348:
349:                    // Test with empty list
350:                    String[] request2 = new String[] {};
351:                    String[] response2 = proxy.echoStringArrayAlt(request2);
352:                    assertTrue(response2 != null);
353:                    assertTrue(compareArrays(request2, response2));
354:
355:                    // Test with null
356:                    // Note that the response will be an empty array because
357:                    // the JAXB bean will never represent List<String> as a null.  This is expected.
358:                    String[] request3 = null;
359:                    String[] response3 = proxy.echoStringArrayAlt(request3);
360:                    assertTrue(response3 != null && response3.length == 0);
361:
362:                    // Test sending Hello null World
363:                    // Note that the null is preserved and the request and response
364:                    // are the same..note that this is different than the xsd:list processing (see testStringList above)
365:                    // This is expected.
366:                    String[] request4 = new String[] { "Hello", null, "World" };
367:                    String[] response4 = proxy.echoStringArrayAlt(request4);
368:                    assertTrue(response4 != null);
369:                    assertTrue(compareArrays(request4, response4)); // Response 4 should be the same as Request 1
370:
371:                    // Test sending "Hello World"
372:                    // Note that the Hello World remains one item.
373:                    String[] request5 = new String[] { "Hello World" };
374:                    String[] response5 = proxy.echoStringArrayAlt(request5);
375:                    assertTrue(response5 != null);
376:                    assertTrue(compareArrays(request5, response5)); // Response 5 should be the same as Request 1
377:                } catch (Exception e) {
378:                    e.printStackTrace();
379:                    fail("Exception received" + e);
380:                }
381:            }
382:
383:            private boolean compareLists(List in, List out) {
384:                if (in.size() != out.size()) {
385:                    TestLogger.logger.debug("Size mismatch " + in.size() + "!="
386:                            + out.size());
387:                    return false;
388:                }
389:                for (int i = 0; i < in.size(); i++) {
390:                    Object inItem = in.get(i);
391:                    Object outItem = out.get(i);
392:                    if (inItem != null && !inItem.equals(outItem)
393:                            || (inItem == null && inItem != outItem)) {
394:                        TestLogger.logger.debug("Item " + i + " mismatch "
395:                                + inItem + "!=" + outItem);
396:                        return false;
397:                    }
398:
399:                }
400:                return true;
401:            }
402:
403:            private boolean compareArrays(String[] in, String[] out) {
404:                if (in.length != out.length) {
405:                    TestLogger.logger.debug("Size mismatch " + in.length + "!="
406:                            + out.length);
407:                    return false;
408:                }
409:                for (int i = 0; i < in.length; i++) {
410:                    Object inItem = in[i];
411:                    Object outItem = out[i];
412:                    if (inItem != null && !inItem.equals(outItem)
413:                            || (inItem == null && inItem != outItem)) {
414:                        TestLogger.logger.debug("Item " + i + " mismatch "
415:                                + inItem + "!=" + outItem);
416:                        return false;
417:                    }
418:
419:                }
420:                return true;
421:            }
422:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.