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 soap;
059:
060: import junit.framework.Test;
061: import junit.framework.TestCase;
062: import junit.framework.TestSuite;
063:
064: import org.apache.wsif.WSIFMessage;
065: import org.apache.wsif.WSIFOperation;
066: import org.apache.wsif.WSIFPort;
067: import org.apache.wsif.WSIFService;
068: import org.apache.wsif.WSIFServiceFactory;
069: import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
070: import org.apache.wsif.util.WSIFPluggableProviders;
071: import util.TestUtilities;
072:
073: import addressbook.wsiftypes.Address;
074: import addressbook.wsiftypes.Phone;
075:
076: /**
077: * Junit test to test leaving out a part in the inpuyt message.
078: * Missing parts should default to null.
079: * @author Ant Elder <ant.elder@uk.ibm.com>
080: */
081: public class MissingInputPartTest extends TestCase {
082: String wsdlLocation = TestUtilities
083: .getWsdlPath("java\\test\\addressbook\\wsifservice")
084: + "AddressBook.wsdl";
085: static String server = TestUtilities.getSoapServer().toUpperCase();
086:
087: public MissingInputPartTest(String name) {
088: super (name);
089: }
090:
091: public static void main(String[] args) {
092: TestUtilities.startListeners(TestUtilities.ADDRESSBOOK_LISTENER
093: | TestUtilities.NATIVEJMS_LISTENER);
094:
095: junit.textui.TestRunner.run(suite());
096: TestUtilities.stopListeners();
097: }
098:
099: public static Test suite() {
100: return new TestSuite(MissingInputPartTest.class);
101: }
102:
103: public void setUp() {
104: TestUtilities.setUpExtensionsAndProviders();
105: }
106:
107: public void testDynamicSOAP() {
108: doitDyn(server + "Port", "soap");
109: }
110:
111: public void testDynamicJava() {
112: doitDyn("JavaPort", "java");
113: }
114:
115: public void testDynamicSoapJms() {
116: doitDyn("SOAPJMSPort", "soap");
117: }
118:
119: // TODO Axis doesn't work as we don't have an axis service
120: // the soap service doesn't understand the axis nil value
121: // public void testDynamicAxis() {
122: // doitDyn(server+"Port", "axis");
123: // }
124: // public void testDynamicAxisJms() {
125: // doitDyn("SOAPJMSPort", "axis");
126: // }
127: public void testDynamicNativeJms() {
128: doitDyn("NativeJmsPort", "");
129: }
130:
131: private void doitDyn(String portName, String protocol) {
132:
133: if (portName.toUpperCase().indexOf("JMS") != -1
134: && !TestUtilities.areWeTesting("jms"))
135: return;
136:
137: TestUtilities.setProviderForProtocol(protocol);
138:
139: try {
140: WSIFServiceFactory factory = WSIFServiceFactory
141: .newInstance();
142: WSIFService service = factory.getService(wsdlLocation,
143: null, // serviceNS
144: null, // serviceName
145: "http://wsifservice.addressbook/", // portTypeNS
146: "AddressBook"); // portTypeName
147:
148: service.mapType(new javax.xml.namespace.QName(
149: "http://wsiftypes.addressbook/", "address"), Class
150: .forName("addressbook.wsiftypes.Address"));
151:
152: service.mapType(new javax.xml.namespace.QName(
153: "http://wsiftypes.addressbook/", "phone"), Class
154: .forName("addressbook.wsiftypes.Phone"));
155:
156: WSIFPort port = null;
157:
158: port = service.getPort(portName);
159:
160: WSIFOperation operation = port.createOperation("addEntry",
161: "AddEntryWholeNameRequest", null);
162:
163: WSIFMessage inputMessage = operation.createInputMessage();
164: WSIFMessage outputMessage = operation.createOutputMessage();
165: WSIFMessage faultMessage = operation.createFaultMessage();
166:
167: // Create a name and address to add to the addressbook
168: String nameToAdd = "Chris P. Bacon";
169:
170: // Add the name and leave out address to the input message
171: inputMessage.setObjectPart("name", nameToAdd);
172: //inputMessage.setObjectPart("address", null); // should default to null
173:
174: // Execute the operation, obtaining a flag to indicate its success
175: boolean ok = operation.executeRequestResponseOperation(
176: inputMessage, outputMessage, faultMessage);
177:
178: assertTrue("Failed to add name and address to addressbook",
179: ok);
180:
181: // Start from fresh
182: operation = null;
183: inputMessage = null;
184: outputMessage = null;
185: faultMessage = null;
186:
187: operation = port.createOperation("getAddressFromName");
188:
189: // Create the messages
190: inputMessage = operation.createInputMessage();
191: outputMessage = operation.createOutputMessage();
192: faultMessage = operation.createFaultMessage();
193:
194: // Set the name to find in the addressbook
195: String nameToLookup = "Chris P. Bacon";
196: inputMessage.setObjectPart("name", nameToLookup);
197:
198: // Execute the operation
199: ok = operation.executeRequestResponseOperation(
200: inputMessage, outputMessage, faultMessage);
201:
202: assertTrue("Failed to lookup name from addressbook", ok);
203:
204: // Should have defaulted to null
205: Address addressFound = (Address) outputMessage
206: .getObjectPart("address");
207: if (addressFound != null) {
208: assertTrue("city not null!!",
209: addressFound.getCity() == null);
210: assertTrue("PhoneNumber not null!!", addressFound
211: .getPhoneNumber() == null);
212: assertTrue("State not null!!",
213: addressFound.getState() == null);
214: assertTrue("StreetName not null!!", addressFound
215: .getStreetName() == null);
216: }
217:
218: } catch (Exception ex) {
219: ex.printStackTrace();
220: assertTrue("AddressBookTest(" + portName
221: + ") caught exception " + ex, false);
222: } finally {
223: if (protocol.equals("axis")) {
224: WSIFPluggableProviders.overrideDefaultProvider(
225: "http://schemas.xmlsoap.org/wsdl/soap/", null);
226: }
227: }
228: }
229:
230: }
|