Source Code Cross Referenced for InoutTest.java in  » Web-Services » wsif » inout » 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 » wsif » inout 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Apache Software License, Version 1.1
003:         *
004:         *
005:         * Copyright (c) 2002 The Apache Software Foundation.  All rights 
006:         * reserved.
007:         *
008:         * Redistribution and use in source and binary forms, with or without
009:         * modification, are permitted provided that the following conditions
010:         * are met:
011:         *
012:         * 1. Redistributions of source code must retain the above copyright
013:         *    notice, this list of conditions and the following disclaimer. 
014:         *
015:         * 2. Redistributions in binary form must reproduce the above copyright
016:         *    notice, this list of conditions and the following disclaimer in
017:         *    the documentation and/or other materials provided with the
018:         *    distribution.
019:         *
020:         * 3. The end-user documentation included with the redistribution,
021:         *    if any, must include the following acknowledgment:  
022:         *       "This product includes software developed by the
023:         *        Apache Software Foundation (http://www.apache.org/)."
024:         *    Alternately, this acknowledgment may appear in the software itself,
025:         *    if and wherever such third-party acknowledgments normally appear.
026:         *
027:         * 4. The names "WSIF" and "Apache Software Foundation" must
028:         *    not be used to endorse or promote products derived from this
029:         *    software without prior written permission. For written 
030:         *    permission, please contact apache@apache.org.
031:         *
032:         * 5. Products derived from this software may not be called "Apache",
033:         *    nor may "Apache" appear in their name, without prior written
034:         *    permission of the Apache Software Foundation.
035:         *
036:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047:         * SUCH DAMAGE.
048:         * ====================================================================
049:         *
050:         * This software consists of voluntary contributions made by many
051:         * individuals on behalf of the Apache Software Foundation and was
052:         * originally based on software copyright (c) 2001, 2002, International
053:         * Business Machines, Inc., http://www.apache.org.  For more
054:         * information on the Apache Software Foundation, please see
055:         * <http://www.apache.org/>.
056:         */
057:
058:        package inout;
059:
060:        import java.text.DateFormat;
061:        import java.util.Date;
062:
063:        import javax.xml.namespace.QName;
064:
065:        import junit.framework.Test;
066:        import junit.framework.TestCase;
067:        import junit.framework.TestSuite;
068:        import junit.textui.TestRunner;
069:        import org.apache.wsif.WSIFException;
070:        import org.apache.wsif.WSIFService;
071:        import org.apache.wsif.WSIFServiceFactory;
072:        import org.apache.wsif.base.WSIFServiceImpl;
073:        import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
074:        import org.apache.wsif.providers.soap.apachesoap.WSIFDynamicProvider_ApacheSOAP;
075:        import org.apache.wsif.util.WSIFPluggableProviders;
076:
077:        import addressbook.wsiftypes.Address;
078:        import addressbook.wsiftypes.Phone;
079:        import inout.wsifservice.Inout;
080:        import inout.wsiftypes.Mutablestring;
081:        import util.AddressUtility;
082:        import util.TestUtilities;
083:
084:        /**
085:         * Junit test to test out the Inout test
086:         * @author Mark Whitlock
087:         */
088:        public class InoutTest extends TestCase {
089:            String wsdlLocation = TestUtilities
090:                    .getWsdlPath("java\\test\\inout\\wsifservice")
091:                    + "Inout.wsdl";
092:            static String server = TestUtilities.getSoapServer().toUpperCase();
093:
094:            static String name1 = "Purdue Boilermaker";
095:            static Address addr1 = new Address(1, "University Drive",
096:                    "West Lafayette", "IN", 47907,
097:                    new Phone(765, "494", "4900"));
098:
099:            static String firstName2 = "Someone";
100:            static String lastName2 = "Else";
101:            static String name2 = "Someone Else";
102:            static Address addr2 = new Address(0, "Somewhere Else", "No Where",
103:                    "NO", 71983, new Phone(600, "391", "5682"));
104:
105:            static Address nulladdr = new Address(0, "", "", "", 0, new Phone(
106:                    0, "", ""));
107:
108:            private final static String ADDRESS = "address";
109:            private final static String NULLNAME = "nullname";
110:            private final static String ADD = "add";
111:            private final static String DATE = "date";
112:            private final static String SUPC = "supc";
113:            private final static String GENC = "genericc";
114:            private final static String WHOAMI = "whoami";
115:            private final static String INOUT = "inout";
116:
117:            private final static String RPC = "rpc";
118:            private final static String DOC = "doc";
119:
120:            private final static String SOAP = "soap";
121:            private final static String AXIS = "axis";
122:            private final static String JAVA = "java";
123:            private final static String NJMS = "nativeJMS";
124:
125:            public InoutTest(String name) {
126:                super (name);
127:            }
128:
129:            public static void main(String[] args) {
130:                TestUtilities.startListeners();
131:                junit.textui.TestRunner.run(suite());
132:                TestUtilities.stopListeners();
133:            }
134:
135:            public static Test suite() {
136:                return new TestSuite(InoutTest.class);
137:            }
138:
139:            public void setUp() {
140:                TestUtilities.setUpExtensionsAndProviders();
141:            }
142:
143:            public void testAxis() {
144:                doit(server + "Port", AXIS, RPC, ADDRESS);
145:            }
146:
147:            public void testSoap() {
148:                doit(server + "Port", SOAP, RPC, ADDRESS);
149:            }
150:
151:            public void testJava() {
152:                doit("JavaPort", JAVA, RPC, ADDRESS);
153:            }
154:
155:            public void testSoapJms() {
156:                doit("SOAPJMSPort", SOAP, RPC, ADDRESS);
157:            }
158:
159:            public void testAxisJms() {
160:                doit("SOAPJMSPort", AXIS, RPC, ADDRESS);
161:            }
162:
163:            public void testNativeJms() {
164:                doit("NativeJMSPort", NJMS, RPC, ADDRESS);
165:            }
166:
167:            //public void testAxisDoc       () { doit("SOAPDocPort"   ,AXIS,DOC, ADDRESS ); } FAILS
168:            //public void testSoapDoc       () { doit("SOAPDocPort"   ,SOAP,DOC, ADDRESS ); } FAILS
169:            //public void testSoapJmsDoc    () { doit("SOAPJMSDocPort",SOAP,DOC, ADDRESS ); } FAILS
170:            //public void testAxisJmsDoc    () { doit("SOAPJMSDocPort",AXIS,DOC, ADDRESS ); } FAILS
171:            //public void testNativeJmsDoc  () { doit("NativeJMSPort" ,NJMS,DOC, ADDRESS ); } FAILS
172:
173:            //public void testNNAxis        () { doit(server+"Port"      ,AXIS,RPC, NULLNAME); } FAILS
174:            //public void testNNSoap        () { doit(server+"Port"      ,SOAP,RPC, NULLNAME); } FAILS
175:            public void testNNJava() {
176:                doit("JavaPort", JAVA, RPC, NULLNAME);
177:            }
178:
179:            //public void testNNSoapJms     () { doit("SOAPJMSPort"   ,SOAP,RPC, NULLNAME); } FAILS
180:            //public void testNNAxisJms     () { doit("SOAPJMSPort"   ,AXIS,RPC, NULLNAME); } FAILS
181:            //public void testNNNativeJms   () { doit("NativeJMSPort" ,NJMS,RPC, NULLNAME); } 
182:
183:            //public void testAddAxis       () { doit(server+"Port"      ,AXIS,RPC, ADD     ); } FAILS
184:            public void testAddSoap() {
185:                doit(server + "Port", SOAP, RPC, ADD);
186:            }
187:
188:            public void testAddJava() {
189:                doit("JavaPort", JAVA, RPC, ADD);
190:            }
191:
192:            public void testAddSoapJms() {
193:                doit("SOAPJMSPort", SOAP, RPC, ADD);
194:            }
195:
196:            //public void testAddAxisJms    () { doit("SOAPJMSPort"   ,AXIS,RPC, ADD     ); } FAILS
197:            public void testAddNativeJms() {
198:                doit("NativeJMSPort", NJMS, RPC, ADD);
199:            }
200:
201:            //public void testDateAxis      () { doit(server+"Port"      ,AXIS,RPC, DATE    ); } FAILS
202:            public void testDateSoap() {
203:                doit(server + "Port", SOAP, RPC, DATE);
204:            }
205:
206:            public void testDateJava() {
207:                doit("JavaPort", JAVA, RPC, DATE);
208:            }
209:
210:            public void testDateSoapJms() {
211:                doit("SOAPJMSPort", SOAP, RPC, DATE);
212:            }
213:
214:            //public void testDateAxisJms   () { doit("SOAPJMSPort"   ,AXIS,RPC, DATE    ); } FAILS
215:            public void testDateNativeJms() {
216:                doit("NativeJMSPort", NJMS, RPC, DATE);
217:            }
218:
219:            public void testSupCAxis() {
220:                doit(server + "Port", AXIS, RPC, SUPC);
221:            }
222:
223:            public void testSupCSoap() {
224:                doit(server + "Port", SOAP, RPC, SUPC);
225:            }
226:
227:            public void testSupCJava() {
228:                doit("JavaPort", JAVA, RPC, SUPC);
229:            }
230:
231:            public void testSupCSoapJms() {
232:                doit("SOAPJMSPort", SOAP, RPC, SUPC);
233:            }
234:
235:            public void testSupCAxisJms() {
236:                doit("SOAPJMSPort", AXIS, RPC, SUPC);
237:            }
238:
239:            public void testSupCNativeJms() {
240:                doit("NativeJMSPort", NJMS, RPC, SUPC);
241:            }
242:
243:            public void testGenCAxis() {
244:                doit(server + "Port", AXIS, RPC, GENC);
245:            }
246:
247:            public void testGenCSoap() {
248:                doit(server + "Port", SOAP, RPC, GENC);
249:            }
250:
251:            public void testGenCJava() {
252:                doit("JavaPort", JAVA, RPC, GENC);
253:            }
254:
255:            public void testGenCSoapJms() {
256:                doit("SOAPJMSPort", SOAP, RPC, GENC);
257:            }
258:
259:            public void testGenCAxisJms() {
260:                doit("SOAPJMSPort", AXIS, RPC, GENC);
261:            }
262:
263:            public void testGenCNativeJms() {
264:                doit("NativeJMSPort", NJMS, RPC, GENC);
265:            }
266:
267:            //public void testWhoAxis       () { doit(server+"Port"      ,AXIS,RPC, WHOAMI  ); } FAILS
268:            public void testWhoSoap() {
269:                doit(server + "Port", SOAP, RPC, WHOAMI);
270:            }
271:
272:            public void testWhoJava() {
273:                doit("JavaPort", JAVA, RPC, WHOAMI);
274:            }
275:
276:            public void testWhoSoapJms() {
277:                doit("SOAPJMSPort", SOAP, RPC, WHOAMI);
278:            }
279:
280:            //public void testWhoAxisJms    () { doit("SOAPJMSPort"   ,AXIS,RPC, WHOAMI  ); } FAILS
281:            public void testWhoNativeJms() {
282:                doit("NativeJMSPort", NJMS, RPC, WHOAMI);
283:            }
284:
285:            // The inout test will never work for any form of soap since soap does not
286:            // support inout or multiple output parameters.
287:            public void testInoJava() {
288:                doit("JavaPort", JAVA, RPC, INOUT);
289:            }
290:
291:            private void doit(String portName, String protocol, String style,
292:                    String cmd) {
293:                if (portName.toUpperCase().indexOf("JMS") != -1
294:                        && !TestUtilities.areWeTesting("jms"))
295:                    return;
296:
297:                if (protocol.equals(SOAP)) {
298:                    WSIFDynamicProvider_ApacheSOAP provider = new WSIFDynamicProvider_ApacheSOAP();
299:
300:                    if (style.equals(DOC))
301:                        provider
302:                                .setPartSerializerName("services.inout.InoutLiteralSerializer");
303:
304:                    WSIFPluggableProviders.overrideDefaultProvider(
305:                            "http://schemas.xmlsoap.org/wsdl/soap/", provider);
306:                }
307:                if (protocol.equals(AXIS)) {
308:                    WSIFDynamicProvider_ApacheAxis provider = new WSIFDynamicProvider_ApacheAxis();
309:
310:                    WSIFPluggableProviders.overrideDefaultProvider(
311:                            "http://schemas.xmlsoap.org/wsdl/soap/", provider);
312:                }
313:
314:                try {
315:                    WSIFServiceFactory factory = WSIFServiceFactory
316:                            .newInstance();
317:                    WSIFService service = factory.getService(wsdlLocation,
318:                            null, null, "http://wsifservice.inout/", "Inout");
319:
320:                    service.mapType(new QName("http://wsiftypes.inout/",
321:                            "arrayofint"), Class.forName("[I"));
322:
323:                    Inout stub = (Inout) service.getStub(portName, Inout.class);
324:
325:                    if (cmd.equals(ADDRESS))
326:                        address(stub);
327:                    else if (cmd.equals(NULLNAME))
328:                        nullname(stub);
329:                    else if (cmd.equals(ADD))
330:                        add(stub);
331:                    else if (cmd.equals(DATE))
332:                        date(stub);
333:                    else if (cmd.equals(SUPC))
334:                        supc(service, portName);
335:                    else if (cmd.equals(GENC))
336:                        genericc(service, portName);
337:                    else if (cmd.equals(WHOAMI))
338:                        whoami(stub);
339:                    else if (cmd.equals(INOUT))
340:                        inout(stub);
341:                    else
342:                        assertTrue(false);
343:                } catch (Exception e) {
344:                    System.err.println("InoutTest(" + portName
345:                            + ") caught exception " + e);
346:                    e.printStackTrace();
347:                    assertTrue(false);
348:                } finally {
349:                    if (protocol.equals(SOAP) || protocol.equals(AXIS)) {
350:                        WSIFPluggableProviders.overrideDefaultProvider(
351:                                "http://schemas.xmlsoap.org/wsdl/soap/", null);
352:                    }
353:                }
354:
355:            }
356:
357:            private void address(Inout stub) throws Exception {
358:                stub.addEntry(name1.toString(), addr1);
359:
360:                Mutablestring msName1 = new Mutablestring(name1);
361:                Address resp1 = stub.getAddressFromName(msName1);
362:                assertTrue(new AddressUtility(resp1).equals(addr1));
363:
364:                Mutablestring msName = new Mutablestring("Pur*");
365:                resp1 = stub.getAddressFromName(msName);
366:                assertTrue(new AddressUtility(resp1).equals(addr1));
367:            }
368:
369:            private void nullname(Inout stub) throws Exception {
370:                stub.addEntry(null, null);
371:
372:                Address resp1 = stub.getAddressFromName((String) null);
373:                assertTrue(resp1 == null);
374:
375:                Address resp2 = stub.getAddressFromName((Mutablestring) null);
376:                assertTrue(resp2 == null);
377:
378:                // This next bit of code works with soap2.2 but not Axis. I've
379:                // commented it out because getAddressFromName((String)null) doesn't
380:                // work with either so I can't run this test with soap or axis.
381:                //Address nullAddr = new Address(0,"","","",0,new Phone(0,null,null));
382:                //Address resp = stub.getAddressFromName (new Mutablestring(null));
383:                //assertTrue(resp==null || TestUtilities.AddressEquals(resp,nullAddr));
384:            }
385:
386:            private void add(Inout stub) throws Exception {
387:                int[] nums = new int[] { 1, 2, 3, 4, 5 };
388:                int total = stub.addNumbers(nums);
389:
390:                String warmFuzzy = new String();
391:                int expected = 0;
392:                for (int i = 0; i < nums.length; i++) {
393:                    expected += nums[i];
394:                    if (i != 0)
395:                        warmFuzzy += "+ ";
396:                    warmFuzzy += nums[i] + " ";
397:                }
398:                warmFuzzy += "= " + total + " (expected " + expected + ")";
399:                System.out.println(warmFuzzy);
400:                assertTrue(total == expected);
401:            }
402:
403:            private void date(Inout stub) throws Exception {
404:                Date first = new Date();
405:                Thread.sleep(1000);
406:                Date remote = stub.getDate();
407:                Thread.sleep(1000);
408:                Date later = new Date();
409:
410:                DateFormat df = DateFormat.getDateTimeInstance();
411:                System.out.println("Remote date is " + df.format(remote)
412:                        + " First date is " + df.format(first)
413:                        + " Later date is " + df.format(later));
414:
415:                assertTrue(first.before(remote) || first.equals(remote));
416:                assertTrue(later.after(remote) || later.equals(remote));
417:            }
418:
419:            private interface SubInout extends Inout {
420:                public void dubiousMethod() throws WSIFException;
421:            }
422:
423:            private void supc(WSIFService service, String portName)
424:                    throws Exception {
425:                SubInout stub = (SubInout) service.getStub(portName,
426:                        SubInout.class);
427:
428:                stub.addEntry(name1, addr1);
429:                Mutablestring msName1 = new Mutablestring(name1);
430:                Address resp1 = stub.getAddressFromName(msName1);
431:                assertTrue(new AddressUtility(addr1).equals(resp1));
432:
433:                boolean caught = false;
434:                try {
435:                    stub.dubiousMethod();
436:                } catch (WSIFException e) {
437:                    caught = true;
438:                }
439:                assertTrue(caught);
440:
441:                stub.addEntry(name2, new SubAddress(addr2));
442:                Mutablestring msName2 = new Mutablestring(name2);
443:                Address resp2 = stub.getAddressFromName(msName2);
444:                assertTrue(new AddressUtility(addr2).equals(resp2));
445:            }
446:
447:            private interface GenericInout {
448:                public void addEntry(String wholeName, Object address)
449:                        throws java.rmi.RemoteException;
450:
451:                public Address getAddressFromName(Mutablestring name)
452:                        throws java.rmi.RemoteException;
453:            }
454:
455:            private void genericc(WSIFService service, String portName)
456:                    throws Exception {
457:                GenericInout stub = (GenericInout) service.getStub(portName,
458:                        GenericInout.class);
459:
460:                stub.addEntry(name1, addr1);
461:                Mutablestring msName1 = new Mutablestring(name1);
462:                Address resp1 = stub.getAddressFromName(msName1);
463:                assertTrue(new AddressUtility(addr1).equals(resp1));
464:            }
465:
466:            /**
467:             * whoami tests out dynamic proxies by overloading is various
468:             * ways.
469:             */
470:            private void whoami(Inout stub) throws Exception {
471:                float f = 1;
472:                int i = 1;
473:                Address a = new Address();
474:                SubAddress suba = new SubAddress();
475:                String resp;
476:
477:                resp = stub.whoami("Hello");
478:                System.out.println("resp was " + resp + " expected String");
479:                assertTrue("String".equals(resp));
480:
481:                resp = stub.whoami(f);
482:                System.out.println("resp was " + resp + " expected float");
483:                assertTrue("float".equals(resp));
484:
485:                resp = stub.whoami(i);
486:                System.out.println("resp was " + resp + " expected int");
487:                assertTrue("int".equals(resp));
488:
489:                resp = stub.whoami(a);
490:                System.out.println("resp was " + resp + " expected Address");
491:                assertTrue("Address".equals(resp));
492:
493:                resp = stub.whoami(suba);
494:                System.out.println("resp was " + resp + " expected Address");
495:                assertTrue("Address".equals(resp));
496:            }
497:
498:            private void inout(Inout stub) throws Exception {
499:                stub.addEntry(name1.toString(), addr1);
500:
501:                Mutablestring msName1 = new Mutablestring(name1);
502:                Address resp1 = new AddressUtility(nulladdr).copy();
503:                boolean success = stub.getAddressFromName(msName1, resp1);
504:                assertTrue(success && new AddressUtility(resp1).equals(addr1));
505:            }
506:
507:        }
508:
509:        class SubAddress extends Address {
510:
511:            public SubAddress() {
512:                super ();
513:            }
514:
515:            public SubAddress(Address a) {
516:                super(a.getStreetNum(), a.getStreetName(), a.getCity(), a
517:                        .getState(), a.getZip(), a.getPhoneNumber());
518:            }
519:
520:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.