1 package test.wsdl.inout; 2 3 import junit.framework.AssertionFailedError; 4 import junit.framework.TestCase; 5 import org.apache.axis.holders.DateHolder; 6 import test.wsdl.inout.holders.AddressHolder; 7 import test.wsdl.inout.holders.PhoneHolder; 8 9 import javax.xml.rpc.ServiceException ; 10 import javax.xml.rpc.holders.IntHolder ; 11 import javax.xml.rpc.holders.StringHolder ; 12 import java.util.Date ; 13 14 21 public class DetailedInoutTestCase extends TestCase 22 { 23 private static Inout io; 24 25 public DetailedInoutTestCase(String name) { 26 super(name); 27 expectedAddress = new Address(); 28 expectedPhone = new Phone(); 29 expectedDate = new Date (2002-1900, 6, 23); 30 expectedAddress.setStreetNum(1); 31 expectedAddress.setStreetName("University Drive"); 32 expectedAddress.setCity("West Lafayette"); 33 expectedAddress.setState("IN"); 34 expectedAddress.setZip(47907); 35 expectedPhone.setAreaCode(765); 36 expectedPhone.setExchange("494"); 37 expectedPhone.setNumber("4900"); 38 expectedAddress.setPhoneNumber(expectedPhone); 39 40 returnAddress = new Address(); 41 returnPhone = new Phone(); 42 returnDate = new Date (1998-1900, 3, 9); 43 returnAddress.setStreetNum(555); 44 returnAddress.setStreetName("Monroe Street"); 45 returnAddress.setCity("Madison"); 46 returnAddress.setState("WI"); 47 returnAddress.setZip(54444); 48 returnPhone.setAreaCode(999); 49 returnPhone.setExchange("one"); 50 returnPhone.setNumber("two"); 51 returnAddress.setPhoneNumber(returnPhone); 52 try { 53 io = new InoutServiceLocator().getInoutService(); 54 } 55 catch (ServiceException jre) { 56 throw new AssertionFailedError("JAX-RPC ServiceException: " + jre); 57 } 58 } 59 60 private String printAddress (Address ad) { 61 String out; 62 if (ad == null) 63 out = "\t[ADDRESS NOT FOUND!]"; 64 else 65 out ="\t" + ad.getStreetNum () + " " + ad.getStreetName () + "\n\t" + ad.getCity () + ", " + ad.getState () + " " + ad.getZip () + "\n\t" + printPhone (ad.getPhoneNumber ()); 66 return out; 67 } 68 69 private String printPhone (Phone ph) 70 { 71 String out; 72 if (ph == null) 73 out = "[PHONE NUMBER NOT FOUND!]"; 74 else 75 out ="Phone: (" + ph.getAreaCode () + ") " + ph.getExchange () + "-" + ph.getNumber (); 76 return out; 77 } 78 79 public boolean equals (Address a1, Address a2) 80 { 81 try 82 { 83 return a1.getStreetNum() == a2.getStreetNum() && a1.getZip() == a2.getZip() && equals (a1.getPhoneNumber(), a2.getPhoneNumber()) && ((a1.getStreetName() == null && a2.getStreetName() == null) || a1.getStreetName().equals (a2.getStreetName())) && ((a1.getCity() == null && a2.getCity() == null) || a1.getCity().equals (a2.getCity())) && ((a1.getState() == null && a2.getState() == null) || a1.getState().equals (a2.getState())); 84 } 85 catch (Throwable t) 86 { 87 return false; 88 } 89 } 90 91 public boolean equals (Phone p1, Phone p2) 92 { 93 try 94 { 95 return p1.getAreaCode() == p2.getAreaCode() && ((p1.getExchange() == null && p2.getExchange() == null) || p1.getExchange().equals (p2.getExchange())) && ((p1.getNumber() == null && p2.getNumber() == null) || p1.getNumber().equals (p2.getNumber())); 96 } 97 catch (Throwable t) 98 { 99 return false; 100 } 101 } 102 103 private Phone expectedPhone; 104 private Address expectedAddress; 105 private Date expectedDate; 106 private int expectedNumber = 99; 107 108 private Phone returnPhone; 109 private Address returnAddress; 110 private Date returnDate; 111 private int returnNumber = 66; 112 113 public void testOut0Inout0In0 () 114 { 115 try 116 { 117 io.out0Inout0In0 (); 118 } 119 catch (Throwable t) 120 { 121 throw new AssertionFailedError("Test failure: out0Inout0In0: " + t.getMessage()); 122 } 123 } 124 125 public void testOut0Inout0In1 () 126 { 127 try 128 { 129 io.out0Inout0In1 ("out0Inout0In1"); 130 } 131 catch (Throwable t) 132 { 133 throw new AssertionFailedError("Test failure: out0Inout0In1" + t.getMessage()); 134 } 135 } 136 137 public void testOut0Inout0InMany () 138 { 139 try 140 { 141 io.out0Inout0InMany ("out0Inout0InMany", expectedAddress); 142 } 143 catch (Throwable t) 144 { 145 throw new AssertionFailedError("Test failure: out0Inout0InMany" + t.getMessage()); 146 } 147 } 148 149 public void testOut0Inout1In0 () 150 { 151 PhoneHolder ph = new PhoneHolder (expectedPhone); 152 try 153 { 154 io.out0Inout1In0 (ph); 155 assertTrue("out0Inout1In0 returned bad value", equals(ph.value, returnPhone)); 156 } 157 catch (Throwable t) 158 { 159 throw new AssertionFailedError("Test failure: out0Inout1In0\nexpected phone = " 160 + printPhone (returnPhone) + "\nactual phone = " 161 + printPhone (ph.value) + t.getMessage()); 162 } 163 } 164 165 public void testOut0Inout1In1 () 166 { 167 StringHolder sh = new StringHolder ("out0Inout1In1"); 168 try 169 { 170 io.out0Inout1In1 (sh, expectedAddress); 171 assertEquals("StringHolder returned bad value", "out0Inout1In1 yo ho ho!", sh.value); 172 } 173 catch (Throwable t) 174 { 175 throw new AssertionFailedError("Test failure: out0Inout1In1\nexpected string = out0Inout1In1 yo ho ho!\nactual string = " 176 + sh.value + t.getMessage()); 177 } 178 } 179 180 public void testOut0Inout1InMany () 181 { 182 PhoneHolder ph = new PhoneHolder (expectedPhone); 183 try 184 { 185 io.out0Inout1InMany ("out0Inout1InMany", expectedAddress, ph); 186 assertTrue("out0Inout1InMany returned bad value", equals(ph.value, returnPhone)); 187 } 188 catch (Throwable t) 189 { 190 throw new AssertionFailedError("Test failure: out0Inout1InMany\nexpected phone = " 191 + printPhone (returnPhone) + "\nactual phone = " 192 + printPhone (ph.value) + t.getMessage()); 193 } 194 } 195 196 public void testOut0InoutManyIn0 () 197 { 198 StringHolder sh = new StringHolder ("out0InoutManyIn0"); 199 AddressHolder ah = new AddressHolder (expectedAddress); 200 try 201 { 202 io.out0InoutManyIn0 (sh, ah); 203 assertEquals("out0InoutManyIn0 yo ho ho!", sh.value); 204 assertTrue("out0InoutManyIn0 returned bad value", equals (ah.value, returnAddress)); 205 } 206 catch (Throwable t) 207 { 208 throw new AssertionFailedError("Test failure: out0InoutManyIn0\nexpected string = out0InoutManyIn0 yo ho ho!\nactual string = " 209 + sh.value + "\nexpected address =\n" + printAddress (returnAddress) 210 + "\nactual address =\n" + printAddress (ah.value) + t.getMessage()); 211 } 212 } 213 214 public void testOut0InoutManyIn1 () 215 { 216 try 217 { 218 StringHolder sh = new StringHolder ("out0InoutManyIn1"); 219 AddressHolder ah = new AddressHolder (expectedAddress); 220 io.out0InoutManyIn1 (sh, ah, expectedPhone); 221 assertEquals("out0InoutManyIn1 yo ho ho!", sh.value); 222 assertTrue("testOut0InoutManyIn1 returned bad value", equals (ah.value, returnAddress)); 223 } 224 catch (Throwable t) 225 { 226 throw new AssertionFailedError("Test failure: out0InoutManyIn1\n" + t.getMessage()); 227 } 228 } 229 230 public void testOut0InoutManyInMany () 231 { 232 StringHolder sh = new StringHolder ("out0InoutManyInMany"); 233 AddressHolder ah = new AddressHolder (expectedAddress); 234 try 235 { 236 io.out0InoutManyInMany (sh, ah, expectedPhone, expectedNumber); 237 assertEquals("out0InoutManyInMany yo ho ho!", sh.value); 238 assertTrue(equals (ah.value, returnAddress)); 239 } 240 catch (Throwable t) 241 { 242 throw new AssertionFailedError("Test failure: out0InoutManyInMany\nexpected string = out0InoutManyInMany yo ho ho!\nactual string = " 243 + sh.value + "\nexpected address =\n" + printAddress (returnAddress) 244 + "\nactual address =\n" + printAddress (ah.value) + t.getMessage()); 245 } 246 } 247 248 public void testOut1Inout0In0 () 249 { 250 int ret = 0; 251 try 252 { 253 ret = io.out1Inout0In0 (); 254 assertEquals("out1Inout0In0 returned wrong value", returnNumber, ret); 255 } 256 catch (Throwable t) 257 { 258 throw new AssertionFailedError("Test failure: out1Inout0In0\nexpected number = " 259 + returnNumber + "\nactual number = " + ret + t.getMessage()); 260 } 261 } 262 263 public void testOut1Inout0In1 () 264 { 265 int ret = 0; 266 try 267 { 268 ret = io.out1Inout0In1 ("out1Inout0In1"); 269 assertEquals(returnNumber, ret); 270 } 271 catch (Throwable t) 272 { 273 throw new AssertionFailedError("Test failure: out1Inout0In1\nexpected number = " 274 + returnNumber + "\nactual number = " + ret + t.getMessage()); 275 } 276 } 277 278 public void testOut1Inout0InMany () 279 { 280 int ret = 0; 281 try 282 { 283 ret = io.out1Inout0InMany ("out1Inout0InMany", expectedAddress); 284 assertEquals(returnNumber, ret); 285 } 286 catch (Throwable t) 287 { 288 throw new AssertionFailedError("Test failure: out1Inout0InMany\nexpected number = " 289 + returnNumber + "\nactual number = " + ret + t.getMessage()); 290 } 291 } 292 293 public void testOut1Inout1In0 () 294 { 295 StringHolder sh = new StringHolder ("out1Inout1In0"); 296 Address ret = null; 297 try 298 { 299 ret = io.out1Inout1In0 (sh); 300 assertEquals("out1Inout1In0 yo ho ho!", sh.value); 301 assertTrue(equals (ret, returnAddress)); 302 } 303 catch (Throwable t) 304 { 305 throw new AssertionFailedError("Test failure: out1Inout1In0\nexpected string = out1Inout1In0 yo ho ho!\nactual string = " 306 + sh.value + "\nexpected address =\n" + printAddress (returnAddress) 307 + "\nactual address =\n" + printAddress (ret) + t.getMessage()); 308 } 309 } 310 311 public void testOut1Inout1In1 () 312 { 313 StringHolder sh = new StringHolder ("out1Inout1In1"); 314 String ret = null; 315 try 316 { 317 ret = io.out1Inout1In1 (sh, expectedAddress); 318 assertEquals("out1Inout1In1 yo ho ho!", sh.value); 319 assertEquals("out1Inout1In1 arghhh!", ret); 320 } 321 catch (Throwable t) 322 { 323 throw new AssertionFailedError("Test failure: out1Inout1In1\nexpected string1 = out1Inout1In1 yo ho ho!\nactual string1 = " 324 + sh.value + "\nexpected string2 = out1Inout1In1 arghhh!\nactual string2 = " + ret); 325 } 326 } 327 328 public void testOut1Inout1InMany () 329 { 330 StringHolder sh = new StringHolder ("out1Inout1InMany"); 331 String ret = null; 332 try 333 { 334 ret = io.out1Inout1InMany (sh, expectedAddress, expectedPhone); 335 assertEquals("out1Inout1InMany yo ho ho!", sh.value); 336 assertEquals("out1Inout1InMany arghhh!", ret); 337 } 338 catch (Throwable t) 339 { 340 throw new AssertionFailedError("Test failure: out1Inout1InMany\nexpected string1 = out1Inout1InMany yo ho ho!\nactual string1 = " 341 + sh.value + "\nexpected string2 = out1Inout1InMany arghhh!\nactual string2 = " + ret + t.getMessage()); 342 } 343 } 344 345 public void testOut1InoutManyIn0 () 346 { 347 StringHolder sh = new StringHolder ("out1InoutManyIn0"); 348 AddressHolder ah = new AddressHolder (expectedAddress); 349 String ret = null; 350 try 351 { 352 ret = io.out1InoutManyIn0 (sh, ah); 353 assertEquals("out1InoutManyIn0 yo ho ho!", sh.value); 354 assertTrue(equals (ah.value, returnAddress)); 355 assertEquals("out1InoutManyIn0 arghhh!", ret); 356 } 357 catch (Throwable t) 358 { 359 throw new AssertionFailedError("Test failure: out1InoutManyIn0\nexpected string1 = out1InoutManyIn0 yo ho ho!\nactual string1 = " 360 + sh.value + "\nexpected address = " + printAddress (returnAddress) 361 + "\nactual address = " + printAddress (ah.value) 362 + "\nexpected string2 = out1InoutManyIn0 arghhh!\nactual string2 = " + ret + t.getMessage()); 363 } 364 } 365 366 public void testOut1InoutManyIn1 () 367 { 368 StringHolder sh = new StringHolder ("out1InoutManyIn1"); 369 AddressHolder ah = new AddressHolder (expectedAddress); 370 String ret = null; 371 try 372 { 373 ret = io.out1InoutManyIn1 (sh, ah, expectedPhone); 374 assertEquals("out1InoutManyIn1 yo ho ho!", sh.value); 375 assertTrue(equals (ah.value, returnAddress)); 376 assertEquals("out1InoutManyIn1 arghhh!", ret); 377 } 378 catch (Throwable t) 379 { 380 throw new AssertionFailedError("Test failure: out1InoutManyIn1\nexpected string1 = out1InoutManyIn1 yo ho ho!\nactual string1 = " 381 + sh.value + "\nexpected address = " + printAddress (returnAddress) 382 + "\nactual address = " + printAddress (ah.value) 383 + "\nexpected string2 = out1InoutManyIn1 arghhh!\nactual string2 = " + ret + t.getMessage()); 384 } 385 } 386 387 public void testOut1InoutManyInMany () 388 { 389 StringHolder sh = new StringHolder ("out1InoutManyInMany"); 390 AddressHolder ah = new AddressHolder (expectedAddress); 391 String ret = null; 392 try 393 { 394 ret = io.out1InoutManyInMany (sh, ah, expectedPhone, expectedNumber); 395 assertEquals("out1InoutManyInMany yo ho ho!", sh.value); 396 assertTrue(equals (ah.value, returnAddress)); 397 assertEquals("out1InoutManyInMany arghhh!", ret); 398 } 399 catch (Throwable t) 400 { 401 throw new AssertionFailedError("Test failure: out1InoutManyInMany\nexpected string1 = out1InoutManyInMany yo ho ho!\nactual string1 = " 402 + sh.value + "\nexpected address = " + printAddress (returnAddress) 403 + "\nactual address = " + printAddress (ah.value) 404 + "\nexpected string2 = out1InoutManyInMany arghhh!\nactual string2 = " + ret + t.getMessage()); 405 } 406 } 407 408 public void testOutManyInout0In0 () 409 { 410 StringHolder sh = new StringHolder ("outManyInout0In0"); 411 AddressHolder ah = new AddressHolder (expectedAddress); 412 try 413 { 414 io.outManyInout0In0 (sh, ah); 415 assertEquals (sh.value, " arghhh!"); 416 assertTrue(equals (ah.value, returnAddress)); 417 } 418 catch (Throwable t) 419 { 420 throw new AssertionFailedError("Test failure: outManyInout0In0\nexpected address = " 421 + printAddress (returnAddress) + "\nactual address = " 422 + printAddress (ah.value) 423 + "\nexpected string = arghhh!\nactual string = " 424 + sh.value + " " + t.getMessage()); 425 } 426 } 427 428 public void testOutManyInout0In1 () 429 { 430 IntHolder ih = new IntHolder (); 431 StringHolder sh = new StringHolder (); 432 try 433 { 434 io.outManyInout0In1 ("outManyInout0In1", ih, sh); 435 assertEquals(returnNumber, ih.value); 436 assertEquals(" yo ho ho!", sh.value); 437 } 438 catch (Throwable t) 439 { 440 throw new AssertionFailedError("Test failure: outManyInout0In1\nexpected string = yo ho ho!\nactual string = " 441 + sh.value + "\nexpected number = " + returnNumber 442 + "\nactual number = " + ih.value + " " + t.getMessage()); 443 } 444 } 445 446 public void testOutManyInout0InMany () 447 { 448 IntHolder ih = new IntHolder (); 449 StringHolder sh = new StringHolder (); 450 try 451 { 452 io.outManyInout0InMany ("outManyInout0InMany", expectedAddress, ih, sh); 453 assertEquals(returnNumber, ih.value); 454 assertEquals(" yo ho ho!", sh.value); 455 } 456 catch (Throwable t) 457 { 458 throw new AssertionFailedError("Test failure: outManyInout0InMany\nexpected string = yo ho ho!\nactual string = " 459 + sh.value + "\nexpected number = " + returnNumber 460 + "\nactual number = " + ih.value + " " + t.getMessage()); 461 } 462 } 463 464 public void testOutManyInout1In0 () 465 { 466 StringHolder shinout = new StringHolder ("outManyInout1In0"); 467 IntHolder ihout = new IntHolder (); 468 StringHolder shout = new StringHolder (); 469 try 470 { 471 io.outManyInout1In0 (shinout, ihout, shout); 472 assertEquals("outManyInout1In0 yo ho ho!", shinout.value); 473 assertEquals(returnNumber, ihout.value); 474 assertEquals(" yo ho ho!", shout.value); 475 } 476 catch (Throwable t) 477 { 478 throw new AssertionFailedError("Test failure: outManyInout1In0\nexpected string1 = outManyInout1In0 yo ho ho!\nactual string1 = " 479 + shinout.value 480 + "\nexpected string2 = yo ho ho!\nactual string2 = " 481 + shout.value + "\nexpected number = " + returnNumber 482 + "\nactual number = " + ihout.value + " " 483 + t.getMessage()); 484 } 485 } 486 487 public void testOutManyInout1In1 () 488 { 489 StringHolder shinout = new StringHolder ("outManyInout1In1"); 490 IntHolder ihout = new IntHolder (); 491 StringHolder shout = new StringHolder (); 492 try 493 { 494 io.outManyInout1In1 (shinout, expectedAddress, ihout, shout); 495 assertEquals("outManyInout1In1 yo ho ho!", shinout.value); 496 assertEquals(returnNumber, ihout.value); 497 assertEquals(" yo ho ho!", shout.value); 498 } 499 catch (Throwable t) 500 { 501 throw new AssertionFailedError("Test failure: outManyInout1In1\nexpected string1 = outManyInout1In1 yo ho ho!\nactual string = " 502 + shinout.value 503 + "\nexpected string2 = yo ho ho!\nactual string2 = " 504 + shout.value + "\nexpected number = " + returnNumber 505 + "\nactual number = " + ihout.value + " " 506 + t.getMessage()); 507 } 508 } 509 510 public void testOutManyInout1InMany () 511 { 512 PhoneHolder ph = new PhoneHolder (expectedPhone); 513 IntHolder ih = new IntHolder (); 514 StringHolder sh = new StringHolder (); 515 try 516 { 517 io.outManyInout1InMany ("outManyInout1InMany", expectedAddress, ph, ih, sh); 518 assertTrue(equals (ph.value, returnPhone)); 519 assertEquals(returnNumber, ih.value); 520 assertEquals(" yo ho ho!", sh.value); 521 } 522 catch (Throwable t) 523 { 524 throw new AssertionFailedError("Test failure: outManyInout1InMany\nexpected phone = " 525 + printPhone (returnPhone) + "\nactual phone = " 526 + printPhone (ph.value) 527 + "\nexpected string = yo ho ho!\nactual string = " 528 + sh.value + "\nexpected number = " + returnNumber 529 + "\nactual number = " + ih.value + " " + t.getMessage()); 530 } 531 } 532 533 public void testOutManyInoutManyIn0 () 534 { 535 StringHolder shinout = new StringHolder ("outManyInoutManyIn0"); 536 AddressHolder ah = new AddressHolder (expectedAddress); 537 IntHolder ihout = new IntHolder (); 538 StringHolder shout = new StringHolder (); 539 try 540 { 541 io.outManyInoutManyIn0 (shinout, ah, ihout, shout); 542 assertEquals("outManyInoutManyIn0 yo ho ho!", shinout.value); 543 assertTrue(equals (ah.value, returnAddress)); 544 assertEquals(returnNumber, ihout.value); 545 assertEquals(" yo ho ho!", shout.value); 546 } 547 catch (Throwable t) 548 { 549 throw new AssertionFailedError("Test failure: outManyInoutManyIn0\nexpected string1 = outManyInoutManyIn0 yo ho ho!\nactual string1 = " 550 + shinout.value + "\nexpected address = " 551 + printAddress (returnAddress) + "\nactual address = " 552 + printAddress (ah.value) 553 + "\nexpected string2 = yo ho ho!\nactual string2 = " 554 + shout.value + "\nexpected number = " + returnNumber 555 + "\nactual number = " + ihout.value + " " 556 + t.getMessage()); 557 } 558 } 559 560 public void testOutManyInoutManyIn1 () 561 { 562 StringHolder shinout = new StringHolder ("outManyInoutManyIn1"); 563 AddressHolder ah = new AddressHolder (expectedAddress); 564 IntHolder ihout = new IntHolder (); 565 StringHolder shout = new StringHolder (); 566 try 567 { 568 io.outManyInoutManyIn1 (shinout, ah, expectedPhone, ihout, shout); 569 assertEquals("outManyInoutManyIn1 yo ho ho!", shinout.value); 570 assertTrue(equals (ah.value, returnAddress)); 571 assertEquals(returnNumber, ihout.value); 572 assertEquals(" yo ho ho!", shout.value); 573 } 574 catch (Throwable t) 575 { 576 throw new AssertionFailedError("Test failure: outManyInoutManyIn1\nexpected string1 = outManyInoutManyIn1 yo ho ho!\nactual string1 = " 577 + shinout.value + "\nexpected address = " 578 + printAddress (returnAddress) + "\nactual address = " 579 + printAddress (ah.value) 580 + "\nexpected string2 = yo ho ho!\nactual string2 = " 581 + shout.value + "\nexpected number = " + returnNumber 582 + "\nactual number = " + ihout.value + " " 583 + t.getMessage()); 584 } 585 } 586 587 public void testOutManyInoutManyInMany () 588 { 589 StringHolder shinout = new StringHolder ("outManyInoutManyInMany"); 590 AddressHolder ah = new AddressHolder (expectedAddress); 591 IntHolder ihout = new IntHolder (); 592 StringHolder shout = new StringHolder (); 593 try 594 { 595 io.outManyInoutManyInMany (shinout, ah, expectedPhone, expectedNumber, ihout, shout); 596 assertEquals("outManyInoutManyInMany yo ho ho!", shinout.value); 597 assertTrue(equals (ah.value, returnAddress)); 598 assertEquals(returnNumber, ihout.value); 599 assertEquals(" yo ho ho!", shout.value); 600 } 601 catch (Throwable t) 602 { 603 throw new AssertionFailedError("Test failure: outManyInoutManyInMany\nexpected string1 = outManyInoutManyInMany yo ho ho!\nactual string1 = " 604 + shinout.value + "\nexpected address = " 605 + printAddress (returnAddress) + "\nactual address = " 606 + printAddress (ah.value) 607 + "\nexpected string2 = yo ho ho!\nactual string2 = " 608 + shout.value + "\nexpected number = " + returnNumber 609 + "\nactual number = " + ihout.value + " " 610 + t.getMessage()); 611 } 612 } 613 public void testDateInout () 614 { 615 org.apache.axis.holders.DateHolder dh = new DateHolder(expectedDate); 616 try 617 { 618 io.dateInout (dh); 619 assertTrue("Output date does not match", returnDate.equals(dh.value)); 620 621 } 622 catch (Throwable t) 623 { 624 throw new AssertionFailedError("Test failure: dateInout: " + t.getMessage()); 625 } 626 } 627 628 } 629 | Popular Tags |