Best Citrus code snippet using com.consol.citrus.validation.callback.AbstractValidationCallback.setApplicationContext
Source:ReceiveMessageTestRunnerTest.java
...320 321 @Test322 public void testReceiveBuilderWithEndpointName() {323 TestContext context = applicationContext.getBean(TestContext.class);324 context.setApplicationContext(applicationContextMock);325 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);326 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);327 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);328 when(configuration.getTimeout()).thenReturn(100L);329 when(messageEndpoint.getActor()).thenReturn(null);330 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(331 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")332 .setHeader("operation", "foo"));333 when(applicationContextMock.getBean(TestContext.class)).thenReturn(context);334 when(applicationContextMock.getBean("fooMessageEndpoint", Endpoint.class)).thenReturn(messageEndpoint);335 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());336 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());337 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());338 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {339 @Override340 public void execute() {341 receive(action -> action.endpoint("fooMessageEndpoint")342 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>"));343 }344 };345 TestCase test = builder.getTestCase();346 Assert.assertEquals(test.getActionCount(), 1);347 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);348 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));349 Assert.assertEquals(action.getName(), "receive");350 Assert.assertEquals(action.getEndpointUri(), "fooMessageEndpoint");351 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());352 }353 354 @Test355 public void testReceiveBuilderWithTimeout() {356 reset(messageEndpoint, messageConsumer, configuration);357 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);358 when(messageEndpoint.getActor()).thenReturn(null);359 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(360 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")361 .setHeader("operation", "foo"));362 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {363 @Override364 public void execute() {365 receive(action -> action.endpoint(messageEndpoint)366 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")367 .timeout(1000L));368 }369 };370 TestCase test = builder.getTestCase();371 Assert.assertEquals(test.getActionCount(), 1);372 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);373 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));374 Assert.assertEquals(action.getName(), "receive");375 Assert.assertEquals(action.getEndpoint(), messageEndpoint);376 Assert.assertEquals(action.getReceiveTimeout(), 1000L);377 }378 379 @Test380 public void testReceiveBuilderWithHeaders() {381 reset(messageEndpoint, messageConsumer, configuration);382 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);383 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);384 when(configuration.getTimeout()).thenReturn(100L);385 when(messageEndpoint.getActor()).thenReturn(null);386 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(387 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")388 .setHeader("some", "value")389 .setHeader("operation", "sayHello")390 .setHeader("foo", "bar"));391 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {392 @Override393 public void execute() {394 receive(action -> action.endpoint(messageEndpoint)395 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")396 .headers(Collections.singletonMap("some", "value"))397 .header("operation", "sayHello")398 .header("foo", "bar"));399 receive(action -> action.endpoint(messageEndpoint)400 .header("operation", "sayHello")401 .header("foo", "bar")402 .headers(Collections.singletonMap("some", "value"))403 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>"));404 }405 };406 TestCase test = builder.getTestCase();407 Assert.assertEquals(test.getActionCount(), 2);408 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);409 Assert.assertEquals(test.getActions().get(1).getClass(), ReceiveMessageAction.class);410 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));411 Assert.assertEquals(action.getName(), "receive");412 Assert.assertEquals(action.getEndpoint(), messageEndpoint);413 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());414 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);415 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");416 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("some"));417 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));418 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("foo"));419 action = ((ReceiveMessageAction)test.getActions().get(1));420 Assert.assertEquals(action.getName(), "receive");421 Assert.assertEquals(action.getEndpoint(), messageEndpoint);422 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());423 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);424 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");425 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("some"));426 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));427 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("foo"));428 }429 @Test430 public void testReceiveBuilderWithHeaderData() {431 reset(messageEndpoint, messageConsumer, configuration);432 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);433 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);434 when(configuration.getTimeout()).thenReturn(100L);435 when(messageEndpoint.getActor()).thenReturn(null);436 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(437 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")438 .setHeader("operation", "foo")439 .addHeaderData("<Header><Name>operation</Name><Value>foo</Value></Header>"));440 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {441 @Override442 public void execute() {443 receive(action -> action.endpoint(messageEndpoint)444 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")445 .header("<Header><Name>operation</Name><Value>foo</Value></Header>"));446 receive(action -> action.endpoint(messageEndpoint)447 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))448 .header("<Header><Name>operation</Name><Value>foo</Value></Header>"));449 }450 };451 TestCase test = builder.getTestCase();452 Assert.assertEquals(test.getActionCount(), 2);453 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);454 Assert.assertEquals(test.getActions().get(1).getClass(), ReceiveMessageAction.class);455 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));456 Assert.assertEquals(action.getName(), "receive");457 Assert.assertEquals(action.getEndpoint(), messageEndpoint);458 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());459 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);460 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");461 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);462 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");463 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderResources().size(), 0L);464 action = ((ReceiveMessageAction) test.getActions().get(1));465 Assert.assertEquals(action.getName(), "receive");466 Assert.assertEquals(action.getEndpoint(), messageEndpoint);467 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());468 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);469 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");470 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);471 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");472 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderResources().size(), 0L);473 }474 @Test475 public void testReceiveBuilderWithMultipleHeaderData() {476 reset(messageEndpoint, messageConsumer, configuration);477 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);478 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);479 when(configuration.getTimeout()).thenReturn(100L);480 when(messageEndpoint.getActor()).thenReturn(null);481 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(482 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")483 .setHeader("operation", "foo")484 .addHeaderData("<Header><Name>operation</Name><Value>foo1</Value></Header>")485 .addHeaderData("<Header><Name>operation</Name><Value>foo2</Value></Header>"));486 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {487 @Override488 public void execute() {489 receive(action -> action.endpoint(messageEndpoint)490 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")491 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")492 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>"));493 receive(action -> action.endpoint(messageEndpoint)494 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))495 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")496 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>"));497 }498 };499 TestCase test = builder.getTestCase();500 Assert.assertEquals(test.getActionCount(), 2);501 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);502 Assert.assertEquals(test.getActions().get(1).getClass(), ReceiveMessageAction.class);503 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));504 Assert.assertEquals(action.getName(), "receive");505 Assert.assertEquals(action.getEndpoint(), messageEndpoint);506 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());507 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);508 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");509 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 2L);510 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");511 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");512 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderResources().size(), 0L);513 action = ((ReceiveMessageAction)test.getActions().get(1));514 Assert.assertEquals(action.getName(), "receive");515 Assert.assertEquals(action.getEndpoint(), messageEndpoint);516 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());517 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);518 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");519 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().size(), 2L);520 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");521 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");522 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderResources().size(), 0L);523 }524 @Test525 public void testReceiveBuilderWithHeaderFragment() {526 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);527 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);528 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);529 when(configuration.getTimeout()).thenReturn(100L);530 when(messageEndpoint.getActor()).thenReturn(null);531 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(532 new DefaultMessage()533 .addHeaderData("<TestRequest><Message>Hello Citrus!</Message></TestRequest>")534 .setHeader("operation", "foo"));535 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));536 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());537 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());538 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());539 when(applicationContextMock.getBeansOfType(Marshaller.class)).thenReturn(Collections.<String, Marshaller>singletonMap("marshaller", marshaller));540 when(applicationContextMock.getBean(Marshaller.class)).thenReturn(marshaller);541 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {542 @Override543 public void execute() {544 receive(action -> action.endpoint(messageEndpoint)545 .headerFragment(new TestRequest("Hello Citrus!")));546 }547 };548 TestCase test = builder.getTestCase();549 Assert.assertEquals(test.getActionCount(), 1);550 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);551 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));552 Assert.assertEquals(action.getName(), "receive");553 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());554 Assert.assertEquals(action.getEndpoint(), messageEndpoint);555 Assert.assertEquals(action.getValidationContexts().size(), 3);556 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);557 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);558 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);559 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);560 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);561 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0),562 "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");563 }564 @Test565 public void testReceiveBuilderWithHeaderFragmentExplicitMarshaller() {566 reset(messageEndpoint, messageConsumer, configuration);567 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);568 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);569 when(configuration.getTimeout()).thenReturn(100L);570 when(messageEndpoint.getActor()).thenReturn(null);571 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(572 new DefaultMessage()573 .addHeaderData("<TestRequest><Message>Hello Citrus!</Message></TestRequest>")574 .setHeader("operation", "foo"));575 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {576 @Override577 public void execute() {578 receive(action -> action.endpoint(messageEndpoint)579 .headerFragment(new TestRequest("Hello Citrus!"), marshaller));580 }581 };582 TestCase test = builder.getTestCase();583 Assert.assertEquals(test.getActionCount(), 1);584 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);585 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));586 Assert.assertEquals(action.getName(), "receive");587 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());588 Assert.assertEquals(action.getEndpoint(), messageEndpoint);589 Assert.assertEquals(action.getValidationContexts().size(), 3);590 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);591 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);592 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);593 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);594 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);595 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");596 }597 @Test598 public void testReceiveBuilderWithHeaderFragmentExplicitMarshallerName() {599 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);600 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);601 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);602 when(configuration.getTimeout()).thenReturn(100L);603 when(messageEndpoint.getActor()).thenReturn(null);604 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(605 new DefaultMessage()606 .addHeaderData("<TestRequest><Message>Hello Citrus!</Message></TestRequest>")607 .setHeader("operation", "foo"));608 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));609 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());610 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());611 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());612 when(applicationContextMock.containsBean("myMarshaller")).thenReturn(true);613 when(applicationContextMock.getBean("myMarshaller")).thenReturn(marshaller);614 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {615 @Override616 public void execute() {617 receive(action -> action.endpoint(messageEndpoint)618 .headerFragment(new TestRequest("Hello Citrus!"), "myMarshaller"));619 }620 };621 TestCase test = builder.getTestCase();622 Assert.assertEquals(test.getActionCount(), 1);623 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);624 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));625 Assert.assertEquals(action.getName(), "receive");626 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());627 Assert.assertEquals(action.getEndpoint(), messageEndpoint);628 Assert.assertEquals(action.getValidationContexts().size(), 3);629 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);630 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);631 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);632 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);633 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);634 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");635 }636 637 @Test638 public void testReceiveBuilderWithHeaderResource() throws IOException {639 reset(resource, messageEndpoint, messageConsumer, configuration);640 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);641 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);642 when(configuration.getTimeout()).thenReturn(100L);643 when(messageEndpoint.getActor()).thenReturn(null);644 when(messageConsumer.receive(any(TestContext.class), anyLong()))645 .thenReturn(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")646 .setHeader("operation", "foo")647 .addHeaderData("<Header><Name>operation</Name><Value>foo</Value></Header>"))648 .thenReturn(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")649 .setHeader("operation", "bar")650 .addHeaderData("<Header><Name>operation</Name><Value>bar</Value></Header>"));651 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>foo</Value></Header>".getBytes()))652 .thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>bar</Value></Header>".getBytes()));653 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {654 @Override655 public void execute() {656 receive(action -> action.endpoint(messageEndpoint)657 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")658 .header(resource));659 receive(action -> action.endpoint(messageEndpoint)660 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))661 .header(resource));662 }663 };664 TestCase test = builder.getTestCase();665 Assert.assertEquals(test.getActionCount(), 2);666 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);667 Assert.assertEquals(test.getActions().get(1).getClass(), ReceiveMessageAction.class);668 669 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));670 Assert.assertEquals(action.getName(), "receive");671 672 Assert.assertEquals(action.getEndpoint(), messageEndpoint);673 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());674 675 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);676 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");677 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);678 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");679 680 action = ((ReceiveMessageAction)test.getActions().get(1));681 Assert.assertEquals(action.getName(), "receive");682 683 Assert.assertEquals(action.getEndpoint(), messageEndpoint);684 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());685 686 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);687 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");688 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);689 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>bar</Value></Header>");690 }691 @Test692 public void testReceiveBuilderWithMultipleHeaderResource() throws IOException {693 reset(resource, messageEndpoint, messageConsumer, configuration);694 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);695 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);696 when(configuration.getTimeout()).thenReturn(100L);697 when(messageEndpoint.getActor()).thenReturn(null);698 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(699 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")700 .setHeader("operation", "foo")701 .addHeaderData("<Header><Name>operation</Name><Value>sayHello</Value></Header>")702 .addHeaderData("<Header><Name>operation</Name><Value>foo</Value></Header>")703 .addHeaderData("<Header><Name>operation</Name><Value>bar</Value></Header>"));704 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>foo</Value></Header>".getBytes()))705 .thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>bar</Value></Header>".getBytes()))706 .thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>foo</Value></Header>".getBytes()))707 .thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>bar</Value></Header>".getBytes()));708 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {709 @Override710 public void execute() {711 receive(action -> action.endpoint(messageEndpoint)712 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")713 .header("<Header><Name>operation</Name><Value>sayHello</Value></Header>")714 .header(resource)715 .header(resource));716 receive(action -> action.endpoint(messageEndpoint)717 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))718 .header("<Header><Name>operation</Name><Value>sayHello</Value></Header>")719 .header(resource)720 .header(resource));721 }722 };723 TestCase test = builder.getTestCase();724 Assert.assertEquals(test.getActionCount(), 2);725 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);726 Assert.assertEquals(test.getActions().get(1).getClass(), ReceiveMessageAction.class);727 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));728 Assert.assertEquals(action.getName(), "receive");729 Assert.assertEquals(action.getEndpoint(), messageEndpoint);730 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());731 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);732 Assert.assertEquals(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");733 Assert.assertEquals(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getHeaderData().size(), 3L);734 Assert.assertEquals(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>sayHello</Value></Header>");735 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo</Value></Header>");736 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(2), "<Header><Name>operation</Name><Value>bar</Value></Header>");737 action = ((ReceiveMessageAction)test.getActions().get(1));738 Assert.assertEquals(action.getName(), "receive");739 Assert.assertEquals(action.getEndpoint(), messageEndpoint);740 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());741 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);742 Assert.assertEquals(((StaticMessageContentBuilder) action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");743 Assert.assertEquals(((StaticMessageContentBuilder) action.getMessageBuilder()).getHeaderData().size(), 3L);744 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>sayHello</Value></Header>");745 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo</Value></Header>");746 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(2), "<Header><Name>operation</Name><Value>bar</Value></Header>");747 }748 749 @Test750 public void testReceiveBuilderWithValidator() {751 reset(messageEndpoint, messageConsumer, configuration);752 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);753 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);754 when(configuration.getTimeout()).thenReturn(100L);755 when(messageEndpoint.getActor()).thenReturn(null);756 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));757 final PlainTextMessageValidator validator = new PlainTextMessageValidator();758 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {759 @Override760 public void execute() {761 receive(action -> action.endpoint(messageEndpoint)762 .messageType(MessageType.PLAINTEXT)763 .payload("TestMessage")764 .header("operation", "sayHello")765 .validator(validator));766 }767 };768 TestCase test = builder.getTestCase();769 Assert.assertEquals(test.getActionCount(), 1);770 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);771 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));772 Assert.assertEquals(action.getName(), "receive");773 Assert.assertEquals(action.getEndpoint(), messageEndpoint);774 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());775 Assert.assertEquals(action.getValidators().size(), 1L);776 Assert.assertEquals(action.getValidators().get(0), validator);777 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);778 Assert.assertEquals(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getPayloadData(), "TestMessage");779 Assert.assertTrue(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));780 }781 782 @Test783 public void testReceiveBuilderWithValidatorName() {784 final PlainTextMessageValidator validator = new PlainTextMessageValidator();785 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);786 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);787 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);788 when(configuration.getTimeout()).thenReturn(100L);789 when(messageEndpoint.getActor()).thenReturn(null);790 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));791 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));792 when(applicationContextMock.getBean("plainTextValidator", MessageValidator.class)).thenReturn(validator);793 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());794 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());795 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());796 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {797 @Override798 public void execute() {799 receive(action -> action.endpoint(messageEndpoint)800 .messageType(MessageType.PLAINTEXT)801 .payload("TestMessage")802 .header("operation", "sayHello")803 .validator("plainTextValidator"));804 }805 };806 TestCase test = builder.getTestCase();807 Assert.assertEquals(test.getActionCount(), 1);808 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);809 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));810 Assert.assertEquals(action.getName(), "receive");811 Assert.assertEquals(action.getEndpoint(), messageEndpoint);812 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());813 Assert.assertEquals(action.getValidators().size(), 1L);814 Assert.assertEquals(action.getValidators().get(0), validator);815 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);816 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");817 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));818 }819 @Test820 public void testReceiveBuilderWithDictionary() {821 final DataDictionary dictionary = new NodeMappingDataDictionary();822 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);823 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);824 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);825 when(configuration.getTimeout()).thenReturn(100L);826 when(messageEndpoint.getActor()).thenReturn(null);827 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));828 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));829 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());830 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());831 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());832 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {833 @Override834 public void execute() {835 receive(action -> action.endpoint(messageEndpoint)836 .messageType(MessageType.PLAINTEXT)837 .payload("TestMessage")838 .header("operation", "sayHello")839 .dictionary(dictionary));840 }841 };842 TestCase test = builder.getTestCase();843 Assert.assertEquals(test.getActionCount(), 1);844 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);845 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));846 Assert.assertEquals(action.getName(), "receive");847 Assert.assertEquals(action.getEndpoint(), messageEndpoint);848 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());849 Assert.assertEquals(action.getDataDictionary(), dictionary);850 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);851 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");852 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));853 }854 @Test855 public void testReceiveBuilderWithDictionaryName() {856 final DataDictionary dictionary = new NodeMappingDataDictionary();857 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);858 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);859 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);860 when(configuration.getTimeout()).thenReturn(100L);861 when(messageEndpoint.getActor()).thenReturn(null);862 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));863 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));864 when(applicationContextMock.getBean("customDictionary", DataDictionary.class)).thenReturn(dictionary);865 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());866 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());867 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());868 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {869 @Override870 public void execute() {871 receive(action -> action.endpoint(messageEndpoint)872 .messageType(MessageType.PLAINTEXT)873 .payload("TestMessage")874 .header("operation", "sayHello")875 .dictionary("customDictionary"));876 }877 };878 TestCase test = builder.getTestCase();879 Assert.assertEquals(test.getActionCount(), 1);880 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);881 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));882 Assert.assertEquals(action.getName(), "receive");883 Assert.assertEquals(action.getEndpoint(), messageEndpoint);884 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());885 Assert.assertEquals(action.getDataDictionary(), dictionary);886 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);887 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");888 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));889 }890 @Test891 public void testReceiveBuilderWithSelector() {892 SelectiveConsumer selectiveConsumer = Mockito.mock(SelectiveConsumer.class);893 reset(messageEndpoint, selectiveConsumer, configuration);894 when(messageEndpoint.createConsumer()).thenReturn(selectiveConsumer);895 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);896 when(configuration.getTimeout()).thenReturn(100L);897 when(messageEndpoint.getActor()).thenReturn(null);898 when(selectiveConsumer.receive(eq("operation = 'sayHello'"), any(TestContext.class), anyLong())).thenReturn(899 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")900 .setHeader("operation", "sayHello"));901 final Map<String, String> messageSelector = new HashMap<>();902 messageSelector.put("operation", "sayHello");903 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {904 @Override905 public void execute() {906 receive(action -> action.endpoint(messageEndpoint)907 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")908 .selector(messageSelector));909 }910 };911 TestCase test = builder.getTestCase();912 Assert.assertEquals(test.getActionCount(), 1);913 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);914 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));915 Assert.assertEquals(action.getName(), "receive");916 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());917 Assert.assertEquals(action.getEndpoint(), messageEndpoint);918 Assert.assertEquals(action.getMessageSelectorMap(), messageSelector);919 }920 921 @Test922 public void testReceiveBuilderWithSelectorExpression() {923 SelectiveConsumer selectiveConsumer = Mockito.mock(SelectiveConsumer.class);924 reset(messageEndpoint, selectiveConsumer, configuration);925 when(messageEndpoint.createConsumer()).thenReturn(selectiveConsumer);926 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);927 when(configuration.getTimeout()).thenReturn(100L);928 when(messageEndpoint.getActor()).thenReturn(null);929 when(selectiveConsumer.receive(eq("operation = 'sayHello'"), any(TestContext.class), anyLong())).thenReturn(930 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")931 .setHeader("operation", "sayHello"));932 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {933 @Override934 public void execute() {935 receive(action -> action.endpoint(messageEndpoint)936 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")937 .selector("operation = 'sayHello'"));938 }939 };940 TestCase test = builder.getTestCase();941 Assert.assertEquals(test.getActionCount(), 1);942 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);943 944 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));945 Assert.assertEquals(action.getName(), "receive");946 947 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());948 Assert.assertEquals(action.getEndpoint(), messageEndpoint);949 950 Assert.assertTrue(action.getMessageSelectorMap().isEmpty());951 Assert.assertEquals(action.getMessageSelector(), "operation = 'sayHello'");952 }953 954 @Test955 public void testReceiveBuilderExtractFromPayload() {956 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);957 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);958 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);959 when(configuration.getTimeout()).thenReturn(100L);960 when(messageEndpoint.getActor()).thenReturn(null);961 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(962 new DefaultMessage("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")963 .setHeader("operation", "sayHello"));964 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));965 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());966 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());967 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());968 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {969 @Override970 public void execute() {971 receive(action -> action.endpoint(messageEndpoint)972 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")973 .extractFromPayload("/TestRequest/Message", "text")974 .extractFromPayload("/TestRequest/Message/@lang", "language"));975 }976 };977 TestContext context = builder.getTestContext();978 Assert.assertNotNull(context.getVariable("text"));979 Assert.assertNotNull(context.getVariable("language"));980 Assert.assertEquals(context.getVariable("text"), "Hello World!");981 Assert.assertEquals(context.getVariable("language"), "ENG");982 TestCase test = builder.getTestCase();983 Assert.assertEquals(test.getActionCount(), 1);984 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);985 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));986 Assert.assertEquals(action.getName(), "receive");987 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());988 Assert.assertEquals(action.getEndpoint(), messageEndpoint);989 Assert.assertEquals(action.getVariableExtractors().size(), 1);990 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);991 Assert.assertTrue(((XpathPayloadVariableExtractor) action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message"));992 Assert.assertTrue(((XpathPayloadVariableExtractor) action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));993 }994 @Test995 public void testReceiveBuilderExtractJsonPathFromPayload() {996 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);997 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);998 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);999 when(configuration.getTimeout()).thenReturn(100L);1000 when(messageEndpoint.getActor()).thenReturn(null);1001 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(1002 new DefaultMessage("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")1003 .setHeader("operation", "sayHello"));1004 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));1005 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1006 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1007 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1008 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {1009 @Override1010 public void execute() {1011 receive(action -> action.endpoint(messageEndpoint)1012 .messageType(MessageType.JSON)1013 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")1014 .extractFromPayload("$.text", "text")1015 .extractFromPayload("$.toString()", "payload")1016 .extractFromPayload("$.person", "person"));1017 }1018 };1019 TestContext context = builder.getTestContext();1020 Assert.assertNotNull(context.getVariable("text"));1021 Assert.assertNotNull(context.getVariable("person"));1022 Assert.assertNotNull(context.getVariable("payload"));1023 Assert.assertEquals(context.getVariable("text"), "Hello World!");1024 Assert.assertEquals(context.getVariable("payload"), "{\"person\":{\"surname\":\"Doe\",\"name\":\"John\"},\"index\":5,\"text\":\"Hello World!\",\"id\":\"x123456789x\"}");1025 Assert.assertTrue(context.getVariable("person").contains("\"John\""));1026 TestCase test = builder.getTestCase();1027 Assert.assertEquals(test.getActionCount(), 1);1028 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1029 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1030 Assert.assertEquals(action.getName(), "receive");1031 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1032 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1033 Assert.assertEquals(action.getVariableExtractors().size(), 1);1034 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);1035 Assert.assertTrue(((JsonPathVariableExtractor) action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.text"));1036 Assert.assertTrue(((JsonPathVariableExtractor) action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.person"));1037 }1038 1039 @Test1040 public void testReceiveBuilderExtractFromHeader() {1041 reset(messageEndpoint, messageConsumer, configuration);1042 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1043 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1044 when(configuration.getTimeout()).thenReturn(100L);1045 when(messageEndpoint.getActor()).thenReturn(null);1046 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(1047 new DefaultMessage("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1048 .setHeader("operation", "sayHello")1049 .setHeader("requestId", "123456"));1050 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {1051 @Override1052 public void execute() {1053 receive(action -> action.endpoint(messageEndpoint)1054 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1055 .extractFromHeader("operation", "operationHeader")1056 .extractFromHeader("requestId", "id"));1057 }1058 };1059 TestContext context = builder.getTestContext();1060 Assert.assertNotNull(context.getVariable("operationHeader"));1061 Assert.assertNotNull(context.getVariable("id"));1062 Assert.assertEquals(context.getVariable("operationHeader"), "sayHello");1063 Assert.assertEquals(context.getVariable("id"), "123456");1064 TestCase test = builder.getTestCase();1065 Assert.assertEquals(test.getActionCount(), 1);1066 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1067 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1068 Assert.assertEquals(action.getName(), "receive");1069 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1070 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1071 Assert.assertEquals(action.getVariableExtractors().size(), 1);1072 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);1073 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));1074 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));1075 }1076 1077 @Test1078 public void testReceiveBuilderExtractCombined() {1079 reset(messageEndpoint, messageConsumer, configuration);1080 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1081 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1082 when(configuration.getTimeout()).thenReturn(100L);1083 when(messageEndpoint.getActor()).thenReturn(null);1084 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(1085 new DefaultMessage("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1086 .setHeader("operation", "sayHello")1087 .setHeader("requestId", "123456"));1088 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {1089 @Override1090 public void execute() {1091 receive(action -> action.endpoint(messageEndpoint)1092 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1093 .extractFromHeader("operation", "operationHeader")1094 .extractFromHeader("requestId", "id")1095 .extractFromPayload("/TestRequest/Message", "text")1096 .extractFromPayload("/TestRequest/Message/@lang", "language"));1097 }1098 };1099 TestContext context = builder.getTestContext();1100 Assert.assertNotNull(context.getVariable("operationHeader"));1101 Assert.assertNotNull(context.getVariable("id"));1102 Assert.assertEquals(context.getVariable("operationHeader"), "sayHello");1103 Assert.assertEquals(context.getVariable("id"), "123456");1104 Assert.assertNotNull(context.getVariable("text"));1105 Assert.assertNotNull(context.getVariable("language"));1106 Assert.assertEquals(context.getVariable("text"), "Hello World!");1107 Assert.assertEquals(context.getVariable("language"), "ENG");1108 TestCase test = builder.getTestCase();1109 Assert.assertEquals(test.getActionCount(), 1);1110 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1111 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1112 Assert.assertEquals(action.getName(), "receive");1113 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1114 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1115 Assert.assertEquals(action.getVariableExtractors().size(), 2);1116 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);1117 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));1118 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));1119 Assert.assertTrue(action.getVariableExtractors().get(1) instanceof XpathPayloadVariableExtractor);1120 Assert.assertTrue(((XpathPayloadVariableExtractor) action.getVariableExtractors().get(1)).getXpathExpressions().containsKey("/TestRequest/Message"));1121 Assert.assertTrue(((XpathPayloadVariableExtractor) action.getVariableExtractors().get(1)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));1122 }1123 1124 @Test1125 public void testReceiveBuilderWithValidationCallback() {1126 final AbstractValidationCallback callback = Mockito.mock(AbstractValidationCallback.class);1127 reset(callback, messageEndpoint, messageConsumer, configuration);1128 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1129 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1130 when(configuration.getTimeout()).thenReturn(100L);1131 when(messageEndpoint.getActor()).thenReturn(null);1132 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));1133 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {1134 @Override1135 public void execute() {1136 receive(action -> action.endpoint(messageEndpoint)1137 .messageType(MessageType.PLAINTEXT)1138 .payload("TestMessage")1139 .header("operation", "sayHello")1140 .validationCallback(callback));1141 }1142 };1143 TestCase test = builder.getTestCase();1144 Assert.assertEquals(test.getActionCount(), 1);1145 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1146 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1147 Assert.assertEquals(action.getName(), "receive");1148 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1149 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());1150 Assert.assertEquals(action.getValidationCallback(), callback);1151 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1152 Assert.assertEquals(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getPayloadData(), "TestMessage");1153 Assert.assertTrue(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));1154 verify(callback).setApplicationContext(applicationContext);1155 verify(callback).validate(any(Message.class), any(TestContext.class));1156 }1157 @Test1158 public void testReceiveBuilderWithValidatonScript() {1159 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1160 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);1161 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1162 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1163 when(configuration.getTimeout()).thenReturn(100L);1164 when(messageEndpoint.getActor()).thenReturn(null);1165 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("{\"message\": \"Hello Citrus!\"}").setHeader("operation", "sayHello"));1166 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));1167 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1168 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());...
Source:AbstractValidationCallback.java
...45 /**46 * Sets the applicationContext.47 * @param applicationContext the applicationContext to set48 */49 public void setApplicationContext(ApplicationContext applicationContext) {50 this.applicationContext = applicationContext;51 }52}...
setApplicationContext
Using AI Code Generation
1package com.consol.citrus;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.ws.client.WebServiceClient;5import com.consol.citrus.ws.validation.callback.AbstractValidationCallback;6import org.springframework.context.ApplicationContext;7import org.springframework.context.ApplicationContextAware;8import org.testng.annotations.Test;9public class Test4 extends TestNGCitrusTestDesigner {10 public void test4() {11 variable("user", "citrus:concat('Hello ', citrus:randomNumber(3))");12 variable("password", "citrus:randomNumber(4)");13 WebServiceClient webServiceClient = new WebServiceClient();14 webServiceClient.setApplicationContext(applicationContext);15 webServiceClient.setValidationCallback(new AbstractValidationCallback() {16 public void validateMessage(TestRunner runner, String message) {17 System.out.println("Received message: " + message);18 }19 });20 send(webServiceClient)21 "</ns0:HelloWorldRequest>");22 }23}24package com.consol.citrus;25import com.consol.citrus.dsl.builder.Builder;26import com.consol.citrus.dsl.runner.TestRunner;27import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;28import com.consol.citrus.ws.client.WebServiceClient;29import org.springframework.context.ApplicationContext;30import org.springframework.context.ApplicationContextAware;31import org.testng.annotations.Test;32public class Test5 extends TestNGCitrusTestDesigner {33 public void test5() {34 variable("user", "citrus:concat('Hello ', citrus:randomNumber(3))");35 variable("password", "citrus:randomNumber(4)");36 WebServiceClient webServiceClient = new WebServiceClient();37 webServiceClient.setApplicationContext(applicationContext);
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2import org.springframework.context.ApplicationContext;3import org.testng.annotations.Test;4public class Test4 {5 public void test1() {6 AbstractValidationCallback abstractValidationCallback = new AbstractValidationCallback();7 abstractValidationCallback.setApplicationContext(new ApplicationContext() {8 public String getId() {9 return null;10 }11 public String getApplicationName() {12 return null;13 }14 public String getDisplayName() {15 return null;16 }17 public long getStartupDate() {18 return 0;19 }20 public ApplicationContext getParent() {21 return null;22 }23 public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {24 return null;25 }26 public BeanFactory getParentBeanFactory() {27 return null;28 }29 public boolean containsLocalBean(String s) {30 return false;31 }32 public boolean containsBeanDefinition(String s) {33 return false;34 }35 public int getBeanDefinitionCount() {36 return 0;37 }38 public String[] getBeanDefinitionNames() {39 return new String[0];40 }41 public String[] getBeanNamesForType(ResolvableType resolvableType) {42 return new String[0];43 }44 public String[] getBeanNamesForType(ResolvableType resolvableType, boolean b, boolean b1) {45 return new String[0];46 }47 public String[] getBeanNamesForType(Class<?> aClass) {48 return new String[0];49 }50 public String[] getBeanNamesForType(Class<?> aClass, boolean b, boolean b1) {51 return new String[0];52 }53 public <T> Map<String, T> getBeansOfType(Class<T> aClass) throws BeansException {54 return null;55 }56 public <T> Map<String, T> getBeansOfType(Class<T> aClass, boolean b, boolean b1) throws BeansException {57 return null;58 }
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2import org.springframework.context.ApplicationContext;3import org.springframework.context.ApplicationContextAware;4public abstract class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {5 protected ApplicationContext applicationContext;6 public void setApplicationContext(ApplicationContext applicationContext) {7 this.applicationContext = applicationContext;8 }9}10package com.consol.citrus.validation.callback;11import org.springframework.context.ApplicationContext;12import org.springframework.context.ApplicationContextAware;13public abstract class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {14 protected ApplicationContext applicationContext;15 public void setApplicationContext(ApplicationContext applicationContext) {16 this.applicationContext = applicationContext;17 }18}19package com.consol.citrus.validation.callback;20import org.springframework.context.ApplicationContext;21import org.springframework.context.ApplicationContextAware;22public abstract class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {23 protected ApplicationContext applicationContext;24 public void setApplicationContext(ApplicationContext applicationContext) {25 this.applicationContext = applicationContext;26 }27}28package com.consol.citrus.validation.callback;29import org.springframework.context.ApplicationContext;30import org.springframework.context.ApplicationContextAware;31public abstract class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {32 protected ApplicationContext applicationContext;33 public void setApplicationContext(ApplicationContext applicationContext) {34 this.applicationContext = applicationContext;35 }36}37package com.consol.citrus.validation.callback;38import org.springframework.context.ApplicationContext;39import org.springframework.context.ApplicationContextAware;40public abstract class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {41 protected ApplicationContext applicationContext;42 public void setApplicationContext(ApplicationContext applicationContext) {43 this.applicationContext = applicationContext;44 }45}
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2public class AbstractValidationCallback {3public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {4}5}6package org.springframework.beans.factory.config;7public class AutowireCapableBeanFactory {8public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {9}10}11package org.springframework.beans.factory.support;12public class AbstractBeanFactory {13public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {14}15}16package org.springframework.beans.factory.support;17public class DefaultListableBeanFactory {18public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {19}20}21package org.springframework.beans.factory.support;22public class DefaultSingletonBeanRegistry {23public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {24}25}26package org.springframework.beans.factory.support;27public class AbstractAutowireCapableBeanFactory {28public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {29}30}31package org.springframework.beans.factory.support;32public class AbstractBeanDefinition {33public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {34}35}36package org.springframework.beans.factory.support;37public class AbstractBeanDefinition {38public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {39}40}41package org.springframework.beans.factory.support;42public class AbstractBeanDefinition {43public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {44}45}
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2import org.springframework.context.ApplicationContext;3public class AbstractValidationCallback {4public void setApplicationContext(ApplicationContext applicationContext) {5this.applicationContext = applicationContext; }6}7package com.consol.citrus.validation.callback;8import org.springframework.context.ApplicationContext;9public class AbstractValidationCallback {10public void setApplicationContext(ApplicationContext applicationContext) {11this.applicationContext = applicationContext; }12}13package com.consol.citrus.validation.callback;14import org.springframework.context.ApplicationContext;15public class AbstractValidationCallback {16public void setApplicationContext(ApplicationContext applicationContext) {17this.applicationContext = applicationContext; }18}19package com.consol.citrus.validation.callback;20import org.springframework.context.ApplicationContext;21public class AbstractValidationCallback {22public void setApplicationContext(ApplicationContext applicationContext) {23this.applicationContext = applicationContext; }24}25package com.consol.citrus.validation.callback;26import org.springframework.context.ApplicationContext;27public class AbstractValidationCallback {28public void setApplicationContext(ApplicationContext applicationContext) {29this.applicationContext = applicationContext; }30}31package com.consol.citrus.validation.callback;32import org.springframework.context.ApplicationContext;33public class AbstractValidationCallback {34public void setApplicationContext(ApplicationContext applicationContext) {35this.applicationContext = applicationContext; }36}37package com.consol.citrus.validation.callback;38import org.springframework.context.ApplicationContext;39public class AbstractValidationCallback {40public void setApplicationContext(ApplicationContext applicationContext) {41this.applicationContext = applicationContext; }42}43package com.consol.citrus.validation.callback;44import org.springframework.context.ApplicationContext;
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.samples;2import org.springframework.context.ApplicationContext;3import org.springframework.context.support.ClassPathXmlApplicationContext;4import org.testng.annotations.Test;5import com.consol.citrus.annotations.CitrusResource;6import com.consol.citrus.annotations.CitrusTest;7import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;8import com.consol.citrus.dsl.validation.ValidationCallback;9import com.consol.citrus.http.client.HttpClient;10import com.consol.citrus.validation.callback.AbstractValidationCallback;11import com.consol.citrus.xml.XsdSchemaRepository;12import com.consol.citrus.xml.namespace.NamespaceContextBuilder;13public class ValidationCallbackTest extends TestNGCitrusTestDesigner {14 private final XsdSchemaRepository schemaRepository = new XsdSchemaRepository();15 private final NamespaceContextBuilder namespaceContextBuilder = new NamespaceContextBuilder();16 private final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");17 private HttpClient httpClient;18 public void validateXmlResponse() {19 http(httpClient)20 .send()21 .post("/services/hello")22 "</HelloRequest>");23 http(httpClient)24 .receive()25 .validationCallback(new AbstractValidationCallback() {26 public void validateMessage(String message, ValidationContext context) {27 schemaRepository.setApplicationContext(applicationContext);28 namespaceContextBuilder.setApplicationContext(applicationContext);29 super.validateMessage(message, context);30 }31 })32 "</HelloResponse>");33 }34}
setApplicationContext
Using AI Code Generation
1public class MyValidationCallback extends AbstractValidationCallback {2 private ApplicationContext applicationContext;3 public MyValidationCallback() {4 super();5 }6 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {7 this.applicationContext = applicationContext;8 }9}10public class MyValidationCallback extends AbstractValidationCallback {11 private ApplicationContext applicationContext;12 public MyValidationCallback() {13 super();14 }15 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {16 this.applicationContext = applicationContext;17 }18}19public class MyValidationCallback extends AbstractValidationCallback {20 private ApplicationContext applicationContext;21 public MyValidationCallback() {22 super();23 }24 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {25 this.applicationContext = applicationContext;26 }27}28public class MyValidationCallback extends AbstractValidationCallback {29 private ApplicationContext applicationContext;30 public MyValidationCallback() {31 super();32 }33 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {34 this.applicationContext = applicationContext;35 }36}37public class MyValidationCallback extends AbstractValidationCallback {38 private ApplicationContext applicationContext;39 public MyValidationCallback() {40 super();41 }42 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {43 this.applicationContext = applicationContext;44 }45}46public class MyValidationCallback extends AbstractValidationCallback {47 private ApplicationContext applicationContext;48 public MyValidationCallback() {49 super();50 }51 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2import org.springframework.beans.factory.annotation.Autowired;3import org.springframework.context.ApplicationContext;4import org.springframework.context.ApplicationContextAware;5import org.springframework.context.ConfigurableApplicationContext;6import org.springframework.stereotype.Component;7public class AbstractValidationCallback implements ApplicationContextAware {8 private ConfigurableApplicationContext applicationContext;9 public void setApplicationContext(ApplicationContext applicationContext) {10 this.applicationContext = (ConfigurableApplicationContext) applicationContext;11 }12}13package com.consol.citrus.validation.callback;14import org.springframework.context.ApplicationContext;15import org.springframework.context.ApplicationContextAware;16import org.springframework.context.ConfigurableApplicationContext;17import org.springframework.stereotype.Component;18public class AbstractValidationCallback implements ApplicationContextAware {19 private ConfigurableApplicationContext applicationContext;20 public void setApplicationContext(ApplicationContext applicationContext) {21 this.applicationContext = (ConfigurableApplicationContext) applicationContext;22 }23}24package com.consol.citrus.validation.callback;25import org.springframework.beans.factory.annotation.Autowired;26import org.springframework.context.ApplicationContext;27import org.springframework.context.ApplicationContextAware;28import org.springframework.context.ConfigurableApplicationContext;29import org.springframework.stereotype.Component;30public class AbstractValidationCallback implements ApplicationContextAware {31 private ConfigurableApplicationContext applicationContext;32 public void setApplicationContext(ApplicationContext applicationContext) {33 this.applicationContext = (ConfigurableApplicationContext) applicationContext;34 }35}36package com.consol.citrus.validation.callback;37import org.springframework.context.ApplicationContext;38import org.springframework.context.ApplicationContextAware;39import org.springframework.context.ConfigurableApplicationContext;40import org.springframework.stereotype.Component;41public class AbstractValidationCallback implements ApplicationContextAware {42 private ConfigurableApplicationContext applicationContext;43 public void setApplicationContext(ApplicationContext applicationContext) {44 this.applicationContext = (ConfigurableApplicationContext) applicationContext;45 }46}
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2import org.springframework.context.ApplicationContext;3import org.springframework.context.ApplicationContextAware;4public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {5private ApplicationContext applicationContext;6public void setApplicationContext(ApplicationContext applicationContext) {7this.applicationContext = applicationContext;8}9}10package com.consol.citrus.validation.callback;11import org.springframework.context.ApplicationContext;12import org.springframework.context.ApplicationContextAware;13public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {14private ApplicationContext applicationContext;15public void setApplicationContext(ApplicationContext applicationContext) {16this.applicationContext = applicationContext;17}18}19package com.consol.citrus.validation.callback;20import org.springframework.context.ApplicationContext;21import org.springframework.context.ApplicationContextAware;22public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {23private ApplicationContext applicationContext;24public void setApplicationContext(ApplicationContext applicationContext) {25this.applicationContext = applicationContext;26}27}28package com.consol.citrus.validation.callback;29import org.springframework.context.ApplicationContext;30import org.springframework.context.ApplicationContextAware;31public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {32private ApplicationContext applicationContext;33public void setApplicationContext(ApplicationContext applicationContext) {34this.applicationContext = applicationContext;35}36}37package com.consol.citrus.validation.callback;38import org.springframework.context.ApplicationContext;39import org.springframework.context.ApplicationContextAware;40public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {41private ApplicationContext applicationContext;42public void setApplicationContext(ApplicationContext applicationContext) {43this.applicationContext = applicationContext;44}45}
setApplicationContext
Using AI Code Generation
1 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {2 this.applicationContext = applicationContext;3 }4}5public class MyValidationCallback extends AbstractValidationCallback {6 private ApplicationContext applicationContext;7 public MyValidationCallback() {8 super();9 }10 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {11 this.applicationContext = applicationContext;12 }13}14public class MyValidationCallback extends AbstractValidationCallback {15 private ApplicationContext applicationContext;16 public MyValidationCallback() {17 super();18 }19 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {20 this.applicationContext = applicationContext;21 }22}23public class MyValidationCallback extends AbstractValidationCallback {24 private ApplicationContext applicationContext;25 public MyValidationCallback() {26 super();27 }28 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {29 this.applicationContext = applicationContext;30 }31}32public class MyValidationCallback extends AbstractValidationCallback {33 private ApplicationContext applicationContext;34 public MyValidationCallback() {35 super();36 }37 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {38 this.applicationContext = applicationContext;39 }40}41public class MyValidationCallback extends AbstractValidationCallback {42 private ApplicationContext applicationContext;43 public MyValidationCallback() {44 super();45 }46 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2import org.springframework.beans.factory.annotation.Autowired;3import org.springframework.context.ApplicationContext;4import org.springframework.context.ApplicationContextAware;5import org.springframework.context.ConfigurableApplicationContext;6import org.springframework.stereotype.Component;7public class AbstractValidationCallback implements ApplicationContextAware {8 private ConfigurableApplicationContext applicationContext;9 public void setApplicationContext(ApplicationContext applicationContext) {10 this.applicationContext = (ConfigurableApplicationContext) applicationContext;11 }12}13package com.consol.citrus.validation.callback;14import org.springframework.context.ApplicationContext;15import org.springframework.context.ApplicationContextAware;16import org.springframework.context.ConfigurableApplicationContext;17import org.springframework.stereotype.Component;18public class AbstractValidationCallback implements ApplicationContextAware {19 private ConfigurableApplicationContext applicationContext;20 public void setApplicationContext(ApplicationContext applicationContext) {21 this.applicationContext = (ConfigurableApplicationContext) applicationContext;22 }23}24package com.consol.citrus.validation.callback;25import org.springframework.beans.factory.annotation.Autowired;26import org.springframework.context.ApplicationContext;27import org.springframework.context.ApplicationContextAware;28import org.springframework.context.ConfigurableApplicationContext;29import org.springframework.stereotype.Component;30public class AbstractValidationCallback implements ApplicationContextAware {31 private ConfigurableApplicationContext applicationContext;32 public void setApplicationContext(ApplicationContext applicationContext) {33 this.applicationContext = (ConfigurableApplicationContext) applicationContext;34 }35}36package com.consol.citrus.validation.callback;37import org.springframework.context.ApplicationContext;38import org.springframework.context.ApplicationContextAware;39import org.springframework.context.ConfigurableApplicationContext;40import org.springframework.stereotype.Component;41public class AbstractValidationCallback implements ApplicationContextAware {42 private ConfigurableApplicationContext applicationContext;43 public void setApplicationContext(ApplicationContext applicationContext) {44 this.applicationContext = (ConfigurableApplicationContext) applicationContext;45 }46}
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2import org.springframework.context.ApplicationContext;3import org.springframework.context.ApplicationContextAware;4public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {5private ApplicationContext applicationContext;6public void setApplicationContext(ApplicationContext applicationContext) {7this.applicationContext = applicationContext;8}9}10package com.consol.citrus.validation.callback;11import org.springframework.context.ApplicationContext;12import org.springframework.context.ApplicationContextAware;13public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {14private ApplicationContext applicationContext;15public void setApplicationContext(ApplicationContext applicationContext) {16this.applicationContext = applicationContext;17}18}19package com.consol.citrus.validation.callback;20import org.springframework.context.ApplicationContext;21import org.springframework.context.ApplicationContextAware;22public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {23private ApplicationContext applicationContext;24public void setApplicationContext(ApplicationContext applicationContext) {25this.applicationContext = applicationContext;26}27}28package com.consol.citrus.validation.callback;29import org.springframework.context.ApplicationContext;30import org.springframework.context.ApplicationContextAware;31public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {32private ApplicationContext applicationContext;33public void setApplicationContext(ApplicationContext applicationContext) {34this.applicationContext = applicationContext;35}36}37package com.consol.citrus.validation.callback;38import org.springframework.context.ApplicationContext;39import org.springframework.context.ApplicationContextAware;40public class AbstractValidationCallback implements ValidationCallback, ApplicationContextAware {41private ApplicationContext applicationContext;42public void setApplicationContext(ApplicationContext applicationContext) {43this.applicationContext = applicationContext;44}45}
setApplicationContext
Using AI Code Generation
1this.applicationContext = applicationContext; }2}3package com.consol.citrus.validation.callback;4import org.springframework.context.ApplicationContext;5public class AbstractValidationCallback {6public void setApplicationContext(ApplicationContext applicationContext) {7this.applicationContext = applicationContext; }8}9package com.consol.citrus.validation.callback;10import org.springframework.context.ApplicationContext;
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.samples;2import org.springframework.context.ApplicationContext;3import org.springframework.context.support.ClassPathXmlApplicationContext;4import org.testng.annotations.Test;5import com.consol.citrus.annotations.CitrusResource;6import com.consol.citrus.annotations.CitrusTest;7import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;8import com.consol.citrus.dsl.validation.ValidationCallback;9import com.consol.citrus.http.client.HttpClient;10import com.consol.citrus.validation.callback.AbstractValidationCallback;11import com.consol.citrus.xml.XsdSchemaRepository;12import com.consol.citrus.xml.namespace.NamespaceContextBuilder;13public class ValidationCallbackTest extends TestNGCitrusTestDesigner {14 private final XsdSchemaRepository schemaRepository = new XsdSchemaRepository();15 private final NamespaceContextBuilder namespaceContextBuilder = new NamespaceContextBuilder();16 private final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");17 private HttpClient httpClient;18 public void validateXmlResponse() {19 http(httpClient)20 .send()21 .post("/services/hello")22 "</HelloRequest>");23 http(httpClient)24 .receive()25 .validationCallback(new AbstractValidationCallback() {26 public void validateMessage(String message, ValidationContext context) {27 schemaRepository.setApplicationContext(applicationContext);28 namespaceContextBuilder.setApplicationContext(applicationContext);29 super.validateMessage(message, context);30 }31 })32 "</HelloResponse>");33 }34}
setApplicationContext
Using AI Code Generation
1package com.consol.citrus.validation.callback;2import org.springframework.beans.factory.annotation.Autowired;3import org.springframework.context.ApplicationContext;4import org.springframework.context.ApplicationContextAware;5import org.springframework.context.ConfigurableApplicationContext;6import org.springframework.stereotype.Component;7public class AbstractValidationCallback implements ApplicationContextAware {8 private ConfigurableApplicationContext applicationContext;9 public void setApplicationContext(ApplicationContext applicationContext) {10 this.applicationContext = (ConfigurableApplicationContext) applicationContext;11 }12}13package com.consol.citrus.validation.callback;14import org.springframework.context.ApplicationContext;15import org.springframework.context.ApplicationContextAware;16import org.springframework.context.ConfigurableApplicationContext;17import org.springframework.stereotype.Component;18public class AbstractValidationCallback implements ApplicationContextAware {19 private ConfigurableApplicationContext applicationContext;20 public void setApplicationContext(ApplicationContext applicationContext) {21 this.applicationContext = (ConfigurableApplicationContext) applicationContext;22 }23}24package com.consol.citrus.validation.callback;25import org.springframework.beans.factory.annotation.Autowired;26import org.springframework.context.ApplicationContext;27import org.springframework.context.ApplicationContextAware;28import org.springframework.context.ConfigurableApplicationContext;29import org.springframework.stereotype.Component;30public class AbstractValidationCallback implements ApplicationContextAware {31 private ConfigurableApplicationContext applicationContext;32 public void setApplicationContext(ApplicationContext applicationContext) {33 this.applicationContext = (ConfigurableApplicationContext) applicationContext;34 }35}36package com.consol.citrus.validation.callback;37import org.springframework.context.ApplicationContext;38import org.springframework.context.ApplicationContextAware;39import org.springframework.context.ConfigurableApplicationContext;40import org.springframework.stereotype.Component;41public class AbstractValidationCallback implements ApplicationContextAware {42 private ConfigurableApplicationContext applicationContext;43 public void setApplicationContext(ApplicationContext applicationContext) {44 this.applicationContext = (ConfigurableApplicationContext) applicationContext;45 }46}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!