1 17 package org.apache.servicemix.jbi.messaging; 18 19 import org.apache.servicemix.JbiConstants; 20 import org.apache.servicemix.components.util.ComponentSupport; 21 import org.apache.servicemix.jbi.ExchangeTimeoutException; 22 import org.apache.servicemix.jbi.container.JBIContainer; 23 import org.apache.servicemix.jbi.jaxp.StringSource; 24 import org.apache.servicemix.tck.ExchangeCompletedListener; 25 26 import javax.jbi.messaging.DeliveryChannel; 27 import javax.jbi.messaging.ExchangeStatus; 28 import javax.jbi.messaging.Fault; 29 import javax.jbi.messaging.InOnly; 30 import javax.jbi.messaging.InOptionalOut; 31 import javax.jbi.messaging.InOut; 32 import javax.jbi.messaging.MessageExchangeFactory; 33 import javax.jbi.messaging.MessagingException; 34 import javax.jbi.messaging.NormalizedMessage; 35 import javax.jbi.messaging.RobustInOnly; 36 import javax.jbi.messaging.MessageExchange.Role; 37 import javax.xml.namespace.QName ; 38 39 import junit.framework.TestCase; 40 41 public class MEPExchangeTest extends TestCase { 42 43 public static final String PAYLOAD = "<payload/>"; 44 public static final String RESPONSE = "<response/>"; 45 46 private JBIContainer container; 47 private TestComponent provider; 48 private TestComponent consumer; 49 private ExchangeCompletedListener listener; 50 51 public static class TestComponent extends ComponentSupport { 52 public TestComponent(QName service, String endpoint) { 53 super(service, endpoint); 54 } 55 public DeliveryChannel getChannel() throws MessagingException { 56 return getContext().getDeliveryChannel(); 57 } 58 } 59 60 public void setUp() throws Exception { 61 container = new JBIContainer(); 63 container.setEmbedded(true); 64 container.setFlowName("st"); 65 listener = new ExchangeCompletedListener(); 66 container.addListener(listener); 67 container.init(); 68 container.start(); 69 provider = new TestComponent(new QName ("provider"), "endpoint"); 71 consumer = new TestComponent(new QName ("consumer"), "endpoint"); 72 container.activateComponent(provider, "provider"); 74 container.activateComponent(consumer, "consumer"); 75 } 76 77 public void tearDown() throws Exception { 78 if (listener != null) { 79 listener.assertExchangeCompleted(); 80 } 81 if (container != null) { 82 container.shutDown(); 83 } 84 container = null; 85 } 86 87 public void testInOnly() throws Exception { 88 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 90 InOnly mec = mef.createInOnlyExchange(); 91 NormalizedMessage m = mec.createMessage(); 92 m.setContent(new StringSource(PAYLOAD)); 93 mec.setInMessage(m); 94 assertEquals(Role.CONSUMER, mec.getRole()); 95 try { 96 mec.setMessage(null, "in"); 97 fail("Message is null"); 98 } catch (Exception e) { 99 } 101 try { 102 mec.setMessage(mec.createMessage(), "in"); 103 fail("Message already set"); 104 } catch (Exception e) { 105 } 107 try { 108 mec.setMessage(mec.createMessage(), "out"); 109 fail("Out not supported"); 110 } catch (Exception e) { 111 } 113 try { 114 mec.setMessage(mec.createFault(), "fault"); 115 fail("Fault not supported"); 116 } catch (Exception e) { 117 } 119 consumer.getChannel().send(mec); 120 try { 121 mec.setProperty("myprop", "myvalue"); 122 fail("Component is not owner"); 123 } catch (Exception e) { 124 } 126 InOnly mep = (InOnly) provider.getChannel().accept(1000L); 128 assertNotNull(mep); 129 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 130 assertEquals(Role.PROVIDER, mep.getRole()); 131 mep.setStatus(ExchangeStatus.DONE); 132 provider.getChannel().send(mep); 133 assertSame(mec, consumer.getChannel().accept(1000L)); 135 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 136 assertEquals(Role.CONSUMER, mec.getRole()); 137 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 141 142 public void testInOnlyWithError() throws Exception { 143 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 144 InOnly mec = mef.createInOnlyExchange(); 145 NormalizedMessage m = mec.createMessage(); 146 m.setContent(new StringSource(PAYLOAD)); 147 mec.setInMessage(m); 148 assertEquals(Role.CONSUMER, mec.getRole()); 149 consumer.getChannel().send(mec); 150 InOnly mep = (InOnly) provider.getChannel().accept(1000L); 152 assertNotNull(mep); 153 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 154 assertEquals(Role.PROVIDER, mep.getRole()); 155 mep.setError(new Exception ()); 156 provider.getChannel().send(mep); 157 assertSame(mec, consumer.getChannel().accept(1000L)); 159 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 160 assertEquals(Role.CONSUMER, mec.getRole()); 161 try { 163 mec.setStatus(ExchangeStatus.DONE); 164 consumer.getChannel().send(mec); 165 fail("Exchange status is ERROR"); 166 } catch (Exception e) { 167 } 169 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 173 174 public void testInOnlySync() throws Exception { 175 new Thread (new Runnable () { 177 public void run() { 178 try { 179 InOnly mep = (InOnly) provider.getChannel().accept(10000L); 181 assertNotNull(mep); 182 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 183 assertEquals(Boolean.TRUE, mep.getProperty(JbiConstants.SEND_SYNC)); 184 mep.setStatus(ExchangeStatus.DONE); 185 provider.getChannel().send(mep); 186 } catch (Exception e) { 187 e.printStackTrace(); 188 fail(); 189 } 190 } 191 }).start(); 192 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 194 InOnly mec = mef.createInOnlyExchange(); 195 NormalizedMessage m = mec.createMessage(); 196 m.setContent(new StringSource(PAYLOAD)); 197 mec.setInMessage(m); 198 boolean result = consumer.getChannel().sendSync(mec, 10000L); 199 assertTrue(result); 200 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 201 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 205 206 public void testInOnlySyncWithTimeoutBeforeAccept() throws Exception { 207 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 209 InOnly mec = mef.createInOnlyExchange(); 210 NormalizedMessage m = mec.createMessage(); 211 m.setContent(new StringSource(PAYLOAD)); 212 mec.setInMessage(m); 213 boolean result = consumer.getChannel().sendSync(mec, 100L); 214 assertFalse(result); 215 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 216 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 220 221 public void testInOnlySyncWithTimeoutAfterAccept() throws Exception { 222 Thread t = new Thread (new Runnable () { 224 public void run() { 225 try { 226 InOnly mep = (InOnly) provider.getChannel().accept(10000L); 228 assertNotNull(mep); 229 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 230 assertEquals(Boolean.TRUE, mep.getProperty(JbiConstants.SEND_SYNC)); 231 Thread.sleep(100L); 232 mep.setStatus(ExchangeStatus.DONE); 233 provider.getChannel().send(mep); 234 } catch (ExchangeTimeoutException e) { 235 } catch (Exception e) { 237 e.printStackTrace(); 238 fail(); 239 } 240 } 241 }); 242 t.start(); 243 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 245 InOnly mec = mef.createInOnlyExchange(); 246 NormalizedMessage m = mec.createMessage(); 247 m.setContent(new StringSource(PAYLOAD)); 248 mec.setInMessage(m); 249 boolean result = consumer.getChannel().sendSync(mec, 50L); 250 251 assertFalse(result); 252 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 253 assertNull(consumer.getChannel().accept(100L)); t.join(); 256 } 257 258 public void testInOut() throws Exception { 259 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 261 InOut mec = mef.createInOutExchange(); 262 NormalizedMessage m = mec.createMessage(); 263 m.setContent(new StringSource(PAYLOAD)); 264 mec.setInMessage(m); 265 consumer.getChannel().send(mec); 266 InOut mep = (InOut) provider.getChannel().accept(100L); 268 assertNotNull(mep); 269 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 270 m = mep.createMessage(); 271 m.setContent(new StringSource(RESPONSE)); 272 mep.setOutMessage(m); 273 provider.getChannel().send(mep); 274 assertSame(mec, consumer.getChannel().accept(100L)); 276 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 277 mec.setStatus(ExchangeStatus.DONE); 278 consumer.getChannel().send(mec); 279 assertSame(mep, provider.getChannel().accept(100L)); 281 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 282 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 286 287 public void testInOutSync() throws Exception { 288 new Thread (new Runnable () { 290 public void run() { 291 try { 292 InOut mep = (InOut) provider.getChannel().accept(10000L); 294 assertNotNull(mep); 295 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 296 NormalizedMessage m = mep.createMessage(); 297 m.setContent(new StringSource(RESPONSE)); 298 mep.setOutMessage(m); 299 provider.getChannel().send(mep); 300 } catch (Exception e) { 301 e.printStackTrace(); 302 fail(); 303 } 304 } 305 }).start(); 306 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 308 InOut mec = mef.createInOutExchange(); 309 NormalizedMessage m = mec.createMessage(); 310 m.setContent(new StringSource(PAYLOAD)); 311 mec.setInMessage(m); 312 consumer.getChannel().sendSync(mec, 10000L); 313 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 314 mec.setStatus(ExchangeStatus.DONE); 315 consumer.getChannel().send(mec); 316 assertNotNull(provider.getChannel().accept(100L)); 318 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 319 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 323 324 public void testInOutSyncSync() throws Exception { 325 Thread t = new Thread (new Runnable () { 327 public void run() { 328 try { 329 InOut mep = (InOut) provider.getChannel().accept(10000L); 331 assertNotNull(mep); 332 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 333 NormalizedMessage m = mep.createMessage(); 334 m.setContent(new StringSource(RESPONSE)); 335 mep.setOutMessage(m); 336 provider.getChannel().sendSync(mep); 337 assertEquals(ExchangeStatus.DONE, mep.getStatus()); 338 } catch (Exception e) { 339 e.printStackTrace(); 340 fail(); 341 } 342 } 343 }); 344 t.start(); 345 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 347 InOut mec = mef.createInOutExchange(); 348 NormalizedMessage m = mec.createMessage(); 349 m.setContent(new StringSource(PAYLOAD)); 350 mec.setInMessage(m); 351 consumer.getChannel().sendSync(mec, 10000L); 352 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 353 mec.setStatus(ExchangeStatus.DONE); 354 consumer.getChannel().send(mec); 355 t.join(100L); 357 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 361 362 public void testInOutWithFault() throws Exception { 363 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 365 InOut mec = mef.createInOutExchange(); 366 NormalizedMessage m = mec.createMessage(); 367 m.setContent(new StringSource(PAYLOAD)); 368 mec.setInMessage(m); 369 consumer.getChannel().send(mec); 370 InOut mep = (InOut) provider.getChannel().accept(100L); 372 assertNotNull(mep); 373 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 374 Fault f = mep.createFault(); 375 f.setContent(new StringSource(RESPONSE)); 376 mep.setFault(f); 377 provider.getChannel().send(mep); 378 assertSame(mec, consumer.getChannel().accept(100L)); 380 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 381 assertNotNull(mec.getFault()); 382 mec.setStatus(ExchangeStatus.DONE); 383 consumer.getChannel().send(mec); 384 assertSame(mep, provider.getChannel().accept(100L)); 386 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 387 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 391 392 public void testInOutWithFaultAndError() throws Exception { 393 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 395 InOut mec = mef.createInOutExchange(); 396 NormalizedMessage m = mec.createMessage(); 397 m.setContent(new StringSource(PAYLOAD)); 398 mec.setInMessage(m); 399 consumer.getChannel().send(mec); 400 InOut mep = (InOut) provider.getChannel().accept(100L); 402 assertNotNull(mep); 403 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 404 Fault f = mep.createFault(); 405 f.setContent(new StringSource(RESPONSE)); 406 mep.setFault(f); 407 provider.getChannel().send(mep); 408 assertSame(mec, consumer.getChannel().accept(100L)); 410 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 411 assertNotNull(mec.getFault()); 412 mec.setStatus(ExchangeStatus.ERROR); 413 consumer.getChannel().send(mec); 414 assertSame(mep, provider.getChannel().accept(100L)); 416 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 417 try { 418 consumer.getChannel().send(mec); 419 fail("Exchange status is ERROR"); 420 } catch (Exception e) { 421 } 423 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 427 428 public void testInOutWithError1() throws Exception { 429 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 431 InOut mec = mef.createInOutExchange(); 432 NormalizedMessage m = mec.createMessage(); 433 m.setContent(new StringSource(PAYLOAD)); 434 mec.setInMessage(m); 435 consumer.getChannel().send(mec); 436 InOut mep = (InOut) provider.getChannel().accept(100L); 438 assertNotNull(mep); 439 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 440 m = mep.createMessage(); 441 m.setContent(new StringSource(RESPONSE)); 442 mep.setStatus(ExchangeStatus.ERROR); 443 provider.getChannel().send(mep); 444 assertSame(mec, consumer.getChannel().accept(100L)); 446 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 447 try { 448 mec.setStatus(ExchangeStatus.DONE); 449 consumer.getChannel().send(mec); 450 fail("Exchange status is ERROR"); 451 } catch (Exception e) { 452 } 454 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 458 459 public void testInOutWithError2() throws Exception { 460 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 462 InOut mec = mef.createInOutExchange(); 463 NormalizedMessage m = mec.createMessage(); 464 m.setContent(new StringSource(PAYLOAD)); 465 mec.setInMessage(m); 466 consumer.getChannel().send(mec); 467 InOut mep = (InOut) provider.getChannel().accept(100L); 469 assertNotNull(mep); 470 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 471 m = mep.createMessage(); 472 m.setContent(new StringSource(RESPONSE)); 473 provider.getChannel().send(mep); 474 assertSame(mec, consumer.getChannel().accept(100L)); 476 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 477 mec.setStatus(ExchangeStatus.ERROR); 478 consumer.getChannel().send(mec); 479 assertSame(mep, provider.getChannel().accept(100L)); 481 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 482 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 486 487 public void testInOptOutWithRep() throws Exception { 488 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 490 InOptionalOut mec = mef.createInOptionalOutExchange(); 491 NormalizedMessage m = mec.createMessage(); 492 m.setContent(new StringSource(PAYLOAD)); 493 mec.setInMessage(m); 494 consumer.getChannel().send(mec); 495 InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L); 497 assertNotNull(mep); 498 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 499 m = mep.createMessage(); 500 m.setContent(new StringSource(RESPONSE)); 501 mep.setOutMessage(m); 502 provider.getChannel().send(mep); 503 assertSame(mec, consumer.getChannel().accept(100L)); 505 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 506 mec.setStatus(ExchangeStatus.DONE); 507 consumer.getChannel().send(mec); 508 assertSame(mep, provider.getChannel().accept(100L)); 510 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 511 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 515 516 public void testInOptOutWithoutRep() throws Exception { 517 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 519 InOptionalOut mec = mef.createInOptionalOutExchange(); 520 NormalizedMessage m = mec.createMessage(); 521 m.setContent(new StringSource(PAYLOAD)); 522 mec.setInMessage(m); 523 consumer.getChannel().send(mec); 524 InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L); 526 assertNotNull(mep); 527 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 528 mep.setStatus(ExchangeStatus.DONE); 529 provider.getChannel().send(mep); 530 assertSame(mec, consumer.getChannel().accept(100L)); 532 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 533 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 537 538 public void testInOptOutWithProviderFault() throws Exception { 539 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 541 InOptionalOut mec = mef.createInOptionalOutExchange(); 542 NormalizedMessage m = mec.createMessage(); 543 m.setContent(new StringSource(PAYLOAD)); 544 mec.setInMessage(m); 545 consumer.getChannel().send(mec); 546 InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L); 548 assertNotNull(mep); 549 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 550 mep.setFault(mep.createFault()); 551 provider.getChannel().send(mep); 552 assertSame(mec, consumer.getChannel().accept(100L)); 554 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 555 assertNotNull(mec.getFault()); 556 mec.setStatus(ExchangeStatus.DONE); 557 consumer.getChannel().send(mec); 558 assertSame(mep, provider.getChannel().accept(100L)); 560 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 561 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 565 566 public void testInOptOutWithProviderError() throws Exception { 567 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 569 InOptionalOut mec = mef.createInOptionalOutExchange(); 570 NormalizedMessage m = mec.createMessage(); 571 m.setContent(new StringSource(PAYLOAD)); 572 mec.setInMessage(m); 573 consumer.getChannel().send(mec); 574 InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L); 576 assertNotNull(mep); 577 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 578 mep.setStatus(ExchangeStatus.ERROR); 579 provider.getChannel().send(mep); 580 assertSame(mec, consumer.getChannel().accept(100L)); 582 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 583 try { 584 mec.setStatus(ExchangeStatus.DONE); 585 consumer.getChannel().send(mec); 586 fail("Exchange status is ERROR"); 587 } catch (Exception e) { 588 } 590 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 594 595 public void testInOptOutWithRepAndConsumerFault() throws Exception { 596 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 598 InOptionalOut mec = mef.createInOptionalOutExchange(); 599 NormalizedMessage m = mec.createMessage(); 600 m.setContent(new StringSource(PAYLOAD)); 601 mec.setInMessage(m); 602 consumer.getChannel().send(mec); 603 InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L); 605 assertNotNull(mep); 606 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 607 m = mep.createMessage(); 608 m.setContent(new StringSource(RESPONSE)); 609 mep.setOutMessage(m); 610 provider.getChannel().send(mep); 611 assertSame(mec, consumer.getChannel().accept(100L)); 613 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 614 mec.setFault(mec.createFault()); 615 consumer.getChannel().send(mec); 616 assertSame(mep, provider.getChannel().accept(100L)); 618 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 619 assertNotNull(mep.getFault()); 620 mep.setStatus(ExchangeStatus.DONE); 621 provider.getChannel().send(mep); 622 assertSame(mec, consumer.getChannel().accept(100L)); 624 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 625 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 629 630 public void testInOptOutWithRepAndConsumerError() throws Exception { 631 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 633 InOptionalOut mec = mef.createInOptionalOutExchange(); 634 NormalizedMessage m = mec.createMessage(); 635 m.setContent(new StringSource(PAYLOAD)); 636 mec.setInMessage(m); 637 consumer.getChannel().send(mec); 638 InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L); 640 assertNotNull(mep); 641 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 642 m = mep.createMessage(); 643 m.setContent(new StringSource(RESPONSE)); 644 mep.setOutMessage(m); 645 provider.getChannel().send(mep); 646 assertSame(mec, consumer.getChannel().accept(100L)); 648 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 649 mec.setStatus(ExchangeStatus.ERROR); 650 consumer.getChannel().send(mec); 651 assertSame(mep, provider.getChannel().accept(100L)); 653 assertEquals(ExchangeStatus.ERROR, mep.getStatus()); 654 try { 655 mep.setStatus(ExchangeStatus.DONE); 656 provider.getChannel().send(mep); 657 fail("Exchange status is ERROR"); 658 } catch (Exception e) { 659 } 661 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 665 666 public void testInOptOutWithRepFaultAndError() throws Exception { 667 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 669 InOptionalOut mec = mef.createInOptionalOutExchange(); 670 NormalizedMessage m = mec.createMessage(); 671 m.setContent(new StringSource(PAYLOAD)); 672 mec.setInMessage(m); 673 consumer.getChannel().send(mec); 674 InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L); 676 assertNotNull(mep); 677 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 678 m = mep.createMessage(); 679 m.setContent(new StringSource(RESPONSE)); 680 mep.setOutMessage(m); 681 provider.getChannel().send(mep); 682 assertSame(mec, consumer.getChannel().accept(100L)); 684 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 685 mec.setFault(mec.createFault()); 686 consumer.getChannel().send(mec); 687 assertSame(mep, provider.getChannel().accept(100L)); 689 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 690 assertNotNull(mep.getFault()); 691 mep.setStatus(ExchangeStatus.ERROR); 692 provider.getChannel().send(mep); 693 assertSame(mec, consumer.getChannel().accept(100L)); 695 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 696 try { 697 mec.setStatus(ExchangeStatus.DONE); 698 consumer.getChannel().send(mec); 699 fail("Exchange status is ERROR"); 700 } catch (Exception e) { 701 } 703 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 707 708 public void testRobustInOnly() throws Exception { 709 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 711 RobustInOnly mec = mef.createRobustInOnlyExchange(); 712 NormalizedMessage m = mec.createMessage(); 713 m.setContent(new StringSource(PAYLOAD)); 714 mec.setInMessage(m); 715 consumer.getChannel().send(mec); 716 RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(100L); 718 assertNotNull(mep); 719 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 720 mep.setStatus(ExchangeStatus.DONE); 721 provider.getChannel().send(mep); 722 assertSame(mec, consumer.getChannel().accept(100L)); 724 assertEquals(ExchangeStatus.DONE, mec.getStatus()); 725 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 729 730 public void testRobustInOnlyWithFault() throws Exception { 731 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 733 RobustInOnly mec = mef.createRobustInOnlyExchange(); 734 NormalizedMessage m = mec.createMessage(); 735 m.setContent(new StringSource(PAYLOAD)); 736 mec.setInMessage(m); 737 consumer.getChannel().send(mec); 738 RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(100L); 740 assertNotNull(mep); 741 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 742 mep.setFault(mep.createFault()); 743 provider.getChannel().send(mep); 744 assertSame(mec, consumer.getChannel().accept(100L)); 746 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 747 assertNotNull(mec.getFault()); 748 mec.setStatus(ExchangeStatus.DONE); 749 provider.getChannel().send(mec); 750 assertSame(mep, provider.getChannel().accept(100L)); 752 assertEquals(ExchangeStatus.DONE, mep.getStatus()); 753 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 757 758 public void testRobustInOnlyWithError() throws Exception { 759 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 761 RobustInOnly mec = mef.createRobustInOnlyExchange(); 762 NormalizedMessage m = mec.createMessage(); 763 m.setContent(new StringSource(PAYLOAD)); 764 mec.setInMessage(m); 765 consumer.getChannel().send(mec); 766 RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(100L); 768 assertNotNull(mep); 769 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 770 mep.setStatus(ExchangeStatus.ERROR); 771 provider.getChannel().send(mep); 772 assertSame(mec, consumer.getChannel().accept(100L)); 774 assertEquals(ExchangeStatus.ERROR, mec.getStatus()); 775 try { 776 mec.setStatus(ExchangeStatus.DONE); 777 provider.getChannel().send(mec); 778 fail("Exchange status is ERROR"); 779 } catch (Exception e) { 780 } 782 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 786 787 public void testRobustInOnlyWithFaultAndError() throws Exception { 788 MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName ("provider")); 790 RobustInOnly mec = mef.createRobustInOnlyExchange(); 791 NormalizedMessage m = mec.createMessage(); 792 m.setContent(new StringSource(PAYLOAD)); 793 mec.setInMessage(m); 794 consumer.getChannel().send(mec); 795 RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(100L); 797 assertNotNull(mep); 798 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); 799 mep.setFault(mep.createFault()); 800 provider.getChannel().send(mep); 801 assertSame(mec, consumer.getChannel().accept(100L)); 803 assertEquals(ExchangeStatus.ACTIVE, mec.getStatus()); 804 assertNotNull(mec.getFault()); 805 mec.setError(new Exception ()); 806 provider.getChannel().send(mec); 807 assertSame(mep, provider.getChannel().accept(100L)); 809 assertEquals(ExchangeStatus.ERROR, mep.getStatus()); 810 try { 811 mep.setStatus(ExchangeStatus.DONE); 812 provider.getChannel().send(mep); 813 fail("Exchange status is ERROR"); 814 } catch (Exception e) { 815 } 817 assertNull(consumer.getChannel().accept(100L)); assertNull(provider.getChannel().accept(100L)); } 821 822 } 823 | Popular Tags |