KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soap > MissingInputPartTest


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package soap;
59
60 import junit.framework.Test;
61 import junit.framework.TestCase;
62 import junit.framework.TestSuite;
63
64 import org.apache.wsif.WSIFMessage;
65 import org.apache.wsif.WSIFOperation;
66 import org.apache.wsif.WSIFPort;
67 import org.apache.wsif.WSIFService;
68 import org.apache.wsif.WSIFServiceFactory;
69 import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
70 import org.apache.wsif.util.WSIFPluggableProviders;
71 import util.TestUtilities;
72
73 import addressbook.wsiftypes.Address;
74 import addressbook.wsiftypes.Phone;
75
76 /**
77  * Junit test to test leaving out a part in the inpuyt message.
78  * Missing parts should default to null.
79  * @author Ant Elder <ant.elder@uk.ibm.com>
80  */

81 public class MissingInputPartTest extends TestCase {
82     String JavaDoc wsdlLocation =
83         TestUtilities.getWsdlPath("java\\test\\addressbook\\wsifservice")
84             + "AddressBook.wsdl";
85     static String JavaDoc server = TestUtilities.getSoapServer().toUpperCase();
86
87     public MissingInputPartTest(String JavaDoc name) {
88         super(name);
89     }
90
91     public static void main(String JavaDoc[] args) {
92         TestUtilities.startListeners(
93             TestUtilities.ADDRESSBOOK_LISTENER
94                 | TestUtilities.NATIVEJMS_LISTENER);
95
96         junit.textui.TestRunner.run (suite());
97         TestUtilities.stopListeners();
98     }
99
100     public static Test suite() {
101         return new TestSuite(MissingInputPartTest.class);
102     }
103
104     public void setUp() {
105         TestUtilities.setUpExtensionsAndProviders();
106     }
107
108     public void testDynamicSOAP() {
109         doitDyn(server+"Port", "soap");
110     }
111     public void testDynamicJava() {
112         doitDyn("JavaPort", "java");
113     }
114     public void testDynamicSoapJms() {
115         doitDyn("SOAPJMSPort", "soap");
116     }
117 // TODO Axis doesn't work as we don't have an axis service
118
// the soap service doesn't understand the axis nil value
119
// public void testDynamicAxis() {
120
// doitDyn(server+"Port", "axis");
121
// }
122
// public void testDynamicAxisJms() {
123
// doitDyn("SOAPJMSPort", "axis");
124
// }
125
public void testDynamicNativeJms() {
126         doitDyn("NativeJmsPort", "" );
127     }
128
129     private void doitDyn(String JavaDoc portName, String JavaDoc protocol) {
130
131         if (portName.toUpperCase().indexOf("JMS") != -1
132         && !TestUtilities.areWeTesting("jms"))
133             return;
134
135         TestUtilities.setProviderForProtocol( protocol );
136
137         try {
138             WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
139                 WSIFService service = factory.getService(wsdlLocation, null, // serviceNS
140
null, // serviceName
141
"http://wsifservice.addressbook/", // portTypeNS
142
"AddressBook"); // portTypeName
143

144             service.mapType(
145                 new javax.xml.namespace.QName JavaDoc(
146                     "http://wsiftypes.addressbook/",
147                     "address"),
148                 Class.forName("addressbook.wsiftypes.Address"));
149
150             service.mapType(
151                 new javax.xml.namespace.QName JavaDoc(
152                     "http://wsiftypes.addressbook/",
153                     "phone"),
154                 Class.forName("addressbook.wsiftypes.Phone"));
155
156             WSIFPort port = null;
157
158             port = service.getPort(portName);
159
160             WSIFOperation operation =
161                 port.createOperation("addEntry", "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 JavaDoc 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 =
176                 operation.executeRequestResponseOperation(
177                     inputMessage,
178                     outputMessage,
179                     faultMessage);
180
181             assertTrue( "Failed to add name and address to addressbook", ok );
182
183             // Start from fresh
184
operation = null;
185             inputMessage = null;
186             outputMessage = null;
187             faultMessage = null;
188
189             operation = port.createOperation("getAddressFromName");
190
191             // Create the messages
192
inputMessage = operation.createInputMessage();
193             outputMessage = operation.createOutputMessage();
194             faultMessage = operation.createFaultMessage();
195
196             // Set the name to find in the addressbook
197
String JavaDoc nameToLookup = "Chris P. Bacon";
198             inputMessage.setObjectPart("name", nameToLookup);
199
200             // Execute the operation
201
ok = operation.executeRequestResponseOperation(
202                     inputMessage,
203                     outputMessage,
204                     faultMessage);
205
206             assertTrue( "Failed to lookup name from addressbook", ok );
207
208             // Should have defaulted to null
209
Address addressFound = (Address) outputMessage.getObjectPart("address");
210             if ( addressFound != null ) {
211                assertTrue( "city not null!!", addressFound.getCity() == null );
212                assertTrue( "PhoneNumber not null!!", addressFound.getPhoneNumber() == null );
213                assertTrue( "State not null!!", addressFound.getState() == null );
214                assertTrue( "StreetName not null!!", addressFound.getStreetName() == null );
215             }
216
217         } catch (Exception JavaDoc ex) {
218             ex.printStackTrace();
219             assertTrue("AddressBookTest(" + portName + ") caught exception " + ex, false);
220         } finally {
221             if (protocol.equals("axis")) {
222                WSIFPluggableProviders.overrideDefaultProvider(
223                     "http://schemas.xmlsoap.org/wsdl/soap/",
224                     null);
225             }
226         }
227     }
228
229 }
230
Free Books   Free Magazines  
Popular Tags