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 shop;
059:
060: import java.util.Collection;
061: import java.util.HashMap;
062: import java.util.Iterator;
063:
064: import junit.framework.Test;
065: import junit.framework.TestCase;
066: import junit.framework.TestSuite;
067:
068: import org.apache.wsif.WSIFMessage;
069: import org.apache.wsif.WSIFOperation;
070: import org.apache.wsif.WSIFPort;
071: import org.apache.wsif.WSIFService;
072: import org.apache.wsif.WSIFServiceFactory;
073: import util.TestUtilities;
074:
075: /**
076: * Shopping cart test scenario using Java & EJB invocation.
077: *
078: * In order to run this test, set your JNDI settings using the following variables:
079: * <UL>
080: * <LI>java.naming.provider.url (javax.naming.Context.PROVIDER_URL)</LI>
081: * <LI>java.naming.factory.initial (javax.naming.Context.INITIAL_CONTEXT_FACTORY)</LI>
082: * </UL>
083: *
084: * @author Owen Burroughs
085: */
086:
087: public class ShoppingCartTest extends TestCase {
088:
089: private boolean debugMode = true;
090: //private boolean debugMode = false;
091: private String wsdlPath;
092:
093: /**
094: * Starts the application.
095: * @param args an array of command-line arguments
096: */
097: public static void main(java.lang.String[] args) {
098: TestUtilities.startListeners();
099: junit.textui.TestRunner.run(suite());
100: TestUtilities.stopListeners();
101: }
102:
103: public static Test suite() {
104: return new TestSuite(ShoppingCartTest.class);
105: }
106:
107: public ShoppingCartTest(String arg0) {
108: super (arg0);
109: }
110:
111: protected void setUp() {
112: wsdlPath = TestUtilities.getWsdlPath("java\\test\\shop");
113: }
114:
115: private void printOrder(Order order) {
116: HashMap items = null;
117: Iterator it = null;
118: Collection entries = null;
119: Item item = null;
120: Object obj = null;
121:
122: debug("\nOrder " + order.getConfirmationNumber());
123: items = order.getItems();
124: entries = items.values();
125: it = entries.iterator();
126: while (it.hasNext()) {
127: debug(it.next());
128: }
129: }
130:
131: private void printOrders(Orders orders) {
132: int size = orders.size();
133:
134: for (int i = 0; i < size; i++) {
135: printOrder((Order) orders.get(i));
136: }
137: }
138:
139: /**
140: * Tests the Java binding for the shopping cart scenario via WSDL
141: */
142: public void testWSDL_Java() throws Exception {
143: debug("\n*** TEST JAVA BINDING ***");
144:
145: WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
146: WSIFService service = factory
147: .getService(
148: wsdlPath + "ShoppingCartAll.wsdl",
149: "http://www.shoppingcart.com/definitions/ShoppingCartInterface",
150: // serviceNS,
151: "ShoppingCart_JavaService", // serviceName,
152: "http://www.shoppingcart.com/definitions/ShoppingCartInterface",
153: // portTypeNS,
154: "ShoppingCart_JavaPortType" // portTypeName
155: );
156:
157: Iterator it = service.getAvailablePortNames();
158: {
159: System.out.println("Available ports for the service are: ");
160: while (it.hasNext()) {
161: System.out.println((String) it.next());
162: }
163: }
164:
165: WSIFPort port = service.getPort();
166:
167: WSIFOperation operation;
168: WSIFMessage inputMessage;
169: WSIFMessage outputMessage;
170: WSIFMessage faultMessage;
171:
172: String customerNumber;
173: String tempString;
174: Address address;
175: ShoppingCart_Java shoppingCart;
176: Item item;
177: CreditCardInfo creditCardInfo;
178: AirMilesContainer airMilesContainer;
179: Integer currentTotal = null;
180: Long orderConfirmationNumber;
181: Integer itemQuantity;
182: Object part;
183: boolean operationSucceeded;
184:
185: // -----------------------------------------------------------------------------------------------------
186: operation = port.createOperation("createOperation");
187: inputMessage = operation.createInputMessage();
188: outputMessage = operation.createOutputMessage();
189: faultMessage = operation.createFaultMessage();
190:
191: debug("\n---> Invocation: public ShoppingCart_Java(String firstName, String lastName, Address address, String customerNumber)");
192:
193: tempString = "Albert";
194: inputMessage.setObjectPart("firstName", tempString);
195:
196: tempString = "Einstein";
197: inputMessage.setObjectPart("lastName", tempString);
198:
199: address = new Address("Berlin", "Unter den Linden");
200: inputMessage.setObjectPart("address", address);
201:
202: customerNumber = "AE001";
203: inputMessage.setObjectPart("customerNumber", customerNumber);
204:
205: operationSucceeded = operation.executeRequestResponseOperation(
206: inputMessage, outputMessage, faultMessage);
207:
208: assertTrue("Failed to create a ShoppingCart",
209: operationSucceeded);
210:
211: // -----------------------------------------------------------------------------------------------------
212: operation = port.createOperation("addItemOperation");
213: inputMessage = operation.createInputMessage();
214: outputMessage = operation.createOutputMessage();
215: faultMessage = operation.createFaultMessage();
216:
217: debug("\n---> Invocation: public int addItem(String itemNumber, Item item, String itemName, int itemQuantity)");
218:
219: tempString = "100123";
220: inputMessage.setObjectPart("itemNumber", tempString);
221:
222: item = new Item();
223: //inputMessage.setObjectPart("item", item);
224:
225: tempString = "Pocket calculator";
226: inputMessage.setObjectPart("itemName", tempString);
227:
228: itemQuantity = new Integer(1);
229: inputMessage.setObjectPart("itemQuantity", itemQuantity);
230:
231: operationSucceeded = operation.executeRequestResponseOperation(
232: inputMessage, outputMessage, faultMessage);
233:
234: assertTrue("addItem test failed", operationSucceeded);
235:
236: if (operationSucceeded) {
237: assertTrue("Part is not an Item!!!", outputMessage
238: .getObjectPart("item") instanceof Item);
239: debug(outputMessage.getObjectPart("item"));
240: } else {
241: // Cannot get here since test would have already failed!
242: }
243:
244: // -----------------------------------------------------------------------------------------------------
245: operation = port.createOperation("addItemOperation");
246: inputMessage = operation.createInputMessage();
247: outputMessage = operation.createOutputMessage();
248: faultMessage = operation.createFaultMessage();
249:
250: debug("\n---> Invocation: public int addItem(String itemNumber, Item item, String itemName, int itemQuantity)");
251:
252: tempString = "234123";
253: inputMessage.setObjectPart("itemNumber", tempString);
254:
255: item = new Item();
256: inputMessage.setObjectPart("item", item);
257:
258: tempString = "Pencil";
259: inputMessage.setObjectPart("itemName", tempString);
260:
261: itemQuantity = new Integer(12);
262: inputMessage.setObjectPart("itemQuantity", itemQuantity);
263:
264: operationSucceeded = operation.executeRequestResponseOperation(
265: inputMessage, outputMessage, faultMessage);
266:
267: assertTrue(
268: "addItem succeeded when it should have thrown a outOfStockException",
269: !operationSucceeded);
270:
271: if (operationSucceeded) {
272: debug(outputMessage.getObjectPart("item"));
273: } else {
274: assertNotNull(
275: "outputMessage should have contained outOfStockException",
276: faultMessage.getObjectPart("outOfStockException"));
277:
278: // Extra steps useful for debugging
279: /* part = faultMessage.getObjectPart("invalidItemException");
280: if (part != null) {
281: debug(faultMessage.getName() + ":\n" + part);
282: } else {
283: part = faultMessage.getObjectPart("outOfStockException");
284: if (part != null) {
285: debug(faultMessage.getName() + ":\n" + part);
286: } else {
287: debug("ERROR: Unknown fault message!");
288: }
289: }
290: */
291: }
292:
293: // -----------------------------------------------------------------------------------------------------
294: operation = port.createOperation("addItemOperation");
295: inputMessage = operation.createInputMessage();
296: outputMessage = operation.createOutputMessage();
297: faultMessage = operation.createFaultMessage();
298:
299: debug("\n---> Invocation: public int addItem(String itemNumber, Item item, String itemName, int itemQuantity)");
300:
301: inputMessage.setObjectPart("itemNumber", "234123");
302:
303: item = new Item();
304: inputMessage.setObjectPart("item", item);
305:
306: inputMessage.setObjectPart("itemName", "Pencil");
307:
308: inputMessage.setIntPart("itemQuantity", 8);
309:
310: operationSucceeded = operation.executeRequestResponseOperation(
311: inputMessage, outputMessage, faultMessage);
312:
313: assertTrue("addItem failed when it should have succeeded",
314: operationSucceeded);
315:
316: //Extra steps useful for debugging
317: /* part = faultMessage.getObjectPart("invalidItemException");
318: if (operationSucceeded) {
319: debug(outputMessage.getObjectPart("item"));
320: } else {
321: part = faultMessage.getObjectPart("invalidItemException");
322: if (part != null) {
323: debug(faultMessage.getName() + ":\n" + part);
324: } else {
325: part = faultMessage.getObjectPart("outOfStockException");
326: if (part != null) {
327: debug(faultMessage.getName() + ":\n" + part);
328: } else {
329: debug("ERROR: Unknown fault message!");
330: }
331: }
332: }*/
333:
334: // -----------------------------------------------------------------------------------------------------
335: operation = port.createOperation("submitOrderOperation");
336: inputMessage = operation.createInputMessage();
337: outputMessage = operation.createOutputMessage();
338: faultMessage = operation.createFaultMessage();
339:
340: debug("\n---> Invocation: public long submitOrder(CreditCardInfo creditCardInfo, AirMilesContainer airMilesContainer)");
341:
342: creditCardInfo = new CreditCardInfo();
343: inputMessage.setObjectPart("creditCardInfo", creditCardInfo);
344:
345: airMilesContainer = new AirMilesContainer();
346: inputMessage.setObjectPart("airMilesContainer",
347: airMilesContainer);
348:
349: inputMessage.setLongPart("orderConfirmationNumber", 0);
350:
351: operationSucceeded = operation.executeRequestResponseOperation(
352: inputMessage, outputMessage, faultMessage);
353:
354: assertTrue(
355: "submitOrderOperation failed when it should have succeeded.",
356: operationSucceeded);
357:
358: debug("order confirmation no. = "
359: + outputMessage
360: .getObjectPart("orderConfirmationNumber"));
361: debug(airMilesContainer);
362:
363: // -----------------------------------------------------------------------------------------------------
364: operation = port.createOperation("queryOrdersOperation");
365: inputMessage = operation.createInputMessage();
366: outputMessage = operation.createOutputMessage();
367: faultMessage = operation.createFaultMessage();
368:
369: debug("\n---> Invocation: public static Orders queryOrders(String customerNumber)");
370:
371: inputMessage.setObjectPart("customerNumber", "AE001");
372:
373: operationSucceeded = operation.executeRequestResponseOperation(
374: inputMessage, outputMessage, faultMessage);
375:
376: assertTrue(
377: "queryOrdersOperation failed when it should have succeeded.",
378: operationSucceeded);
379:
380: printOrders((Orders) outputMessage.getObjectPart("orders"));
381:
382: // -----------------------------------------------------------------------------------------------------
383: }
384:
385: /**
386: * Tests the EJB binding for the shopping cart scenario via WSDL
387: */
388: public void testWSDL_EJB() throws Exception {
389: if (!TestUtilities.areWeTesting("ejb"))
390: return;
391:
392: debug("\n*** TEST EJB BINDING ***");
393:
394: WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
395: WSIFService service = factory
396: .getService(
397: wsdlPath + "ShoppingCartAll.wsdl", // WSDL file
398: "http://www.shoppingcart.com/definitions/ShoppingCartInterface", // serviceNS,
399: "ShoppingCart_EJBService", // serviceName,
400: "http://www.shoppingcart.com/definitions/ShoppingCartInterface",
401: // portTypeNS,
402: "ShoppingCart_EJBPortType" // portTypeName
403: );
404:
405: Iterator it = service.getAvailablePortNames();
406: {
407: System.out.println("Available ports for the service are: ");
408: while (it.hasNext()) {
409: System.out.println((String) it.next());
410: }
411: }
412:
413: WSIFPort port = service.getPort();
414: WSIFOperation operation;
415: WSIFMessage inputMessage;
416: WSIFMessage outputMessage;
417: WSIFMessage faultMessage;
418:
419: String customerNumber;
420: String tempString;
421: Address address;
422: ShoppingCart shoppingCart;
423: Item item = null;
424: CreditCardInfo creditCardInfo;
425: AirMilesContainer airMilesContainer;
426: Integer currentTotal = null;
427: Long orderConfirmationNumber;
428: Integer itemQuantity;
429: Object part;
430: boolean operationSucceeded;
431:
432: // -----------------------------------------------------------------------------------------------------
433: operation = port.createOperation("createOperation");
434: inputMessage = operation.createInputMessage();
435: outputMessage = operation.createOutputMessage();
436: faultMessage = operation.createFaultMessage();
437:
438: debug("\n---> Invocation (home): public ShoppingCart create(java.lang.String firstName, java.lang.String lastName, org.apache.wsif.ejb.sample.shop.Address address, java.lang.String customerNumber) throws org.apache.wsif.ejb.sample.shop.CreateException, javax.ejb.CreateException, java.rmi.RemoteException");
439:
440: inputMessage.setObjectPart("firstName", "Albert");
441:
442: inputMessage.setObjectPart("lastName", "Einstein");
443:
444: address = new Address("Berlin", "Unter den Linden");
445: inputMessage.setObjectPart("address", address);
446:
447: inputMessage.setObjectPart("customerNumber", "AE001");
448:
449: operationSucceeded = operation.executeRequestResponseOperation(
450: inputMessage, outputMessage, faultMessage);
451:
452: assertTrue("createOperation failed!!", operationSucceeded);
453:
454: // -----------------------------------------------------------------------------------------------------
455: operation = port.createOperation("addItemOperation");
456: inputMessage = operation.createInputMessage();
457: outputMessage = operation.createOutputMessage();
458: faultMessage = operation.createFaultMessage();
459:
460: debug("\n---> Invocation (remote): public Item addItem(java.lang.String itemNumber, java.lang.String itemName, int itemQuantity) throws org.apache.wsif.ejb.sample.shop.OutOfStockException, java.rmi.RemoteException, org.apache.wsif.ejb.sample.shop.InvalidItemException");
461:
462: inputMessage.setObjectPart("itemNumber", "100123");
463:
464: inputMessage.setObjectPart("itemName", "Pocket calculator");
465:
466: inputMessage.setIntPart("itemQuantity", 1);
467:
468: operationSucceeded = operation.executeRequestResponseOperation(
469: inputMessage, outputMessage, faultMessage);
470:
471: assertTrue("addItemOperation failed!!", operationSucceeded);
472:
473: if (operationSucceeded) {
474: assertTrue(
475: "addItemOperation (EJB) did not return an Item Object!!",
476: outputMessage.getObjectPart("item") instanceof Item);
477: debug(outputMessage.getObjectPart("item"));
478: } else {
479: part = faultMessage.getObjectPart("invalidItemException");
480: if (part != null) {
481: debug(faultMessage.getName() + ":\n" + part);
482: } else {
483: part = faultMessage
484: .getObjectPart("outOfStockException");
485: if (part != null) {
486: debug(faultMessage.getName() + ":\n" + part);
487: } else {
488: debug("ERROR: Unknown fault message!");
489: }
490: }
491: }
492:
493: // -----------------------------------------------------------------------------------------------------
494: operation = port.createOperation("addItemOperation");
495: inputMessage = operation.createInputMessage();
496: outputMessage = operation.createOutputMessage();
497: faultMessage = operation.createFaultMessage();
498:
499: debug("\n---> Invocation (remote): public Item addItem(java.lang.String itemNumber, java.lang.String itemName, int itemQuantity) throws org.apache.wsif.ejb.sample.shop.OutOfStockException, java.rmi.RemoteException, org.apache.wsif.ejb.sample.shop.InvalidItemException");
500:
501: inputMessage.setObjectPart("itemNumber", "234123");
502:
503: inputMessage.setObjectPart("itemName", "Pencil");
504:
505: inputMessage.setIntPart("itemQuantity", 12);
506:
507: operationSucceeded = operation.executeRequestResponseOperation(
508: inputMessage, outputMessage, faultMessage);
509:
510: assertTrue(
511: "addItemOperation succeeded when it should have thrown an outOfStockException",
512: !operationSucceeded);
513:
514: if (operationSucceeded) {
515: assertTrue(
516: "addItemOperation (EJB) did not return an Item Object!!",
517: outputMessage.getObjectPart("item") instanceof Item);
518: debug(outputMessage.getObjectPart("item"));
519: } else {
520: assertNotNull(
521: "outputMessage should have contained outOfStockException",
522: faultMessage.getObjectPart("outOfStockException"));
523:
524: /* part = faultMessage.getObjectPart("invalidItemException");
525: if (part != null) {
526: debug(faultMessage.getName() + ":\n" + part);
527: } else {
528: part = faultMessage.getObjectPart("outOfStockException");
529: if (part != null) {
530: debug(faultMessage.getName() + ":\n" + part);
531: } else {
532: debug("ERROR: Unknown fault message!");
533: }
534: }
535: */
536: }
537:
538: // -----------------------------------------------------------------------------------------------------
539: operation = port.createOperation("addItemOperation");
540: inputMessage = operation.createInputMessage();
541: outputMessage = operation.createOutputMessage();
542: faultMessage = operation.createFaultMessage();
543:
544: debug("\n---> Invocation (remote): public Item addItem(java.lang.String itemNumber, java.lang.String itemName, int itemQuantity) throws org.apache.wsif.ejb.sample.shop.OutOfStockException, java.rmi.RemoteException, org.apache.wsif.ejb.sample.shop.InvalidItemException");
545:
546: inputMessage.setObjectPart("itemNumber", "234123");
547:
548: inputMessage.setObjectPart("itemName", "Pencil");
549:
550: inputMessage.setIntPart("itemQuantity", 8);
551:
552: operationSucceeded = operation.executeRequestResponseOperation(
553: inputMessage, outputMessage, faultMessage);
554:
555: assertTrue("addItemOperation failed!!", operationSucceeded);
556:
557: if (operationSucceeded) {
558: assertTrue(
559: "addItemOperation (EJB) did not return an Item Object!!",
560: outputMessage.getObjectPart("item") instanceof Item);
561: debug(outputMessage.getObjectPart("item"));
562: } else {
563: part = faultMessage.getObjectPart("invalidItemException");
564: if (part != null) {
565: debug(faultMessage.getName() + ":\n" + part);
566: } else {
567: part = faultMessage
568: .getObjectPart("outOfStockException");
569: if (part != null) {
570: debug(faultMessage.getName() + ":\n" + part);
571: } else {
572: debug("ERROR: Unknown fault message!");
573: }
574: }
575: }
576:
577: // -----------------------------------------------------------------------------------------------------
578: operation = port.createOperation("submitOrderOperation");
579: inputMessage = operation.createInputMessage();
580: outputMessage = operation.createOutputMessage();
581: faultMessage = operation.createFaultMessage();
582:
583: debug("\n---> Invocation (remote): public SubmitOrderResult submitOrder(org.apache.wsif.ejb.sample.shop.CreditCardInfo creditCardInfo, org.apache.wsif.ejb.sample.shop.AirMilesContainer airMilesContainer) throws java.rmi.RemoteException");
584:
585: creditCardInfo = new CreditCardInfo();
586: inputMessage.setObjectPart("creditCardInfo", creditCardInfo);
587:
588: airMilesContainer = new AirMilesContainer();
589: inputMessage.setObjectPart("airMilesContainer",
590: airMilesContainer);
591:
592: inputMessage.setLongPart("orderConfirmationNumber", 0);
593:
594: operationSucceeded = operation.executeRequestResponseOperation(
595: inputMessage, outputMessage, faultMessage);
596:
597: assertTrue("submitOrderOperation failed!!", operationSucceeded);
598:
599: debug(outputMessage.getObjectPart("submitOrderResult"));
600:
601: // -----------------------------------------------------------------------------------------------------
602:
603: }
604:
605: /**
606: * Tests input only operations on the Java binding for the shopping cart scenario via WSDL
607: */
608: public void testWSDL_Java_InputOnly() throws Exception {
609: debug("\n*** TEST INPUT ONLY OPERATION USING JAVA BINDING ***");
610:
611: WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
612: WSIFService service = factory
613: .getService(
614: wsdlPath + "ShoppingCartAll.wsdl",
615: "http://www.shoppingcart.com/definitions/ShoppingCartInterface",
616: // serviceNS,
617: "ShoppingCart_JavaService", // serviceName,
618: "http://www.shoppingcart.com/definitions/ShoppingCartInterface",
619: // portTypeNS,
620: "ShoppingCart_JavaPortType" // portTypeName
621: );
622:
623: WSIFPort port = service.getPort();
624:
625: WSIFOperation operation;
626: WSIFMessage inputMessage;
627: WSIFMessage outputMessage;
628: WSIFMessage faultMessage;
629:
630: String customerNumber;
631: String tempString;
632: Address address;
633: ShoppingCart_Java shoppingCart;
634: Item item;
635: CreditCardInfo creditCardInfo;
636: AirMilesContainer airMilesContainer;
637: Integer currentTotal = null;
638: Long orderConfirmationNumber;
639: Integer itemQuantity;
640: Object part;
641: boolean operationSucceeded;
642:
643: // -----------------------------------------------------------------------------------------------------
644: operation = port.createOperation("createOperation");
645: inputMessage = operation.createInputMessage();
646:
647: debug("\n---> Invocation: public ShoppingCart_Java(String firstName, String lastName, Address address, String customerNumber)");
648:
649: inputMessage.setObjectPart("firstName", "Albert");
650:
651: inputMessage.setObjectPart("lastName", "Einstein");
652:
653: address = new Address("Berlin", "Unter den Linden");
654: inputMessage.setObjectPart("address", address);
655:
656: inputMessage.setObjectPart("customerNumber", "AE001");
657:
658: operation.executeInputOnlyOperation(inputMessage);
659:
660: // -----------------------------------------------------------------------------------------------------
661: // First add something to the basket
662: operation = port.createOperation("addItemOperation");
663: inputMessage = operation.createInputMessage();
664: outputMessage = operation.createOutputMessage();
665: faultMessage = operation.createFaultMessage();
666:
667: debug("\n---> Invocation: public int addItem(String itemNumber, Item item, String itemName, int itemQuantity)");
668:
669: inputMessage.setObjectPart("itemNumber", "100123");
670:
671: item = new Item();
672: inputMessage.setObjectPart("item", item);
673:
674: inputMessage.setObjectPart("itemName", "Pocket calculator");
675:
676: inputMessage.setIntPart("itemQuantity", 1);
677:
678: operationSucceeded = operation.executeRequestResponseOperation(
679: inputMessage, outputMessage, faultMessage);
680:
681: assertTrue("addItem test failed", operationSucceeded);
682:
683: if (operationSucceeded) {
684: assertTrue(
685: "addItemOperation (EJB) did not return an Item Object!!",
686: outputMessage.getObjectPart("item") instanceof Item);
687: debug(outputMessage.getObjectPart("item"));
688: debug("Current total = "
689: + outputMessage.getObjectPart("currentTotal"));
690: } else {
691: // Cannot get here since test would have already failed!
692: }
693:
694: // -----------------------------------------------------------------------------------------------------
695: // Test an "Input Only" operation by invoking the emptyBasket method
696: operation = port.createOperation("emptyOrderOperation");
697: inputMessage = operation.createInputMessage();
698:
699: debug("\n---> Invocation: public void emptyOrder(String customerNumber)");
700:
701: inputMessage.setObjectPart("customerNumber", "AE001");
702:
703: operation.executeInputOnlyOperation(inputMessage);
704:
705: // -----------------------------------------------------------------------------------------------------
706: // Add to the basket again - the basket should be empty before this if previous operation worked!!
707: operation = port.createOperation("addItemOperation");
708: inputMessage = operation.createInputMessage();
709: outputMessage = operation.createOutputMessage();
710: faultMessage = operation.createFaultMessage();
711:
712: debug("\n---> Invocation: public int addItem(String itemNumber, Item item, String itemName, int itemQuantity)");
713:
714: inputMessage.setObjectPart("itemNumber", "100123");
715:
716: item = new Item();
717: inputMessage.setObjectPart("item", item);
718:
719: inputMessage.setObjectPart("itemName", "Pocket calculator");
720:
721: inputMessage.setIntPart("itemQuantity", 5);
722:
723: operationSucceeded = operation.executeRequestResponseOperation(
724: inputMessage, outputMessage, faultMessage);
725:
726: assertTrue("addItem test failed", operationSucceeded);
727:
728: if (operationSucceeded) {
729: assertTrue(
730: "addItemOperation (EJB) did not return an Item Object!!",
731: outputMessage.getObjectPart("item") instanceof Item);
732: debug(outputMessage.getObjectPart("item"));
733: debug("Current total = "
734: + outputMessage.getObjectPart("currentTotal"));
735: } else {
736: // Cannot get here since test would have already failed!
737: }
738: }
739:
740: /**
741: * Tests input only operations on the EJB binding for the shopping cart scenario via WSDL
742: */
743: public void testWSDL_EJB_InputOnly() throws Exception {
744: if (!TestUtilities.areWeTesting("ejb"))
745: return;
746:
747: debug("\n*** TEST INPUT ONLY OPERATION USING EJB BINDING ***");
748:
749: WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
750: WSIFService service = factory
751: .getService(
752: wsdlPath + "ShoppingCartAll.wsdl",
753: "http://www.shoppingcart.com/definitions/ShoppingCartInterface",
754: // serviceNS,
755: "ShoppingCart_EJBService", // serviceName,
756: "http://www.shoppingcart.com/definitions/ShoppingCartInterface",
757: // portTypeNS,
758: "ShoppingCart_EJBPortType" // portTypeName
759: );
760:
761: WSIFPort port = service.getPort();
762:
763: WSIFOperation operation;
764: WSIFMessage inputMessage;
765: WSIFMessage outputMessage;
766: WSIFMessage faultMessage;
767:
768: String customerNumber;
769: String tempString;
770: Address address;
771: ShoppingCart shoppingCart;
772: Item item = null;
773: CreditCardInfo creditCardInfo;
774: AirMilesContainer airMilesContainer;
775: Integer currentTotal = null;
776: Long orderConfirmationNumber;
777: Integer itemQuantity;
778: Object part;
779: boolean operationSucceeded;
780:
781: // -----------------------------------------------------------------------------------------------------
782: operation = port.createOperation("createOperation");
783: inputMessage = operation.createInputMessage();
784: outputMessage = operation.createOutputMessage();
785: faultMessage = operation.createFaultMessage();
786:
787: debug("\n---> Invocation (home): public ShoppingCart create(java.lang.String firstName, java.lang.String lastName, org.apache.wsif.ejb.sample.shop.Address address, java.lang.String customerNumber) throws org.apache.wsif.ejb.sample.shop.CreateException, javax.ejb.CreateException, java.rmi.RemoteException");
788:
789: inputMessage.setObjectPart("firstName", "Albert");
790:
791: inputMessage.setObjectPart("lastName", "Einstein");
792:
793: address = new Address("Berlin", "Unter den Linden");
794: inputMessage.setObjectPart("address", address);
795:
796: inputMessage.setObjectPart("customerNumber", "AE001");
797:
798: operationSucceeded = operation.executeRequestResponseOperation(
799: inputMessage, outputMessage, faultMessage);
800:
801: assertTrue("createOperation failed!!", operationSucceeded);
802:
803: // -----------------------------------------------------------------------------------------------------
804: // First add something to the basket
805: operation = port.createOperation("addItemOperation");
806: inputMessage = operation.createInputMessage();
807: outputMessage = operation.createOutputMessage();
808: faultMessage = operation.createFaultMessage();
809:
810: debug("\n---> Invocation (remote): public Item addItem(java.lang.String itemNumber, java.lang.String itemName, int itemQuantity) throws org.apache.wsif.ejb.sample.shop.OutOfStockException, java.rmi.RemoteException, org.apache.wsif.ejb.sample.shop.InvalidItemException");
811:
812: inputMessage.setObjectPart("itemNumber", "100123");
813:
814: inputMessage.setObjectPart("itemName", "Pocket calculator");
815:
816: inputMessage.setIntPart("itemQuantity", 1);
817:
818: operationSucceeded = operation.executeRequestResponseOperation(
819: inputMessage, outputMessage, faultMessage);
820:
821: assertTrue("addItemOperation failed!!", operationSucceeded);
822:
823: if (operationSucceeded) {
824: assertTrue(
825: "addItemOperation (EJB) did not return an Item Object!!",
826: outputMessage.getObjectPart("item") instanceof Item);
827: debug(outputMessage.getObjectPart("item"));
828: } else {
829: part = faultMessage.getObjectPart("invalidItemException");
830: if (part != null) {
831: debug(faultMessage.getName() + ":\n" + part);
832: } else {
833: part = faultMessage
834: .getObjectPart("outOfStockException");
835: if (part != null) {
836: debug(faultMessage.getName() + ":\n" + part);
837: } else {
838: debug("ERROR: Unknown fault message!");
839: }
840: }
841: }
842:
843: // -----------------------------------------------------------------------------------------------------
844: // Test an "Input Only" operation by invoking the emptyBasket method
845: operation = port.createOperation("emptyOrderOperation");
846: inputMessage = operation.createInputMessage();
847:
848: debug("\n---> Invocation: public void emptyOrder(String customerNumber)");
849:
850: inputMessage.setObjectPart("customerNumber", "AE001");
851:
852: operation.executeInputOnlyOperation(inputMessage);
853:
854: // -----------------------------------------------------------------------------------------------------
855: // Add to the basket again - the basket should be empty before this if previous operation worked!!
856: operation = port.createOperation("addItemOperation");
857: inputMessage = operation.createInputMessage();
858: outputMessage = operation.createOutputMessage();
859: faultMessage = operation.createFaultMessage();
860:
861: debug("\n---> Invocation (remote): public Item addItem(java.lang.String itemNumber, java.lang.String itemName, int itemQuantity) throws org.apache.wsif.ejb.sample.shop.OutOfStockException, java.rmi.RemoteException, org.apache.wsif.ejb.sample.shop.InvalidItemException");
862:
863: inputMessage.setObjectPart("itemNumber", "100123");
864:
865: inputMessage.setObjectPart("itemName", "Pocket calculator");
866:
867: inputMessage.setIntPart("itemQuantity", 5);
868:
869: operationSucceeded = operation.executeRequestResponseOperation(
870: inputMessage, outputMessage, faultMessage);
871:
872: assertTrue("addItemOperation failed!!", operationSucceeded);
873:
874: if (operationSucceeded) {
875: assertTrue(
876: "addItemOperation (EJB) did not return an Item Object!!",
877: outputMessage.getObjectPart("item") instanceof Item);
878: debug(outputMessage.getObjectPart("item"));
879: } else {
880: part = faultMessage.getObjectPart("invalidItemException");
881: if (part != null) {
882: debug(faultMessage.getName() + ":\n" + part);
883: } else {
884: part = faultMessage
885: .getObjectPart("outOfStockException");
886: if (part != null) {
887: debug(faultMessage.getName() + ":\n" + part);
888: } else {
889: debug("ERROR: Unknown fault message!");
890: }
891: }
892: }
893: }
894:
895: private void debug(Object s) {
896: if (debugMode)
897: System.out.println(s);
898: }
899:
900: }
|