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 jms;
059:
060: import java.util.Iterator;
061:
062: import junit.framework.Test;
063: import junit.framework.TestCase;
064: import junit.framework.TestSuite;
065:
066: import org.apache.wsif.WSIFConstants;
067: import org.apache.wsif.WSIFCorrelationId;
068: import org.apache.wsif.WSIFException;
069: import org.apache.wsif.WSIFMessage;
070: import org.apache.wsif.WSIFOperation;
071: import org.apache.wsif.WSIFPort;
072: import org.apache.wsif.WSIFService;
073: import org.apache.wsif.WSIFServiceFactory;
074: import util.TestUtilities;
075:
076: /**
077: * Junit test to do various JMS tests
078: * @author Mark Whitlock
079: */
080: public class JmsFaultTest extends TestCase {
081: String wsdlLocation = TestUtilities.getWsdlPath("java\\test\\jms")
082: + "jmsfault.wsdl";
083:
084: private static final boolean SYNC = true;
085: private static final boolean ASYNC = false;
086:
087: public JmsFaultTest(String name) {
088: super (name);
089: }
090:
091: public static void main(String[] args) {
092: TestUtilities.startListeners(TestUtilities.NATIVEJMS_LISTENER);
093: junit.textui.TestRunner.run(suite());
094: TestUtilities.stopListeners();
095: }
096:
097: public static Test suite() {
098: return new TestSuite(JmsFaultTest.class);
099: }
100:
101: public void setUp() {
102: TestUtilities.setUpExtensionsAndProviders();
103: }
104:
105: public void testNoFaultSync() {
106: doit("throwSimple", 0, false, false, null, null, SYNC);
107: }
108:
109: public void testSimpleSync() {
110: doit("throwSimple", 1, true, false,
111: new String[] { "faultText" },
112: new Object[] { "A Simple Fault" }, SYNC);
113: }
114:
115: public void testIntsSync() {
116: doit("throwSimple", 2, true, false, new String[] { "faultInt1",
117: "faultInt2", "faultInt3" }, new Object[] {
118: new Integer(1), new Integer(2), new Integer(3) }, SYNC);
119: }
120:
121: public void testTwoIntsSync() {
122: doit("throwSimple", 3, true, false, new String[] { "faultInt1",
123: "faultInt2" }, new Object[] { new Integer(1),
124: new Integer(2) }, SYNC);
125: }
126:
127: public void testEmptyJmsFaultSync() {
128: doit("throwSimple", 2, true, false, new String[] { "faultInt1",
129: "faultInt2", "faultInt3" }, new Object[] {
130: new Integer(1), new Integer(2), new Integer(3) }, SYNC);
131: }
132:
133: public void testIndicIntSync() {
134: doit("throwIndicInt", 4, true, false,
135: new String[] { "faultText" },
136: new Object[] { "A Simple Fault" }, SYNC);
137: }
138:
139: public void testNoFaultAltSync() {
140: doit("throwSimple", 5, false, false, null, null, SYNC);
141: }
142:
143: public void testFaultIndicPropSync() {
144: doit("throwProperties", 6, true, false, new String[] {
145: "faultText", "faultIndic" }, new Object[] {
146: "A Fault Indicator", new Byte((byte) -1) }, SYNC);
147: }
148:
149: public void testJmsPropFaultSync() {
150: doit("throwProperties", 7, true, false, new String[] {
151: "faultText", "faultIndic", "faultProp" }, new Object[] {
152: "Another Property Fault", new Byte((byte) -2),
153: "Another JMS Property" }, SYNC);
154: }
155:
156: public void testIndicOnlySync() {
157: doit("throwProperties", 8, true, false,
158: new String[] { "faultIndic" }, new Object[] { new Byte(
159: (byte) -3) }, SYNC);
160: }
161:
162: public void testPropOnlySync() {
163: doit("throwProperties", 9, true, false,
164: new String[] { "faultProp" },
165: new Object[] { "Another JMS Property" }, SYNC);
166: }
167:
168: public void testNullFaultSync() {
169: doit("throwProperties", 10, true, false, null, null, SYNC);
170: }
171:
172: /* ***************** ASYNC ************************** */
173:
174: public void testNoFaultAsync() {
175: doit("throwSimple", 0, false, false, null, null, ASYNC);
176: }
177:
178: public void testSimpleAsync() {
179: doit("throwSimple", 1, true, false,
180: new String[] { "faultText" },
181: new Object[] { "A Simple Fault" }, ASYNC);
182: }
183:
184: public void testIntsAsync() {
185: doit("throwSimple", 2, true, false, new String[] { "faultInt1",
186: "faultInt2", "faultInt3" }, new Object[] {
187: new Integer(1), new Integer(2), new Integer(3) }, ASYNC);
188: }
189:
190: public void testTwoIntsAsync() {
191: doit("throwSimple", 3, true, false, new String[] { "faultInt1",
192: "faultInt2" }, new Object[] { new Integer(1),
193: new Integer(2) }, ASYNC);
194: }
195:
196: public void testEmptyJmsFaultAsync() {
197: doit("throwSimple", 2, true, false, new String[] { "faultInt1",
198: "faultInt2", "faultInt3" }, new Object[] {
199: new Integer(1), new Integer(2), new Integer(3) }, ASYNC);
200: }
201:
202: public void testIndicIntAsync() {
203: doit("throwIndicInt", 4, true, false,
204: new String[] { "faultText" },
205: new Object[] { "A Simple Fault" }, ASYNC);
206: }
207:
208: public void testNoFaultAltAsync() {
209: doit("throwSimple", 5, false, false, null, null, ASYNC);
210: }
211:
212: public void testFaultIndicPropAsync() {
213: doit("throwProperties", 6, true, false, new String[] {
214: "faultText", "faultIndic" }, new Object[] {
215: "A Fault Indicator", new Byte((byte) -1) }, ASYNC);
216: }
217:
218: public void testJmsPropFaultAsync() {
219: doit("throwProperties", 7, true, false, new String[] {
220: "faultText", "faultIndic", "faultProp" }, new Object[] {
221: "Another Property Fault", new Byte((byte) -2),
222: "Another JMS Property" }, ASYNC);
223: }
224:
225: public void testIndicOnlyAsync() {
226: doit("throwProperties", 8, true, false,
227: new String[] { "faultIndic" }, new Object[] { new Byte(
228: (byte) -3) }, ASYNC);
229: }
230:
231: public void testPropOnlyAsync() {
232: doit("throwProperties", 9, true, false,
233: new String[] { "faultProp" },
234: new Object[] { "Another JMS Property" }, ASYNC);
235: }
236:
237: public void testNullFaultAsync() {
238: doit("throwProperties", 10, true, false, null, null, ASYNC);
239: }
240:
241: private void doit(String method, int choice, boolean faultExpected,
242: boolean exceptionExpected, String[] names, Object[] parts,
243: boolean blocks) {
244:
245: if (!TestUtilities.areWeTesting("jms"))
246: return;
247:
248: try {
249: WSIFServiceFactory factory = WSIFServiceFactory
250: .newInstance();
251: WSIFService service = factory.getService(wsdlLocation,
252: null, null, "http://jms/", "JmsFault");
253:
254: WSIFPort port = service.getPort("default");
255: WSIFOperation operation = port.createOperation(method);
256:
257: WSIFMessage inputMessage = operation.createInputMessage();
258: inputMessage.setIntPart("choice", choice);
259: WSIFMessage outputMessage = operation.createOutputMessage();
260: WSIFMessage faultMessage = operation.createFaultMessage();
261:
262: boolean operationSucceeded = false;
263: if (blocks == SYNC) {
264: operationSucceeded = operation
265: .executeRequestResponseOperation(inputMessage,
266: outputMessage, faultMessage);
267:
268: } else if (blocks == ASYNC) {
269: WSIFMessage context = operation.getContext();
270: context.setObjectPart(WSIFConstants.CONTEXT_JMS_PREFIX
271: + "JMSReplyTo", TestUtilities
272: .getWsifProperty("wsif.async.replytoq2"));
273: operation.setContext(context);
274:
275: WSIFCorrelationId id = operation
276: .executeRequestResponseAsync(inputMessage);
277: System.out
278: .println("async operation done, correlation id="
279: + id.getCorrelationId());
280:
281: Object jmsResponse = TestUtilities
282: .getJMSAsyncResponse(
283: id.getCorrelationId(),
284: TestUtilities
285: .getWsifProperty("wsif.async.replytoq2"));
286:
287: operationSucceeded = operation.processAsyncResponse(
288: jmsResponse, outputMessage, faultMessage);
289:
290: } else
291: assertTrue(false);
292:
293: System.out.println("JmsFaultTest " + method + " "
294: + operationSucceeded + " " + (names == null));
295:
296: assertTrue(
297: "Bad boolean success value from executeRequestReponseOperation",
298: (operationSucceeded && !faultExpected)
299: || (!operationSucceeded && faultExpected));
300:
301: if (!operationSucceeded) {
302: Iterator it = faultMessage.getPartNames();
303: int i = 0;
304: while (it.hasNext()) {
305: it.next();
306: i++;
307: }
308:
309: if (names == null)
310: names = new String[] {};
311: if (parts == null)
312: parts = new Object[] {};
313:
314: assertTrue(
315: "Bad number of parts in the fault message expected="
316: + names.length + " got=" + i,
317: i == names.length);
318:
319: for (i = 0; i < names.length; i++) {
320: Object o = faultMessage.getObjectPart(names[i]);
321:
322: assertTrue("Bad value for partName=" + names[i]
323: + " " + o, parts[i].equals(o));
324: }
325: }
326:
327: assertTrue(!exceptionExpected);
328: } catch (Exception e) {
329: System.err.println("JmsFaultTest(" + method
330: + ") caught exception " + e);
331: if (!exceptionExpected || !(e instanceof WSIFException))
332: e.printStackTrace();
333: assertTrue(exceptionExpected && e instanceof WSIFException);
334: }
335: }
336: }
|