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 faults;
059:
060: import javax.wsdl.Definition;
061: import javax.wsdl.PortType;
062: import javax.wsdl.Service;
063: import junit.framework.Test;
064: import junit.framework.TestCase;
065: import junit.framework.TestSuite;
066:
067: import org.apache.wsif.WSIFConstants;
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 org.apache.wsif.util.WSIFUtils;
074: import util.TestUtilities;
075:
076: /**
077: * Junit test to test out Faults.
078: * Tests faults using the stockquote sample
079: */
080: public class FaultMsgTest extends TestCase {
081: String wsdlLocation = TestUtilities
082: .getWsdlPath("java\\test\\faults")
083: + "Stockquote.wsdl";
084: static String server = TestUtilities.getSoapServer().toUpperCase();
085:
086: public FaultMsgTest(String name) {
087: super (name);
088: }
089:
090: public static void main(String[] args) {
091: TestUtilities.startListeners(TestUtilities.STOCKQUOTE_LISTENER);
092: junit.textui.TestRunner.run(suite());
093: TestUtilities.stopListeners();
094: }
095:
096: public static Test suite() {
097: return new TestSuite(FaultMsgTest.class);
098: }
099:
100: public void setUp() {
101: TestUtilities.setUpExtensionsAndProviders();
102: }
103:
104: //public void testJava () { doit("JavaPort" ,"java"); }
105: public void testAxis() {
106: doit(server + "Port", "axis");
107: }
108:
109: public void testSoap() {
110: doit(server + "Port", "soap");
111: }
112:
113: public void testSoapJms() {
114: if (TestUtilities.areWeTesting("jms"))
115: doit("SOAPJMSPort", "soap");
116: }
117:
118: public void testAxisJms() {
119: if (TestUtilities.areWeTesting("jms"))
120: doit("SOAPJMSPort", "axis");
121: }
122:
123: private void doit(String portName, String protocol) {
124:
125: try {
126: invokeMethod(wsdlLocation, "getQuote", null, null,
127: portName, protocol, new String[] { "" }, 0);
128: } catch (Exception e) {
129: System.err.println("AsyncTest(" + portName
130: + ") caught exception " + e);
131: e.printStackTrace();
132: assertTrue(false);
133: } finally {
134: }
135:
136: }
137:
138: public static void invokeMethod(String wsdlLocation,
139: String operationName, String inputName, String outputName,
140: String portName, String protocol, String[] args,
141: int argShift) throws Exception {
142:
143: String serviceNS = null;
144: String serviceName = null;
145: String portTypeNS = null;
146: String portTypeName = null;
147:
148: TestUtilities.setProviderForProtocol(protocol);
149:
150: try {
151: System.out.println("Reading WSDL document from '"
152: + wsdlLocation + "'");
153: Definition def = WSIFUtils.readWSDL(null, wsdlLocation);
154:
155: Service service = WSIFUtils.selectService(def, serviceNS,
156: serviceName);
157: PortType portType = WSIFUtils.selectPortType(def,
158: portTypeNS, portTypeName);
159:
160: WSIFServiceFactory factory = WSIFServiceFactory
161: .newInstance();
162: WSIFService dpf = factory
163: .getService(def, service, portType);
164: WSIFPort port = (portName == null) ? dpf.getPort() : dpf
165: .getPort(portName);
166:
167: // 1st a call that should work
168: WSIFOperation op1 = port.createOperation("getQuote",
169: inputName, outputName);
170: WSIFMessage input1 = op1.createInputMessage();
171: WSIFMessage output1 = op1.createOutputMessage();
172: WSIFMessage fault1 = op1.createFaultMessage();
173: input1.setObjectPart("symbol", "");
174: boolean ok = op1.executeRequestResponseOperation(input1,
175: output1, fault1);
176:
177: assertEquals("ok getQuote response", true, ok);
178: float q1 = ((Float) output1.getObjectPart("quote"))
179: .floatValue();
180: assertEquals("getQuote value", -1.0F, q1, 0F);
181:
182: // now a call that is defined in WSDL but not on server
183: op1 = port.createOperation("XXXgetQuote", inputName,
184: outputName);
185: input1 = op1.createInputMessage();
186: output1 = op1.createOutputMessage();
187: fault1 = op1.createFaultMessage();
188: input1.setObjectPart("symbol", "");
189: ok = op1.executeRequestResponseOperation(input1, output1,
190: fault1);
191:
192: assertEquals("ok getQuote response", false, ok);
193: String name = fault1.getName();
194: Object fobject = fault1
195: .getObjectPart(WSIFConstants.SOAP_FAULT_OBJECT);
196:
197: assertEquals("fault message name",
198: WSIFConstants.SOAP_FAULT_MSG_NAME, name);
199: if ("axis".equals(protocol)) {
200: assertTrue("fault obj type",
201: fobject instanceof org.apache.axis.AxisFault);
202: //System.out.println( "AxisFault=" + fobject );
203: } else {
204: assertTrue("fault obj type",
205: fobject instanceof org.apache.soap.Fault);
206: //System.out.println( "SOAPFault=" + fobject );
207: }
208:
209: // now a call where the remote service returns a fault;
210: // doesn't seem any diff?
211:
212: } catch (Exception ex) {
213: ex.printStackTrace();
214: assertTrue(false);
215: } finally {
216: TestUtilities.resetDefaultProviders();
217: }
218:
219: }
220: }
|