1 57 58 package jms; 59 60 import java.rmi.RemoteException ; 61 import java.text.DateFormat ; 62 import java.util.Date ; 63 64 import javax.jms.DeliveryMode ; 65 import javax.xml.namespace.QName ; 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 85 public class JmsTest extends TestCase { 86 String wsdlLocation = TestUtilities.getWsdlPath("java\\test\\jms") + "jms.wsdl"; 87 static String server = TestUtilities.getSoapServer().toUpperCase(); 88 89 static String 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 SOAP = "soap"; 100 private final static String AXIS = "axis"; 101 private final static String JAVA = "java"; 102 private final static String NJMS = "njms"; 103 private final static String REPLYTOQ = "AddressBookReplyTo"; 104 private final static int PERS = DeliveryMode.PERSISTENT; 105 private final static int NPERS = DeliveryMode.NON_PERSISTENT; 106 private final static String UP = "user properties"; 107 private final static String APV = "address property values"; 108 private final static String BPV = "binding property values"; 109 private final static String ABPV = "address and binding property values"; 110 private final static String UPV = "user properties values"; 111 private final static String OPV = "overiding property values"; 112 private final static String TO = "timeout"; 113 114 private interface AddressBookWithAttrs extends AddressBook { 115 public void addEntry(String name, Address address) throws RemoteException ; 116 public void addEntry(String name, Address address, int deliveryMode) 117 throws RemoteException ; 118 public void addEntry( 119 String name, 120 Address address, 121 int priority, 122 String replyTo, 123 int deliveryMode, 124 long timeToLive) 125 throws RemoteException ; 126 127 public void addEntry( 128 String 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 strUp, 139 Object obj) 140 throws RemoteException ; 141 142 public Address getAddressFromName(String name) throws RemoteException ; 143 public Address getAddressFromName(String name, int deliveryMode) 144 throws RemoteException ; 145 } 146 147 public JmsTest(String name) { 148 super(name); 149 } 150 151 public static void main(String [] 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 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 319 public void testSoapTimeout() { 320 doit("timeout", SOAP, REPLYTOQ, 3, NPERS, 0, TO); 321 } 322 323 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 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 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 portName, 577 String protocol, 578 String replyTo, 579 int priority, 580 int deliveryMode, 581 long timeToLive, 582 String 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 ("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 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 cmd, 639 int deliveryMode) 640 throws Exception { 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 679 private void doTimeout( 680 AddressBookWithAttrs stub, 681 int deliveryMode) 682 throws Exception { 683 684 boolean caught = false; 685 Date first = new Date (); 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 second = new Date (); 694 695 DateFormat 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 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 |