KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jms > JmsTest


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 jms;
59
60 import java.rmi.RemoteException JavaDoc;
61 import java.text.DateFormat JavaDoc;
62 import java.util.Date JavaDoc;
63
64 import javax.jms.DeliveryMode JavaDoc;
65 import javax.xml.namespace.QName JavaDoc;
66 import junit.framework.Test;
67 import junit.framework.TestCase;
68 import junit.framework.TestSuite;
69
70 import org.apache.wsif.WSIFException;
71 import org.apache.wsif.WSIFService;
72 import org.apache.wsif.WSIFServiceFactory;
73 import org.apache.wsif.util.WSIFProperties;
74 import util.AddressUtility;
75 import util.TestUtilities;
76
77 import addressbook.wsifservice.AddressBook;
78 import addressbook.wsiftypes.Address;
79 import addressbook.wsiftypes.Phone;
80
81 /**
82  * Junit test to do various JMS tests
83  * @author Mark Whitlock
84  */

85 public class JmsTest extends TestCase {
86     String JavaDoc wsdlLocation = TestUtilities.getWsdlPath("java\\test\\jms") + "jms.wsdl";
87     static String JavaDoc server = TestUtilities.getSoapServer().toUpperCase();
88     
89     static String JavaDoc name = "Purdue Boilermaker";
90     static Address addr =
91         new Address(
92             1,
93             "University Drive",
94             "West Lafayette",
95             "IN",
96             47907,
97             new Phone(765, "494", "4900"));
98
99     private final static String JavaDoc SOAP = "soap";
100     private final static String JavaDoc AXIS = "axis";
101     private final static String JavaDoc JAVA = "java";
102     private final static String JavaDoc NJMS = "njms";
103     private final static String JavaDoc REPLYTOQ = "AddressBookReplyTo";
104     private final static int PERS = DeliveryMode.PERSISTENT;
105     private final static int NPERS = DeliveryMode.NON_PERSISTENT;
106     private final static String JavaDoc UP = "user properties";
107     private final static String JavaDoc APV = "address property values";
108     private final static String JavaDoc BPV = "binding property values";
109     private final static String JavaDoc ABPV = "address and binding property values";
110     private final static String JavaDoc UPV = "user properties values";
111     private final static String JavaDoc OPV = "overiding property values";
112     private final static String JavaDoc TO = "timeout";
113
114     private interface AddressBookWithAttrs extends AddressBook {
115         public void addEntry(String JavaDoc name, Address address) throws RemoteException JavaDoc;
116         public void addEntry(String JavaDoc name, Address address, int deliveryMode)
117             throws RemoteException JavaDoc;
118         public void addEntry(
119             String JavaDoc name,
120             Address address,
121             int priority,
122             String JavaDoc replyTo,
123             int deliveryMode,
124             long timeToLive)
125             throws RemoteException JavaDoc;
126     
127         public void addEntry(
128             String JavaDoc name,
129             Address address,
130             int deliveryMode,
131             boolean boolUp,
132             byte byteUp,
133             short shUp,
134             int intUp,
135             long loUp,
136             float flUp,
137             double doUp,
138             String JavaDoc strUp,
139             Object JavaDoc obj)
140             throws RemoteException JavaDoc;
141     
142         public Address getAddressFromName(String JavaDoc name) throws RemoteException JavaDoc;
143         public Address getAddressFromName(String JavaDoc name, int deliveryMode)
144             throws RemoteException JavaDoc;
145     }
146
147     public JmsTest(String JavaDoc name) {
148         super(name);
149     }
150
151     public static void main(String JavaDoc[] args) {
152         TestUtilities.startListeners(
153             TestUtilities.ADDRESSBOOK_LISTENER
154                 | TestUtilities.NATIVEJMS_LISTENER);
155
156         junit.textui.TestRunner.run(suite());
157         TestUtilities.stopListeners();
158     }
159
160     public static Test suite() {
161         return new TestSuite(JmsTest.class);
162     }
163
164     public void setUp() {
165         TestUtilities.setUpExtensionsAndProviders();
166     }
167
168     /* *************** Start of SOAP tests ****************** */
169     
170     public void testSoapDefault() {
171         doit("default", SOAP, REPLYTOQ, 3, NPERS, 0, null);
172     }
173
174     public void testSoapDefaultAlt() {
175         doit("default-alt", SOAP, REPLYTOQ, 3, NPERS, 0, null);
176     }
177
178     public void testSoapBadQcfMixQ() {
179         doit("bad-qcfmixq", SOAP, REPLYTOQ, 3, NPERS, 0, null);
180     }
181
182     public void testSoapBadMixQ() {
183         doit("bad-mixq", SOAP, REPLYTOQ, 3, NPERS, 0, null);
184     }
185
186     public void testSoapBadMixIcf() {
187         doit("bad-mixicf", SOAP, REPLYTOQ, 3, NPERS, 0, null);
188     }
189
190     public void testSoapBadQcf() {
191         doit("bad-qcf", SOAP, REPLYTOQ, 3, NPERS, 0, null);
192     }
193
194     public void testSoapBadQ() {
195         doit("bad-queue", SOAP, REPLYTOQ, 3, NPERS, 0, null);
196     }
197
198     public void testSoapBadAltQ() {
199         doit("bad-altqueue", SOAP, REPLYTOQ, 3, NPERS, 0, null);
200     }
201
202     public void testSoapBadStyle() {
203         doit("bad-style", SOAP, REPLYTOQ, 3, NPERS, 0, null);
204     }
205
206     public void testSoapBadIcf() {
207         doit("bad-icf", SOAP, REPLYTOQ, 3, NPERS, 0, null);
208     }
209
210     public void testSoapBadJurl() {
211         doit("bad-jurl", SOAP, REPLYTOQ, 3, NPERS, 0, null);
212     }
213
214     public void testSoapBadNoQ() {
215         doit("bad-noq", SOAP, REPLYTOQ, 3, NPERS, 0, null);
216     }
217
218     public void testSoapBadNoStyle() {
219         doit("bad-nostyle", SOAP, REPLYTOQ, 3, NPERS, 0, null);
220     }
221
222     public void testSoapBadNoQcf() {
223         doit("bad-noqcf", SOAP, REPLYTOQ, 3, NPERS, 0, null);
224     }
225
226     public void testSoapBadNoIcfJurl() {
227         doit("bad-noicfjurl", SOAP, REPLYTOQ, 3, NPERS, 0, null);
228     }
229
230     public void testSoapBadAltAndQ() {
231         doit("bad-altandq", SOAP, REPLYTOQ, 3, NPERS, 0, null);
232     }
233
234     public void testSoapBadTopic() {
235         doit("bad-topic", SOAP, REPLYTOQ, 3, NPERS, 0, null);
236     }
237
238     public void testSoapBadImplSpec() {
239         doit("bad-implspec", SOAP, REPLYTOQ, 3, NPERS, 0, null);
240     }
241
242     public void testSoapBadMqAndJndi() {
243         doit("bad-mqandjndi", SOAP, REPLYTOQ, 3, NPERS, 0, null);
244     }
245
246     public void testSoapBadNothing() {
247         doit("bad-nothing", SOAP, REPLYTOQ, 3, NPERS, 0, null);
248     }
249
250     public void testSoapBadNoBinding() {
251         doit("bad-nobinding", SOAP, REPLYTOQ, 3, NPERS, 0, null);
252     }
253
254     public void testSoapHttpNoAttrs() {
255         doit(server+"-http-noattrs", SOAP, REPLYTOQ, 3, NPERS, 0, null);
256     }
257
258     public void testSoapNullReplyTo() {
259         doit("default", SOAP, null, 3, NPERS, 0, null);
260     }
261
262     public void testSoapShortReplyTo() {
263         doit("default", SOAP, "", 3, NPERS, 0, null);
264     }
265
266     public void testSoapBadReplyTo() {
267         doit("baddefault", SOAP, "trash", 3, NPERS, 0, null);
268     }
269     
270     public void testSoapZeroPriority() {
271         doit("default", SOAP, REPLYTOQ, 0, NPERS, 0, null);
272     }
273     
274     public void testSoapNegPriority() {
275         doit("baddefault", SOAP, REPLYTOQ, -1, NPERS, 0, null);
276     }
277     
278     public void testSoapBigPriority() {
279         doit("baddefault", SOAP, REPLYTOQ, 57, NPERS, 0, null);
280     }
281     
282     public void testSoapPersistent() {
283         doit("default", SOAP, REPLYTOQ, 3, PERS, 0, null);
284     }
285     
286     public void testSoapBadPers() {
287         doit("bad-persist", SOAP, REPLYTOQ, 3, PERS, 0, null);
288     }
289     
290     public void testSoapNonPers() {
291         doit("nonpersist", SOAP, REPLYTOQ, 3, NPERS, 0, null);
292     }
293
294     public void testSoapUserProp() {
295         doit("default", SOAP, REPLYTOQ, 3, NPERS, 0, UP);
296     }
297     
298     public void testSoapAddrPrVals() {
299         doit("addrpv", SOAP, REPLYTOQ, 3, PERS, 0, APV);
300     }
301     
302     public void testSoapBindPrVals() {
303         doit("bindpv", SOAP, REPLYTOQ, 3, PERS, 0, BPV);
304     }
305     
306 // public void testSoapAdBiPrVals() {
307
// doit("adbipv", SOAP, REPLYTOQ, 3, PERS, 0, ABPV);
308
// }
309
// public void testSoapOvAdBiPrVals() {
310
// doit("ovpv", SOAP, REPLYTOQ, 3, PERS, 0, OPV);
311
// }
312
// public void testSoapUserPrVals() {
313
// doit("userpv", SOAP, REPLYTOQ, 3, NPERS, 0, UPV);
314
// }
315
// public void testSoapBadPVNoName() {
316
// doit("bad-pvnoname", SOAP, REPLYTOQ, 3, NPERS, 0, APV);
317
// }
318

319     public void testSoapTimeout() {
320         doit("timeout", SOAP, REPLYTOQ, 3, NPERS, 0, TO);
321     }
322
323     /* ********** Start of AXIS tests ************ */
324     
325     public void testAxisDefault() {
326         doit("default", AXIS, REPLYTOQ, 3, NPERS, 0, null);
327     }
328
329     public void testAxisDefaultAlt() {
330         doit("default-alt", AXIS, REPLYTOQ, 3, NPERS, 0, null);
331     }
332     
333     public void testAxisBadQcfMixQ() {
334         doit("bad-qcfmixq", AXIS, REPLYTOQ, 3, NPERS, 0, null);
335     }
336     
337     public void testAxisBadMixQ() {
338         doit("bad-mixq", AXIS, REPLYTOQ, 3, NPERS, 0, null);
339     }
340     
341     public void testAxisBadMixIcf() {
342         doit("bad-mixicf", AXIS, REPLYTOQ, 3, NPERS, 0, null);
343     }
344     
345     public void testAxisBadQcf() {
346         doit("bad-qcf", AXIS, REPLYTOQ, 3, NPERS, 0, null);
347     }
348     
349     public void testAxisBadQ() {
350         doit("bad-queue", AXIS, REPLYTOQ, 3, NPERS, 0, null);
351     }
352     
353     public void testAxisBadAltQ() {
354         doit("bad-altqueue", AXIS, REPLYTOQ, 3, NPERS, 0, null);
355     }
356     
357     public void testAxisBadStyle() {
358         doit("bad-style", AXIS, REPLYTOQ, 3, NPERS, 0, null);
359     }
360     
361     public void testAxisBadIcf() {
362         doit("bad-icf", AXIS, REPLYTOQ, 3, NPERS, 0, null);
363     }
364     
365     public void testAxisBadJurl() {
366         doit("bad-jurl", AXIS, REPLYTOQ, 3, NPERS, 0, null);
367     }
368     
369     public void testAxisBadNoQ() {
370         doit("bad-noq", AXIS, REPLYTOQ, 3, NPERS, 0, null);
371     }
372     
373     public void testAxisBadNoStyle() {
374         doit("bad-nostyle", AXIS, REPLYTOQ, 3, NPERS, 0, null);
375     }
376     
377     public void testAxisBadNoQcf() {
378         doit("bad-noqcf", AXIS, REPLYTOQ, 3, NPERS, 0, null);
379     }
380     
381     public void testAxisBadNoIcfJurl() {
382         doit("bad-noicfjurl", AXIS, REPLYTOQ, 3, NPERS, 0, null);
383     }
384     
385     public void testAxisBadAltAndQ() {
386         doit("bad-altandq", AXIS, REPLYTOQ, 3, NPERS, 0, null);
387     }
388     
389     public void testAxisBadTopic() {
390         doit("bad-topic", AXIS, REPLYTOQ, 3, NPERS, 0, null);
391     }
392     
393     public void testAxisBadImplSpec() {
394         doit("bad-implspec", AXIS, REPLYTOQ, 3, NPERS, 0, null);
395     }
396     
397     public void testAxisBadMqAndJndi() {
398         doit("bad-mqandjndi", AXIS, REPLYTOQ, 3, NPERS, 0, null);
399     }
400     
401     public void testAxisBadNothing() {
402         doit("bad-nothing", AXIS, REPLYTOQ, 3, NPERS, 0, null);
403     }
404     
405     public void testAxisBadNoBinding() {
406         doit("bad-nobinding", AXIS, REPLYTOQ, 3, NPERS, 0, null);
407     }
408     
409     public void testAxisHttpNoAttrs() {
410         doit(server+"-http-noattrs", AXIS, REPLYTOQ, 3, NPERS, 0, null);
411     }
412     
413     public void testAxisNullReplyTo() {
414         doit("default", AXIS, null, 3, NPERS, 0, null);
415     }
416     
417     public void testAxisShortReplyTo() {
418         doit("default", AXIS, "", 3, NPERS, 0, null);
419     }
420     
421     public void testAxisBadReplyTo() {
422         doit("baddefault", AXIS, "trash", 3, NPERS, 0, null);
423     }
424     
425     public void testAxisZeroPriority() {
426         doit("default", AXIS, REPLYTOQ, 0, NPERS, 0, null);
427     }
428     
429     public void testAxisNegPriority() {
430         doit("baddefault", AXIS, REPLYTOQ, -1, NPERS, 0, null);
431     }
432     
433     public void testAxisBigPriority() {
434         doit("baddefault", AXIS, REPLYTOQ, 57, NPERS, 0, null);
435     }
436     
437     public void testAxisPersistent() {
438         doit("default", AXIS, REPLYTOQ, 3, PERS, 0, null);
439     }
440     
441     public void testAxisBadPers() {
442         doit("bad-persist", AXIS, REPLYTOQ, 3, PERS, 0, null);
443     }
444     
445     public void testAxisNonPers() {
446         doit("nonpersist", AXIS, REPLYTOQ, 3, NPERS, 0, null);
447     }
448
449     public void testAxisUserProp() {
450         doit("default", AXIS, REPLYTOQ, 3, NPERS, 0, UP);
451     }
452
453     public void testAxisAddrPrVals() {
454         doit("addrpv", AXIS, REPLYTOQ, 3, PERS, 0, APV);
455     }
456
457     public void testAxisBindPrVals() {
458         doit("bindpv", AXIS, REPLYTOQ, 3, PERS, 0, BPV);
459     }
460
461     public void testAxisTimeout() {
462         doit("timeout", AXIS, REPLYTOQ, 3, NPERS, 0, TO);
463     }
464
465     /* ********** Start of Native JMS tests ************ */
466
467     public void testNativeJMSDefault() {
468         doit("NJdefault", NJMS, REPLYTOQ, 3, NPERS, 0, null);
469     }
470     public void testNativeJMSDefaultAlt() {
471         doit("NJdefault-alt", NJMS, REPLYTOQ, 3, NPERS, 0, null);
472     }
473     public void testNativeJMSBadQcfMixQ() {
474         doit("NJbad-qcfmixq", NJMS, REPLYTOQ, 3, NPERS, 0, null);
475     }
476     public void testNativeJMSBadMixQ() {
477         doit("NJbad-mixq", NJMS, REPLYTOQ, 3, NPERS, 0, null);
478     }
479     public void testNativeJMSBadMixIcf() {
480         doit("NJbad-mixicf", NJMS, REPLYTOQ, 3, NPERS, 0, null);
481     }
482     public void testNativeJMSBadQcf() {
483         doit("NJbad-qcf", NJMS, REPLYTOQ, 3, NPERS, 0, null);
484     }
485     public void testNativeJMSBadQ() {
486         doit("NJbad-queue", NJMS, REPLYTOQ, 3, NPERS, 0, null);
487     }
488     public void testNativeJMSBadAltQ() {
489         doit("NJbad-altqueue", NJMS, REPLYTOQ, 3, NPERS, 0, null);
490     }
491     public void testNativeJMSBadStyle() {
492         doit("NJbad-style", NJMS, REPLYTOQ, 3, NPERS, 0, null);
493     }
494     public void testNativeJMSBadIcf() {
495         doit("NJbad-icf", NJMS, REPLYTOQ, 3, NPERS, 0, null);
496     }
497     public void testNativeJMSBadJurl() {
498         doit("NJbad-jurl", NJMS, REPLYTOQ, 3, NPERS, 0, null);
499     }
500     public void testNativeJMSBadNoQ() {
501         doit("NJbad-noq", NJMS, REPLYTOQ, 3, NPERS, 0, null);
502     }
503     public void testNativeJMSBadNoStyle() {
504         doit("NJbad-nostyle", NJMS, REPLYTOQ, 3, NPERS, 0, null);
505     }
506     public void testNativeJMSBadNoQcf() {
507         doit("NJbad-noqcf", NJMS, REPLYTOQ, 3, NPERS, 0, null);
508     }
509     public void testNativeJMSBadNoIcfJurl() {
510         doit("NJbad-noicfjurl", NJMS, REPLYTOQ, 3, NPERS, 0, null);
511     }
512     public void testNativeJMSBadAltAndQ() {
513         doit("NJbad-altandq", NJMS, REPLYTOQ, 3, NPERS, 0, null);
514     }
515     public void testNativeJMSBadTopic() {
516         doit("NJbad-topic", NJMS, REPLYTOQ, 3, NPERS, 0, null);
517     }
518     public void testNativeJMSBadImplSpec() {
519         doit("NJbad-implspec", NJMS, REPLYTOQ, 3, NPERS, 0, null);
520     }
521     public void testNativeJMSBadMqAndJndi() {
522         doit("NJbad-mqandjndi", NJMS, REPLYTOQ, 3, NPERS, 0, null);
523     }
524     public void testNativeJMSBadNothing() {
525         doit("NJbad-nothing", NJMS, REPLYTOQ, 3, NPERS, 0, null);
526     }
527     public void testNativeJMSBadNoBinding() {
528         doit("NJbad-nobinding", NJMS, REPLYTOQ, 3, NPERS, 0, null);
529     }
530     public void testNativeJMSNullReplyTo() {
531         doit("NJdefault", NJMS, null, 3, NPERS, 0, null);
532     }
533     public void testNativeJMSShortReplyTo() {
534         doit("NJdefault", NJMS, "", 3, NPERS, 0, null);
535     }
536     public void testNativeJMSBadReplyTo() {
537         doit("NJbaddefault", NJMS, "trash", 3, NPERS, 0, null);
538     }
539     public void testNativeJMSZeroPriority() {
540         doit("NJdefault", NJMS, REPLYTOQ, 0, NPERS, 0, null);
541     }
542     public void testNativeJMSNegPriority() {
543         doit("NJbaddefault", NJMS, REPLYTOQ, -1, NPERS, 0, null);
544     }
545     public void testNativeJMSBigPriority() {
546         doit("NJbaddefault", NJMS, REPLYTOQ, 57, NPERS, 0, null);
547     }
548     public void testNativeJMSPersistent() {
549         doit("NJdefault", NJMS, REPLYTOQ, 3, PERS, 0, null);
550     }
551     public void testNativeJMSBadPers() {
552         doit("NJbad-persist", NJMS, REPLYTOQ, 3, PERS, 0, null);
553     }
554 // public void testNativeJMSNonPers() { TODO - doesn't work!
555
// doit("NJnonpersist", NJMS, REPLYTOQ, 3, NPERS, 0, null);
556
// }
557
public void testNativeJMSUserProp() {
558         doit("NJdefault", NJMS, REPLYTOQ, 3, NPERS, 0, UP);
559     }
560     public void testNativeJMSAddrPrVals() {
561         doit("NJaddrpv", NJMS, REPLYTOQ, 3, PERS, 0, APV);
562     }
563     public void testNativeJMSBindPrVals() {
564         doit("NJbindpv", NJMS, REPLYTOQ, 3, PERS, 0, BPV);
565     }
566
567     public void testNativeJMSTimeout() {
568         doit("NJtimeout", NJMS, REPLYTOQ, 3, NPERS, 0, TO);
569     }
570
571     public void testJavaNoAttrs() {
572         doit("java-noattrs", JAVA, null, 3, NPERS, 0, null);
573     }
574
575     private void doit(
576         String JavaDoc portName,
577         String JavaDoc protocol,
578         String JavaDoc replyTo,
579         int priority,
580         int deliveryMode,
581         long timeToLive,
582         String JavaDoc cmd) {
583             
584         if (!TestUtilities.areWeTesting("jms"))
585             return;
586
587         TestUtilities.setProviderForProtocol( protocol );
588
589         boolean ExceptionExpected = (portName.indexOf("bad") != -1);
590
591         try {
592             WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
593             WSIFService service =
594                 factory.getService(
595                     wsdlLocation,
596                     null,
597                     null,
598                     "http://wsifservice.addressbook/",
599                     "AddressBook");
600
601             service.mapType(
602                 new QName JavaDoc("http://wsiftypes.addressbook/", "zero"),
603                 jms.NumberZero.class);
604
605             AddressBookWithAttrs stub =
606                 (AddressBookWithAttrs) service.getStub(portName, AddressBookWithAttrs.class);
607
608             if ("timeout".equals(cmd))
609                 doTimeout(stub, deliveryMode);
610             else {
611                 if (cmd == null)
612                     stub.addEntry(
613                         name,
614                         addr,
615                         priority,
616                         replyTo,
617                         deliveryMode,
618                         timeToLive);
619                 else
620                     doProperties(stub, cmd, deliveryMode);
621
622                 Address resp = stub.getAddressFromName(name, deliveryMode);
623                 assertTrue(new AddressUtility(resp).equals(addr));
624             }
625             assertTrue(!ExceptionExpected);
626         } catch (Exception JavaDoc e) {
627             System.err.println("JmsTest(" + portName + ") caught exception " + e);
628             if (!ExceptionExpected || !(e instanceof WSIFException))
629                 e.printStackTrace();
630             assertTrue(ExceptionExpected && e instanceof WSIFException);
631         } finally {
632             TestUtilities.resetDefaultProviders();
633         }
634     }
635
636     private void doProperties(
637         AddressBookWithAttrs stub,
638         String JavaDoc cmd,
639         int deliveryMode)
640         throws Exception JavaDoc {
641
642         if (UP.equals(cmd)) {
643             byte b = 52;
644             short s = 53;
645             int i = 54;
646             long l = 55;
647             float f = 56.57F;
648             double d = 58.59D;
649             stub.addEntry(
650                 name,
651                 addr,
652                 deliveryMode,
653                 true,
654                 b,
655                 s,
656                 i,
657                 l,
658                 f,
659                 d,
660                 "60 through 67",
661                 new NumberZero());
662         } else if (
663             APV.equals(cmd)
664                 || BPV.equals(cmd)
665                 || ABPV.equals(cmd)
666                 || UPV.equals(cmd)) {
667             stub.addEntry(name, addr, deliveryMode);
668         } else
669             assertTrue(false);
670     }
671
672     /**
673      * This test only tests out synchronous timeouts. Asynchronous timeouts
674      * are the responsibility of the application since it is the application
675      * that does the listen or receive for the response message. The asynchronous
676      * timeout in wsif.properties is also used by the correlation service,
677      * but this is tested in a separate unit test.
678      */

679     private void doTimeout(
680         AddressBookWithAttrs stub,
681         int deliveryMode)
682         throws Exception JavaDoc {
683
684         boolean caught = false;
685         Date JavaDoc first = new Date JavaDoc();
686         try {
687             stub.addEntry(name, addr, deliveryMode);
688         } catch (WSIFException we) {
689             System.out.println("Caught expected " + we);
690             caught = true;
691         }
692         assertTrue(caught);
693         Date JavaDoc second = new Date JavaDoc();
694
695         DateFormat JavaDoc df = DateFormat.getDateTimeInstance();
696         System.out.println("first date was " + df.format(first));
697         System.out.println("second date was " + df.format(second));
698
699         // getTime() returns milliseconds.
700
long firstTime = first.getTime();
701         long secondTime = second.getTime();
702         System.out.println("first time was " + firstTime);
703         System.out.println("second time was " + secondTime);
704
705         long timeout = WSIFProperties.getSyncTimeout();
706         assertTrue(firstTime<secondTime);
707         assertTrue((secondTime-firstTime)>timeout);
708         assertTrue((secondTime-firstTime)<(timeout*2));
709     }
710
711 }
Popular Tags