1 57 58 package interop; 59 60 import interop.wsifserviceWrapped.ArrayOfSimpleDocument; 61 import interop.wsifserviceWrapped.ChildDocument; 62 import interop.wsifserviceWrapped.ComplexDocumentResponse; 63 import interop.wsifserviceWrapped.ComplexDocument_ElemType; 64 import interop.wsifserviceWrapped.ComplexDocument_Type; 65 import interop.wsifserviceWrapped.Doc_TestPortType; 66 import interop.wsifserviceWrapped.SimpleDocument_ElemType; 67 import interop.wsifserviceWrapped.SimpleDocument_Type; 68 import interop.wsifserviceWrapped.SingleTagResponse; 69 import interop.wsifserviceWrapped.SingleTag_ElemType; 70 import interop.wsifserviceWrapped.SingleTag_Type; 71 import interop.wsifserviceWrapped.SimpleDocumentResponse; 72 import java.io.StringWriter ; 73 74 import junit.framework.Test; 75 import junit.framework.TestCase; 76 import junit.framework.TestSuite; 77 78 import org.apache.wsif.WSIFException; 79 import org.apache.wsif.WSIFMessage; 80 import org.apache.wsif.WSIFOperation; 81 import org.apache.wsif.WSIFPort; 82 import org.apache.wsif.WSIFService; 83 import org.apache.wsif.WSIFServiceFactory; 84 import org.apache.xml.serialize.OutputFormat; 85 import org.apache.xml.serialize.XMLSerializer; 86 import org.w3c.dom.Element ; 87 import util.TestUtilities; 88 89 98 public class InteropDocWrappedTest extends TestCase { 99 100 String wsdlLocation = 101 TestUtilities.getWsdlPath("java\\test\\interop\\wsifservice") 102 + "interopdoc.wsdl"; 103 106 public InteropDocWrappedTest(String name) { 107 super(name); 108 } 109 110 public static void main(String [] args) { 111 junit.textui.TestRunner.run(suite()); 116 } 118 119 public static Test suite() { 120 return new TestSuite(InteropDocWrappedTest.class); 121 } 122 123 public void setUp() { 124 TestUtilities.setUpExtensionsAndProviders(); 125 } 126 127 public void testSingleTagDII() { 128 doitSingleTagDII("interopDocPort", "axis"); 129 } 130 public void testSimpleDocumentDII() { 131 doitSimpleDocumentDII("interopDocPort", "axis"); 132 } 133 public void testComplexDocumentDII() { 134 doitComplexDocumentDII("interopDocPort", "axis"); 135 } 136 public void testSingleTagStub() { 137 doitSingleTagStub("interopDocPort", "axis"); 138 } 139 public void testSimpleDocumentStub() { 140 doitSimpleDocumentStub("interopDocPort", "axis"); 141 } 142 public void testComplexDocumentStub() { 143 doitComplexDocumentStub("interopDocPort", "axis"); 144 } 145 146 private void doitSingleTagDII(String portName, String protocol) { 147 if (portName.toUpperCase().indexOf("JMS") != -1 148 && !TestUtilities.areWeTesting("jms")) 149 return; 150 151 TestUtilities.setProviderForProtocol(protocol); 152 153 try { 154 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 155 WSIFService service = 156 factory.getService( 157 wsdlLocation, 158 null, 159 null, 160 "http://soapinterop.org/", 161 "Doc_TestPortType"); 162 163 service.mapType( 164 new javax.xml.namespace.QName ( 165 "http://soapinterop.org/", 166 ">SingleTag"), 167 SingleTag_ElemType.class ); 168 service.mapType( 169 new javax.xml.namespace.QName ( 170 "http://soapinterop.org/", 171 "SingleTag"), 172 SingleTag_Type.class ); 173 service.mapType( 174 new javax.xml.namespace.QName ( 175 "http://soapinterop.org/", 176 "SingleTagResponse"), 177 SingleTagResponse.class ); 178 179 WSIFPort port = service.getPort(portName); 180 181 WSIFOperation operation = port.createOperation("SingleTag"); 182 183 WSIFMessage inMsg = operation.createInputMessage(); 184 WSIFMessage outMsg = operation.createOutputMessage(); 185 WSIFMessage faultMsg = operation.createFaultMessage(); 186 187 SingleTag_ElemType stet = new SingleTag_ElemType(); 188 stet.setSingleTag(new SingleTag_Type()); 189 190 inMsg.setObjectPart("parameters", stet); 191 192 boolean ok = 193 operation.executeRequestResponseOperation( 194 inMsg, 195 outMsg, 196 faultMsg); 197 198 assertTrue("operation returned false!!", ok); 199 200 Object o = null; 201 try { 202 o = outMsg.getObjectPart("outputDoc"); 203 assertTrue("response is null!!!", o != null); 204 } catch (WSIFException e) { 205 assertTrue("response part 'outputDoc' not found in output message!!!", false); 206 } 207 assertTrue( 208 "response part has wrong type: " + o.getClass(), 209 SingleTagResponse.class.isAssignableFrom(o.getClass())); 210 211 SingleTagResponse response = (SingleTagResponse) o; 212 assertNotNull("response singleTag is null!!!", response.getSingleTag()); 213 214 } catch (Exception ex) { 215 ex.printStackTrace(); 216 assertTrue( 217 "InteropDocTest.doitSingleTagDII(" 218 + portName 219 + ") caught exception " 220 + ex.getLocalizedMessage(), 221 false); 222 } 223 } 224 225 private void doitSimpleDocumentDII(String portName, String protocol) { 226 if (portName.toUpperCase().indexOf("JMS") != -1 227 && !TestUtilities.areWeTesting("jms")) 228 return; 229 230 TestUtilities.setProviderForProtocol(protocol); 231 232 try { 233 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 234 WSIFService service = 235 factory.getService( 236 wsdlLocation, 237 null, 238 null, 239 "http://soapinterop.org/", 240 "Doc_TestPortType"); 241 242 service.mapPackage("http://soapinterop.org/", "interop.wsifserviceWrapped"); 243 service.mapType( 244 new javax.xml.namespace.QName ( 245 "http://soapinterop.org/", 246 ">SimpleDocument"), 247 SimpleDocument_ElemType.class ); 248 service.mapType( 249 new javax.xml.namespace.QName ( 250 "http://soapinterop.org/", 251 "SimpleDocument"), 252 SimpleDocument_Type.class ); 253 service.mapType( 254 new javax.xml.namespace.QName ( 255 "http://soapinterop.org/", 256 "SimpleDocumentResponse"), 257 SimpleDocumentResponse.class ); 258 259 WSIFPort port = service.getPort(portName); 260 261 WSIFOperation operation = port.createOperation("SimpleDocument"); 262 263 WSIFMessage inMsg = operation.createInputMessage(); 264 WSIFMessage outMsg = operation.createOutputMessage(); 265 WSIFMessage faultMsg = operation.createFaultMessage(); 266 267 SimpleDocument_ElemType sdtet = new SimpleDocument_ElemType(); 268 SimpleDocument_Type sdt = new SimpleDocument_Type(); 269 sdt.setValue("petra"); 270 sdtet.setSimpleDocument(sdt); 271 272 inMsg.setObjectPart("parameters", sdtet); 273 274 boolean ok = 275 operation.executeRequestResponseOperation( 276 inMsg, 277 outMsg, 278 faultMsg); 279 280 assertTrue("operation returned false!!", ok); 281 282 Object o = null; 283 try { 284 o = outMsg.getObjectPart("outputDoc"); 285 assertTrue("response is null!!!", o != null); 286 } catch (WSIFException e) { 287 assertTrue("response part 'outputDoc' not found in output message!!!", false); 288 } 289 assertTrue( 290 "response part has wrong type: " + o.getClass(), 291 SimpleDocumentResponse.class.isAssignableFrom(o.getClass())); 292 293 SimpleDocumentResponse response = (SimpleDocumentResponse) o; 294 SimpleDocument_Type sdtResponse = response.getSimpleDocument(); 295 assertNotNull("response SimpleDocument is null!!!", sdtResponse); 296 297 assertTrue( 298 "document value wrong: " + sdtResponse.getValue(), 299 sdt.getValue().equals(sdtResponse.getValue())); 300 301 } catch (Exception ex) { 302 ex.printStackTrace(); 303 assertTrue( 304 "InteropDocTest.doitSimpleDocumentDII(" 305 + portName 306 + ") caught exception " 307 + ex.getLocalizedMessage(), 308 false); 309 } 310 } 311 312 private void doitComplexDocumentDII(String portName, String protocol) { 313 if (portName.toUpperCase().indexOf("JMS") != -1 314 && !TestUtilities.areWeTesting("jms")) 315 return; 316 317 TestUtilities.setProviderForProtocol(protocol); 318 319 try { 320 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 321 WSIFService service = 322 factory.getService( 323 wsdlLocation, 324 null, 325 null, 326 "http://soapinterop.org/", 327 "Doc_TestPortType"); 328 329 service.mapPackage("http://soapinterop.org/", "interop.wsifserviceWrapped"); 330 331 service.mapType( 332 new javax.xml.namespace.QName ( 333 "http://soapinterop.org/", 334 ">ComplexDocument"), 335 ComplexDocument_ElemType.class ); 336 service.mapType( 337 new javax.xml.namespace.QName ( 338 "http://soapinterop.org/", 339 "ComplexDocument"), 340 ComplexDocument_Type.class ); 341 service.mapType( 342 new javax.xml.namespace.QName ( 343 "http://soapinterop.org/", 344 "ArrayOfSimpleDocument"), 345 ArrayOfSimpleDocument.class ); 346 service.mapType( 347 new javax.xml.namespace.QName ( 348 "http://soapinterop.org/", 349 "SimpleDocument"), 350 SimpleDocument_Type.class ); 351 service.mapType( 352 new javax.xml.namespace.QName ( 353 "http://soapinterop.org/", 354 "ChildDocument"), 355 ChildDocument.class ); 356 service.mapType( 357 new javax.xml.namespace.QName ( 358 "http://soapinterop.org/", 359 "ComplexDocumentResponse"), 360 ComplexDocumentResponse.class ); 361 362 WSIFPort port = service.getPort(portName); 363 364 WSIFOperation operation = port.createOperation("ComplexDocument"); 365 366 WSIFMessage inMsg = operation.createInputMessage(); 367 WSIFMessage outMsg = operation.createOutputMessage(); 368 WSIFMessage faultMsg = operation.createFaultMessage(); 369 370 ComplexDocument_ElemType cdtet = new ComplexDocument_ElemType(); 371 ComplexDocument_Type cdt = makeComplexDocument(); 372 checkComplexDocument(cdt); 373 cdtet.setComplexDocument(cdt); 374 375 inMsg.setObjectPart("parameters", cdtet); 376 377 boolean ok = 378 operation.executeRequestResponseOperation( 379 inMsg, 380 outMsg, 381 faultMsg); 382 383 assertTrue("operation returned false!!", ok); 384 385 Object o = null; 386 try { 387 o = outMsg.getObjectPart("outputDoc"); 388 assertTrue("response is null!!!", o != null); 389 } catch (WSIFException e) { 390 assertTrue("response part 'outputDoc' not found in output message!!!", false); 391 } 392 assertTrue( 393 "response part has wrong type: " + o.getClass(), 394 ComplexDocumentResponse.class.isAssignableFrom(o.getClass())); 395 396 ComplexDocumentResponse response = (ComplexDocumentResponse) o; 397 ComplexDocument_Type cdtResponse = response.getComplexDocument(); 398 assertNotNull("response ComplexDocument is null!!!", cdtResponse); 399 400 checkComplexDocument(cdtResponse); 401 402 } catch (Exception ex) { 403 ex.printStackTrace(); 404 assertTrue( 405 "InteropDocTest.doitComplexDocumentDII(" 406 + portName 407 + ") caught exception " 408 + ex.getLocalizedMessage(), 409 false); 410 } 411 } 412 private void doitSingleTagStub(String portName, String protocol) { 413 if (portName.toUpperCase().indexOf("JMS") != -1 414 && !TestUtilities.areWeTesting("jms")) 415 return; 416 417 TestUtilities.setProviderForProtocol(protocol); 418 419 try { 420 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 421 WSIFService service = 422 factory.getService( 423 wsdlLocation, 424 null, 425 null, 426 "http://soapinterop.org/", 427 "Doc_TestPortType"); 428 429 service.mapPackage("http://soapinterop.org/", "interop.wsifserviceWrapped"); 430 431 service.mapType( 432 new javax.xml.namespace.QName ( 433 "http://soapinterop.org/", 434 ">SingleTag"), 435 SingleTag_ElemType.class ); 436 service.mapType( 437 new javax.xml.namespace.QName ( 438 "http://soapinterop.org/", 439 "SingleTag"), 440 SingleTag_Type.class ); 441 service.mapType( 442 new javax.xml.namespace.QName ( 443 "http://soapinterop.org/", 444 "SingleTagResponse"), 445 SingleTagResponse.class ); 446 447 Doc_TestPortType stub = (Doc_TestPortType) service.getStub(portName, Doc_TestPortType.class); 448 449 SingleTag_ElemType stet = new SingleTag_ElemType(); 450 stet.setSingleTag(new SingleTag_Type()); 451 452 SingleTagResponse response = stub.singleTag(stet); 453 454 assertNotNull("response is null!!!", response); 455 assertNotNull("response singleTag is null!!!", response.getSingleTag()); 456 457 } catch (Exception ex) { 458 ex.printStackTrace(); 459 assertTrue( 460 "InteropDocTest.doitSingleTagDII(" 461 + portName 462 + ") caught exception " 463 + ex.getLocalizedMessage(), 464 false); 465 } 466 } 467 468 private void doitSimpleDocumentStub(String portName, String protocol) { 469 if (portName.toUpperCase().indexOf("JMS") != -1 470 && !TestUtilities.areWeTesting("jms")) 471 return; 472 473 TestUtilities.setProviderForProtocol(protocol); 474 475 try { 476 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 477 WSIFService service = 478 factory.getService( 479 wsdlLocation, 480 null, 481 null, 482 "http://soapinterop.org/", 483 "Doc_TestPortType"); 484 485 service.mapPackage("http://soapinterop.org/", "interop.wsifserviceWrapped"); 486 487 service.mapType( 488 new javax.xml.namespace.QName ( 489 "http://soapinterop.org/", 490 ">SimpleDocument"), 491 SimpleDocument_ElemType.class ); 492 service.mapType( 493 new javax.xml.namespace.QName ( 494 "http://soapinterop.org/", 495 "SimpleDocument"), 496 SimpleDocument_Type.class ); 497 service.mapType( 498 new javax.xml.namespace.QName ( 499 "http://soapinterop.org/", 500 "SimpleDocumentResponse"), 501 SimpleDocumentResponse.class ); 502 503 Doc_TestPortType stub = (Doc_TestPortType) service.getStub(portName, Doc_TestPortType.class); 504 505 SimpleDocument_ElemType sdtet = new SimpleDocument_ElemType(); 506 SimpleDocument_Type sdt = new SimpleDocument_Type(); 507 sdt.setValue("petra"); 508 sdtet.setSimpleDocument(sdt); 509 510 SimpleDocumentResponse response = stub.simpleDocument(sdtet); 511 512 assertNotNull("response is null!!!", response); 513 514 SimpleDocument_Type sdtResponse = response.getSimpleDocument(); 515 assertNotNull("response simpleDocument is null!!!", sdtResponse); 516 517 assertTrue( 518 "simpleDocument value wrong: " + sdtResponse.getValue(), 519 sdt.getValue().equals(sdtResponse.getValue())); 520 521 } catch (Exception ex) { 522 ex.printStackTrace(); 523 assertTrue( 524 "InteropDocTest.doitSimpleDocumentDII(" 525 + portName 526 + ") caught exception " 527 + ex.getLocalizedMessage(), 528 false); 529 } 530 } 531 532 private void doitComplexDocumentStub(String portName, String protocol) { 533 if (portName.toUpperCase().indexOf("JMS") != -1 534 && !TestUtilities.areWeTesting("jms")) 535 return; 536 537 TestUtilities.setProviderForProtocol(protocol); 538 539 try { 540 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 541 WSIFService service = 542 factory.getService( 543 wsdlLocation, 544 null, 545 null, 546 "http://soapinterop.org/", 547 "Doc_TestPortType"); 548 549 service.mapPackage("http://soapinterop.org/", "interop.wsifserviceWrapped"); 550 551 service.mapType( 552 new javax.xml.namespace.QName ( 553 "http://soapinterop.org/", 554 ">ComplexDocument"), 555 ComplexDocument_ElemType.class ); 556 service.mapType( 557 new javax.xml.namespace.QName ( 558 "http://soapinterop.org/", 559 "ComplexDocument"), 560 ComplexDocument_Type.class ); 561 service.mapType( 562 new javax.xml.namespace.QName ( 563 "http://soapinterop.org/", 564 "ArrayOfSimpleDocument"), 565 ArrayOfSimpleDocument.class ); 566 service.mapType( 567 new javax.xml.namespace.QName ( 568 "http://soapinterop.org/", 569 "SimpleDocument"), 570 SimpleDocument_Type.class ); 571 service.mapType( 572 new javax.xml.namespace.QName ( 573 "http://soapinterop.org/", 574 "ChildDocument"), 575 ChildDocument.class ); 576 service.mapType( 577 new javax.xml.namespace.QName ( 578 "http://soapinterop.org/", 579 "ComplexDocumentResponse"), 580 ComplexDocumentResponse.class ); 581 582 Doc_TestPortType stub = (Doc_TestPortType) service.getStub(portName, Doc_TestPortType.class); 583 584 ComplexDocument_ElemType cdtet = new ComplexDocument_ElemType(); 585 ComplexDocument_Type cdt = makeComplexDocument(); 586 checkComplexDocument(cdt); 587 cdtet.setComplexDocument(cdt); 588 589 ComplexDocumentResponse response = stub.complexDocument(cdtet); 590 assertNotNull("response is null!!!", response); 591 592 ComplexDocument_Type cdtResponse = response.getComplexDocument(); 593 assertNotNull("response complexDocument is null!!!", cdtResponse); 594 595 checkComplexDocument(cdtResponse); 596 597 } catch (Exception ex) { 598 ex.printStackTrace(); 599 assertTrue( 600 "InteropDocTest.doitComplexDocumentDII(" 601 + portName 602 + ") caught exception " 603 + ex.getLocalizedMessage(), 604 false); 605 } 606 } 607 608 private ComplexDocument_Type makeComplexDocument() { 609 610 ComplexDocument_Type cdt = new ComplexDocument_Type(); 611 612 ArrayOfSimpleDocument asd = new ArrayOfSimpleDocument(); 613 SimpleDocument_Type[] adt = new SimpleDocument_Type[2]; 614 adt[0] = new SimpleDocument_Type("petra"); 615 adt[1] = new SimpleDocument_Type("ant"); 616 asd.setSimpleDocument(adt); 617 cdt.setSimpleDoc(asd); 618 619 ChildDocument cd = new ChildDocument(); 620 asd = new ArrayOfSimpleDocument(); 621 adt = new SimpleDocument_Type[1]; 622 adt[0] = new SimpleDocument_Type("sue"); 623 asd.setSimpleDocument(adt); 624 cd.setChildSimpleDoc(asd); 625 cdt.setChild(cd); 626 627 cdt.setAnAttribute("together"); 628 629 return cdt; 630 } 631 632 private void checkComplexDocument(ComplexDocument_Type cdt) { 633 634 ArrayOfSimpleDocument asd = cdt.getSimpleDoc(); 635 assertTrue("asd is null!!!", asd != null); 636 SimpleDocument_Type[] adt = asd.getSimpleDocument(); 637 638 boolean b = "petra".equals(adt[0]); 639 640 assertTrue("adt is null!!!", adt != null); 641 assertTrue("adt length not 2, is: " + adt.length, adt.length == 2); 642 assertTrue("child adt[0] not 'petra', is: " + adt[0], "petra".equals(adt[0].getValue())); 643 assertTrue("child adt[1] not 'ant', is: " + adt[0], "ant".equals(adt[1].getValue())); 644 645 ChildDocument cd = cdt.getChild(); 646 asd = cd.getChildSimpleDoc(); 647 assertTrue("child asd is null!!!", asd != null); 648 adt = asd.getSimpleDocument(); 649 assertTrue("child adt is null!!!", adt != null); 650 assertTrue("child adt length not 1, is: " + adt.length, adt.length == 1); 651 assertTrue("child adt[0] not 'sue', is: " + adt[0], "sue".equals(adt[0].getValue())); 652 653 String s = cdt.getAnAttribute(); 654 assertTrue("attribute not 'together' is: " + s, "together".equals(s)); 655 656 } 657 658 } 659 | Popular Tags |