Best Citrus code snippet using com.consol.citrus.dsl.runner.SendMessageTestRunnerTest.execute
Source:SendMessageTestRunnerTest.java
...83 return null;84 }).when(messageProducer).send(any(Message.class), any(TestContext.class));85 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {86 @Override87 public void execute() {88 send(builder -> builder.endpoint(messageEndpoint)89 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))90 .header("additional", "additionalValue"));91 }92 };93 final TestCase test = builder.getTestCase();94 Assert.assertEquals(test.getActionCount(), 1);95 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);96 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));97 Assert.assertEquals(action.getName(), "send");98 Assert.assertEquals(action.getEndpoint(), messageEndpoint);99 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);100 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();101 Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");102 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");103 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");104 }105 @Test106 public void testSendBuilderWithObjectMessageInstance() {107 reset(messageEndpoint, messageProducer);108 when(messageEndpoint.createProducer()).thenReturn(messageProducer);109 when(messageEndpoint.getActor()).thenReturn(null);110 doAnswer(invocation -> {111 Message message = (Message) invocation.getArguments()[0];112 Assert.assertEquals(message.getPayload(Integer.class), new Integer(10));113 Assert.assertNotNull(message.getHeader("operation"));114 Assert.assertEquals(message.getHeader("operation"), "foo");115 return null;116 }).when(messageProducer).send(any(Message.class), any(TestContext.class));117 final Message message = new DefaultMessage(10).setHeader("operation", "foo");118 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {119 @Override120 public void execute() {121 send(builder -> builder.endpoint(messageEndpoint)122 .message(message));123 }124 };125 final TestCase test = builder.getTestCase();126 Assert.assertEquals(test.getActionCount(), 1);127 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);128 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));129 Assert.assertEquals(action.getName(), "send");130 Assert.assertEquals(action.getEndpoint(), messageEndpoint);131 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);132 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();133 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);134 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);135 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());136 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));137 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");138 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());139 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 1);140 Assert.assertEquals(constructed.getHeader("operation"), "foo");141 Assert.assertNotEquals(constructed.getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));142 }143 @Test144 public void testSendBuilderWithObjectMessageInstanceAdditionalHeader() {145 reset(messageEndpoint, messageProducer);146 when(messageEndpoint.createProducer()).thenReturn(messageProducer);147 when(messageEndpoint.getActor()).thenReturn(null);148 doAnswer(invocation -> {149 Message message = (Message) invocation.getArguments()[0];150 Assert.assertEquals(message.getPayload(Integer.class), new Integer(10));151 Assert.assertNotNull(message.getHeader("operation"));152 Assert.assertEquals(message.getHeader("operation"), "foo");153 Assert.assertNotNull(message.getHeader("additional"));154 Assert.assertEquals(message.getHeader("additional"), "new");155 return null;156 }).when(messageProducer).send(any(Message.class), any(TestContext.class));157 final Message message = new DefaultMessage(10).setHeader("operation", "foo");158 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {159 @Override160 public void execute() {161 send(builder -> builder.endpoint(messageEndpoint)162 .message(message)163 .header("additional", "new"));164 }165 };166 final TestCase test = builder.getTestCase();167 Assert.assertEquals(test.getActionCount(), 1);168 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);169 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));170 Assert.assertEquals(action.getName(), "send");171 Assert.assertEquals(action.getEndpoint(), messageEndpoint);172 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);173 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();174 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);175 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);176 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "new");177 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());178 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));179 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");180 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());181 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 2);182 Assert.assertEquals(constructed.getHeader("operation"), "foo");183 Assert.assertEquals(constructed.getHeader("additional"), "new");184 }185 @Test186 public void testSendBuilderWithPayloadModel() {187 reset(applicationContextMock, messageEndpoint, messageProducer);188 when(messageEndpoint.createProducer()).thenReturn(messageProducer);189 when(messageEndpoint.getActor()).thenReturn(null);190 doAnswer(invocation -> {191 Message message = (Message) invocation.getArguments()[0];192 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");193 return null;194 }).when(messageProducer).send(any(Message.class), any(TestContext.class));195 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));196 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());197 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());198 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());199 when(applicationContextMock.getBeansOfType(Marshaller.class)).thenReturn(Collections.singletonMap("marshaller", marshaller));200 when(applicationContextMock.getBean(Marshaller.class)).thenReturn(marshaller);201 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {202 @Override203 public void execute() {204 send(builder -> builder.endpoint(messageEndpoint)205 .payloadModel(new TestRequest("Hello Citrus!")));206 }207 };208 final TestCase test = builder.getTestCase();209 Assert.assertEquals(test.getActionCount(), 1);210 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);211 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));212 Assert.assertEquals(action.getName(), "send");213 Assert.assertEquals(action.getEndpoint(), messageEndpoint);214 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);215 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();216 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");217 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);218 }219 @Test220 public void testSendBuilderWithPayloadModelExplicitMarshaller() {221 reset(messageEndpoint, messageProducer);222 when(messageEndpoint.createProducer()).thenReturn(messageProducer);223 when(messageEndpoint.getActor()).thenReturn(null);224 doAnswer(invocation -> {225 Message message = (Message) invocation.getArguments()[0];226 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");227 return null;228 }).when(messageProducer).send(any(Message.class), any(TestContext.class));229 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {230 @Override231 public void execute() {232 send(builder -> builder.endpoint(messageEndpoint)233 .payload(new TestRequest("Hello Citrus!"), marshaller));234 }235 };236 final TestCase test = builder.getTestCase();237 Assert.assertEquals(test.getActionCount(), 1);238 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);239 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));240 Assert.assertEquals(action.getName(), "send");241 Assert.assertEquals(action.getEndpoint(), messageEndpoint);242 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);243 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();244 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");245 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);246 }247 @Test248 public void testSendBuilderWithPayloadModelExplicitMarshallerName() {249 reset(applicationContextMock, messageEndpoint, messageProducer);250 when(messageEndpoint.createProducer()).thenReturn(messageProducer);251 when(messageEndpoint.getActor()).thenReturn(null);252 doAnswer(invocation -> {253 Message message = (Message) invocation.getArguments()[0];254 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");255 return null;256 }).when(messageProducer).send(any(Message.class), any(TestContext.class));257 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));258 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());259 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());260 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());261 when(applicationContextMock.containsBean("myMarshaller")).thenReturn(true);262 when(applicationContextMock.getBean("myMarshaller")).thenReturn(marshaller);263 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {264 @Override265 public void execute() {266 send(builder -> builder.endpoint(messageEndpoint)267 .payload(new TestRequest("Hello Citrus!"), "myMarshaller"));268 }269 };270 final TestCase test = builder.getTestCase();271 Assert.assertEquals(test.getActionCount(), 1);272 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);273 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));274 Assert.assertEquals(action.getName(), "send");275 Assert.assertEquals(action.getEndpoint(), messageEndpoint);276 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);277 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();278 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");279 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);280 }281 282 @Test283 public void testSendBuilderWithPayloadData() {284 reset(messageEndpoint, messageProducer);285 when(messageEndpoint.createProducer()).thenReturn(messageProducer);286 when(messageEndpoint.getActor()).thenReturn(null);287 doAnswer(invocation -> {288 Message message = (Message) invocation.getArguments()[0];289 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");290 return null;291 }).when(messageProducer).send(any(Message.class), any(TestContext.class));292 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {293 @Override294 public void execute() {295 send(builder -> builder.endpoint(messageEndpoint)296 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>"));297 }298 };299 final TestCase test = builder.getTestCase();300 Assert.assertEquals(test.getActionCount(), 1);301 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);302 303 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));304 Assert.assertEquals(action.getName(), "send");305 306 Assert.assertEquals(action.getEndpoint(), messageEndpoint);307 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);308 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();309 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");310 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);311 }312 @Test313 public void testSendBuilderWithPayloadResource() throws IOException {314 reset(resource, messageEndpoint, messageProducer);315 when(messageEndpoint.createProducer()).thenReturn(messageProducer);316 when(messageEndpoint.getActor()).thenReturn(null);317 doAnswer(invocation -> {318 Message message = (Message) invocation.getArguments()[0];319 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");320 return null;321 }).when(messageProducer).send(any(Message.class), any(TestContext.class));322 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("<TestRequest><Message>Hello World!</Message></TestRequest>".getBytes()));323 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {324 @Override325 public void execute() {326 send(builder -> builder.endpoint(messageEndpoint)327 .payload(resource));328 }329 };330 final TestCase test = builder.getTestCase();331 Assert.assertEquals(test.getActionCount(), 1);332 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);333 334 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));335 Assert.assertEquals(action.getName(), "send");336 337 Assert.assertEquals(action.getEndpoint(), messageEndpoint);338 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);339 340 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();341 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");342 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);343 }344 345 @Test346 public void testSendBuilderWithEndpointName() {347 final TestContext context = applicationContext.getBean(TestContext.class);348 context.setApplicationContext(applicationContextMock);349 reset(applicationContextMock, messageEndpoint, messageProducer);350 when(messageEndpoint.createProducer()).thenReturn(messageProducer);351 when(messageEndpoint.getActor()).thenReturn(null);352 doAnswer(invocation -> {353 Message message = (Message) invocation.getArguments()[0];354 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");355 return null;356 }).when(messageProducer).send(any(Message.class), any(TestContext.class));357 when(applicationContextMock.getBean(TestContext.class)).thenReturn(context);358 when(applicationContextMock.getBean("fooMessageEndpoint", Endpoint.class)).thenReturn(messageEndpoint);359 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());360 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());361 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());362 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {363 @Override364 public void execute() {365 send(builder -> builder.endpoint("fooMessageEndpoint")366 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>"));367 }368 };369 final TestCase test = builder.getTestCase();370 Assert.assertEquals(test.getActionCount(), 1);371 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);372 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));373 Assert.assertEquals(action.getName(), "send");374 Assert.assertEquals(action.getEndpointUri(), "fooMessageEndpoint");375 }376 377 @Test378 public void testSendBuilderWithHeaders() {379 reset(messageEndpoint, messageProducer);380 when(messageEndpoint.createProducer()).thenReturn(messageProducer);381 when(messageEndpoint.getActor()).thenReturn(null);382 doAnswer(invocation -> {383 Message message = (Message) invocation.getArguments()[0];384 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");385 Assert.assertNotNull(message.getHeader("operation"));386 Assert.assertEquals(message.getHeader("operation"), "foo");387 Assert.assertNotNull(message.getHeader("language"));388 Assert.assertEquals(message.getHeader("language"), "eng");389 return null;390 }).when(messageProducer).send(any(Message.class), any(TestContext.class));391 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {392 @Override393 public void execute() {394 send(builder -> builder.endpoint(messageEndpoint)395 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")396 .headers(Collections.singletonMap("some", "value"))397 .header("operation", "foo")398 .header("language", "eng"));399 }400 };401 final TestCase test = builder.getTestCase();402 Assert.assertEquals(test.getActionCount(), 1);403 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);404 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));405 Assert.assertEquals(action.getName(), "send");406 Assert.assertEquals(action.getEndpoint(), messageEndpoint);407 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);408 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();409 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");410 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 3L);411 Assert.assertEquals(messageBuilder.getMessageHeaders().get("some"), "value");412 Assert.assertEquals(messageBuilder.getMessageHeaders().get("operation"), "foo");413 Assert.assertEquals(messageBuilder.getMessageHeaders().get("language"), "eng");414 }415 416 @Test417 public void testSendBuilderWithHeaderData() {418 reset(messageEndpoint, messageProducer);419 when(messageEndpoint.createProducer()).thenReturn(messageProducer);420 when(messageEndpoint.getActor()).thenReturn(null);421 doAnswer(invocation -> {422 Message message = (Message) invocation.getArguments()[0];423 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");424 Assert.assertNotNull(message.getHeaderData());425 Assert.assertEquals(message.getHeaderData().size(), 1L);426 Assert.assertEquals(message.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");427 return null;428 }).when(messageProducer).send(any(Message.class), any(TestContext.class));429 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {430 @Override431 public void execute() {432 send(builder -> builder.endpoint(messageEndpoint)433 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")434 .header("<Header><Name>operation</Name><Value>foo</Value></Header>"));435 436 send(builder -> builder.endpoint(messageEndpoint)437 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))438 .header("<Header><Name>operation</Name><Value>foo</Value></Header>"));439 }440 };441 final TestCase test = builder.getTestCase();442 Assert.assertEquals(test.getActionCount(), 2);443 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);444 Assert.assertEquals(test.getActions().get(1).getClass(), SendMessageAction.class);445 446 SendMessageAction action = ((SendMessageAction)test.getActions().get(0));447 Assert.assertEquals(action.getName(), "send");448 449 Assert.assertEquals(action.getEndpoint(), messageEndpoint);450 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);451 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();452 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");453 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);454 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);455 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");456 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);457 action = ((SendMessageAction)test.getActions().get(1));458 Assert.assertEquals(action.getName(), "send");459 Assert.assertEquals(action.getEndpoint(), messageEndpoint);460 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);461 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();462 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");463 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);464 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);465 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");466 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);467 }468 @Test469 public void testSendBuilderWithMultipleHeaderData() {470 reset(messageEndpoint, messageProducer);471 when(messageEndpoint.createProducer()).thenReturn(messageProducer);472 when(messageEndpoint.getActor()).thenReturn(null);473 doAnswer(invocation -> {474 Message message = (Message) invocation.getArguments()[0];475 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");476 Assert.assertNotNull(message.getHeaderData());477 Assert.assertEquals(message.getHeaderData().size(), 2L);478 Assert.assertEquals(message.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");479 Assert.assertEquals(message.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");480 return null;481 }).when(messageProducer).send(any(Message.class), any(TestContext.class));482 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {483 @Override484 public void execute() {485 send(builder -> builder.endpoint(messageEndpoint)486 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")487 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")488 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>"));489 send(builder -> builder.endpoint(messageEndpoint)490 .message(new DefaultMessage("<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 }494 };495 final TestCase test = builder.getTestCase();496 Assert.assertEquals(test.getActionCount(), 2);497 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);498 Assert.assertEquals(test.getActions().get(1).getClass(), SendMessageAction.class);499 SendMessageAction action = ((SendMessageAction)test.getActions().get(0));500 Assert.assertEquals(action.getName(), "send");501 Assert.assertEquals(action.getEndpoint(), messageEndpoint);502 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);503 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();504 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");505 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);506 Assert.assertEquals(messageBuilder.getHeaderData().size(), 2L);507 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");508 Assert.assertEquals(messageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");509 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);510 action = ((SendMessageAction)test.getActions().get(1));511 Assert.assertEquals(action.getName(), "send");512 Assert.assertEquals(action.getEndpoint(), messageEndpoint);513 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);514 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();515 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");516 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);517 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 2L);518 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");519 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");520 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);521 }522 523 @Test524 public void testSendBuilderWithHeaderDataResource() throws IOException {525 reset(resource, messageEndpoint, messageProducer);526 when(messageEndpoint.createProducer()).thenReturn(messageProducer);527 when(messageEndpoint.getActor()).thenReturn(null);528 doAnswer(invocation -> {529 Message message = (Message) invocation.getArguments()[0];530 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");531 Assert.assertNotNull(message.getHeaderData());532 Assert.assertEquals(message.getHeaderData().size(), 1L);533 Assert.assertEquals(message.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");534 return null;535 }).doAnswer(invocation -> {536 Message message = (Message) invocation.getArguments()[0];537 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");538 Assert.assertNotNull(message.getHeaderData());539 Assert.assertEquals(message.getHeaderData().size(), 1L);540 Assert.assertEquals(message.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo2</Value></Header>");541 return null;542 }).when(messageProducer).send(any(Message.class), any(TestContext.class));543 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>foo1</Value></Header>".getBytes()))544 .thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>foo2</Value></Header>".getBytes()));545 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {546 @Override547 public void execute() {548 send(builder -> builder.endpoint(messageEndpoint)549 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")550 .header(resource));551 send(builder -> builder.endpoint(messageEndpoint)552 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))553 .header(resource));554 }555 };556 final TestCase test = builder.getTestCase();557 Assert.assertEquals(test.getActionCount(), 2);558 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);559 Assert.assertEquals(test.getActions().get(1).getClass(), SendMessageAction.class);560 561 SendMessageAction action = ((SendMessageAction)test.getActions().get(0));562 Assert.assertEquals(action.getName(), "send");563 564 Assert.assertEquals(action.getEndpoint(), messageEndpoint);565 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);566 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();567 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");568 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);569 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);570 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");571 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);572 action = ((SendMessageAction)test.getActions().get(1));573 Assert.assertEquals(action.getName(), "send");574 Assert.assertEquals(action.getEndpoint(), messageEndpoint);575 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);576 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();577 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");578 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);579 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);580 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo2</Value></Header>");581 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);582 }583 584 @Test585 public void testSendBuilderExtractFromPayload() {586 reset(messageEndpoint, messageProducer);587 when(messageEndpoint.createProducer()).thenReturn(messageProducer);588 when(messageEndpoint.getActor()).thenReturn(null);589 doAnswer(invocation -> {590 Message message = (Message) invocation.getArguments()[0];591 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>");592 return null;593 }).when(messageProducer).send(any(Message.class), any(TestContext.class));594 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {595 @Override596 public void execute() {597 send(builder -> builder.endpoint(messageEndpoint)598 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")599 .extractFromPayload("/TestRequest/Message", "text")600 .extractFromPayload("/TestRequest/Message/@lang", "language"));601 }602 };603 final TestContext context = builder.getTestContext();604 Assert.assertNotNull(context.getVariable("text"));605 Assert.assertNotNull(context.getVariable("language"));606 Assert.assertEquals(context.getVariable("text"), "Hello World!");607 Assert.assertEquals(context.getVariable("language"), "ENG");608 final TestCase test = builder.getTestCase();609 Assert.assertEquals(test.getActionCount(), 1);610 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);611 612 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));613 Assert.assertEquals(action.getName(), "send");614 615 Assert.assertEquals(action.getEndpoint(), messageEndpoint);616 617 Assert.assertEquals(action.getVariableExtractors().size(), 1);618 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);619 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message"));620 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));621 }622 @Test623 public void testSendBuilderExtractJsonPathFromPayload() {624 reset(messageEndpoint, messageProducer);625 when(messageEndpoint.createProducer()).thenReturn(messageProducer);626 when(messageEndpoint.getActor()).thenReturn(null);627 doAnswer(invocation -> {628 Message message = (Message) invocation.getArguments()[0];629 Assert.assertEquals(message.getPayload(String.class), "{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");630 return null;631 }).when(messageProducer).send(any(Message.class), any(TestContext.class));632 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {633 @Override634 public void execute() {635 send(builder -> builder.endpoint(messageEndpoint)636 .messageType(MessageType.JSON)637 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")638 .extractFromPayload("$.text", "text")639 .extractFromPayload("$.person", "person"));640 }641 };642 final TestContext context = builder.getTestContext();643 Assert.assertNotNull(context.getVariable("text"));644 Assert.assertNotNull(context.getVariable("person"));645 Assert.assertEquals(context.getVariable("text"), "Hello World!");646 Assert.assertTrue(context.getVariable("person").contains("\"John\""));647 final TestCase test = builder.getTestCase();648 Assert.assertEquals(test.getActionCount(), 1);649 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);650 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));651 Assert.assertEquals(action.getName(), "send");652 Assert.assertEquals(action.getEndpoint(), messageEndpoint);653 Assert.assertEquals(action.getVariableExtractors().size(), 1);654 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);655 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.text"));656 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.person"));657 }658 659 @Test660 public void testSendBuilderExtractFromHeader() {661 reset(messageEndpoint, messageProducer);662 when(messageEndpoint.createProducer()).thenReturn(messageProducer);663 when(messageEndpoint.getActor()).thenReturn(null);664 doAnswer(invocation -> {665 Message message = (Message) invocation.getArguments()[0];666 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>");667 return null;668 }).when(messageProducer).send(any(Message.class), any(TestContext.class));669 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {670 @Override671 public void execute() {672 send(builder -> builder.endpoint(messageEndpoint)673 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")674 .header("operation", "sayHello")675 .header("requestId", "123456")676 .extractFromHeader("operation", "operationHeader")677 .extractFromHeader("requestId", "id"));678 }679 };680 final TestContext context = builder.getTestContext();681 Assert.assertNotNull(context.getVariable("operationHeader"));682 Assert.assertNotNull(context.getVariable("id"));683 Assert.assertEquals(context.getVariable("operationHeader"), "sayHello");684 Assert.assertEquals(context.getVariable("id"), "123456");685 final TestCase test = builder.getTestCase();686 Assert.assertEquals(test.getActionCount(), 1);687 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);688 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));689 Assert.assertEquals(action.getName(), "send");690 Assert.assertEquals(action.getEndpoint(), messageEndpoint);691 Assert.assertEquals(action.getVariableExtractors().size(), 1);692 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);693 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));694 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));695 }696 @Test697 public void testXpathSupport() {698 reset(messageEndpoint, messageProducer);699 when(messageEndpoint.createProducer()).thenReturn(messageProducer);700 when(messageEndpoint.getActor()).thenReturn(null);701 doAnswer(invocation -> {702 Message message = (Message) invocation.getArguments()[0];703 Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),704 "<?xmlversion=\"1.0\"encoding=\"UTF-8\"?><TestRequest><Messagelang=\"ENG\">HelloWorld!</Message></TestRequest>");705 return null;706 }).when(messageProducer).send(any(Message.class), any(TestContext.class));707 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {708 @Override709 public void execute() {710 send(builder -> builder.endpoint(messageEndpoint)711 .payload("<TestRequest><Message lang=\"ENG\">?</Message></TestRequest>")712 .xpath("/TestRequest/Message", "Hello World!"));713 }714 };715 final TestCase test = builder.getTestCase();716 Assert.assertEquals(test.getActionCount(), 1);717 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);718 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));719 Assert.assertEquals(action.getName(), "send");720 Assert.assertEquals(action.getEndpoint(), messageEndpoint);721 Assert.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);722 Assert.assertEquals(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().size(), 1);723 Assert.assertTrue(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0) instanceof XpathMessageConstructionInterceptor);724 Assert.assertEquals(((XpathMessageConstructionInterceptor)((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)).getXPathExpressions().get("/TestRequest/Message"), "Hello World!");725 }726 @Test727 public void testJsonPathSupport() {728 reset(messageEndpoint, messageProducer);729 when(messageEndpoint.createProducer()).thenReturn(messageProducer);730 when(messageEndpoint.getActor()).thenReturn(null);731 doAnswer(invocation -> {732 Message message = (Message) invocation.getArguments()[0];733 Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),734 "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");735 return null;736 }).when(messageProducer).send(any(Message.class), any(TestContext.class));737 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {738 @Override739 public void execute() {740 send(builder -> builder.endpoint(messageEndpoint)741 .messageType(MessageType.JSON)742 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")743 .jsonPath("$.TestRequest.Message", "Hello World!"));744 }745 };746 final TestCase test = builder.getTestCase();747 Assert.assertEquals(test.getActionCount(), 1);748 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);749 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));750 Assert.assertEquals(action.getName(), "send");751 Assert.assertEquals(action.getEndpoint(), messageEndpoint);752 Assert.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);753 Assert.assertEquals(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().size(), 1);754 Assert.assertTrue(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0) instanceof JsonPathMessageConstructionInterceptor);755 Assert.assertEquals(((JsonPathMessageConstructionInterceptor)((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)).getJsonPathExpressions().get("$.TestRequest.Message"), "Hello World!");756 }757 @Test758 public void testSendBuilderWithDictionary() {759 final JsonMappingDataDictionary dictionary = new JsonMappingDataDictionary();760 dictionary.getMappings().put("TestRequest.Message", "Hello World!");761 reset(messageEndpoint, messageProducer);762 when(messageEndpoint.createProducer()).thenReturn(messageProducer);763 when(messageEndpoint.getActor()).thenReturn(null);764 doAnswer(invocation -> {765 Message message = (Message) invocation.getArguments()[0];766 Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),767 "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");768 return null;769 }).when(messageProducer).send(any(Message.class), any(TestContext.class));770 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {771 @Override772 public void execute() {773 send(builder -> builder.endpoint(messageEndpoint)774 .messageType(MessageType.JSON)775 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")776 .dictionary(dictionary));777 }778 };779 final TestCase test = builder.getTestCase();780 Assert.assertEquals(test.getActionCount(), 1);781 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);782 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));783 Assert.assertEquals(action.getName(), "send");784 Assert.assertEquals(action.getEndpoint(), messageEndpoint);785 Assert.assertEquals(action.getDataDictionary(), dictionary);786 }787 @Test788 public void testSendBuilderWithDictionaryName() {789 final JsonMappingDataDictionary dictionary = new JsonMappingDataDictionary();790 dictionary.getMappings().put("TestRequest.Message", "Hello World!");791 reset(applicationContextMock, messageEndpoint, messageProducer);792 when(messageEndpoint.createProducer()).thenReturn(messageProducer);793 when(messageEndpoint.getActor()).thenReturn(null);794 doAnswer(invocation -> {795 Message message = (Message) invocation.getArguments()[0];796 Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),797 "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");798 return null;799 }).when(messageProducer).send(any(Message.class), any(TestContext.class));800 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));801 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());802 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());803 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());804 when(applicationContextMock.getBean("customDictionary", DataDictionary.class)).thenReturn(dictionary);805 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {806 @Override807 public void execute() {808 send(builder -> builder.endpoint(messageEndpoint)809 .messageType(MessageType.JSON)810 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")811 .dictionary("customDictionary"));812 }813 };814 final TestCase test = builder.getTestCase();815 Assert.assertEquals(test.getActionCount(), 1);816 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);817 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));818 Assert.assertEquals(action.getName(), "send");819 Assert.assertEquals(action.getEndpoint(), messageEndpoint);820 Assert.assertEquals(action.getDataDictionary(), dictionary);821 }...
execute
Using AI Code Generation
1execute(sendMessage()2 .endpoint(soapClient)3 "</ns0:hello>"));4execute(sendMessage()5 .endpoint(soapClient)6 .header("operation", "sayHello"));7execute(sendMessage()8 .endpoint(soapClient)9 .header("operation", "sayHello")10 .header("citrus_soap_action", "sayHello"));11execute(sendMessage()12 .endpoint(soapClient)13 .header("operation", "sayHello")14 .header("citrus_soap_action", "sayHello")15 .header("citrus_jms_correlation_id", "1234567890"));16execute(sendMessage()17 .endpoint(soapClient)18 .header("operation", "sayHello")19 .header("citrus_soap_action", "sayHello")20 .header("citrus_jms_correlation_id", "1234567890")21 .header("citrus_http_method", "POST"));22execute(sendMessage()23 .endpoint(soapClient)24 .payload("<ns0:hello xmlns:ns
execute
Using AI Code Generation
1[2019-07-18T11:43:39,960] []: import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner2[2019-07-18T11:43:39,960] []: import com.consol.citrus.dsl.runner.SendMessageTestRunnerTest.SendAction3[2019-07-18T11:43:39,960] []: class SendMessageTestRunnerTest extends JUnit4CitrusTestRunner {4[2019-07-18T11:43:39,960] []: void execute() {5[2019-07-18T11:43:39,960] []: send(new SendAction())6[2019-07-18T11:43:39,960] []: }7[2019-07-18T11:43:39,960] []: static class SendAction implements com.consol.citrus.actions.SendMessageAction {8[2019-07-18T11:43:39,960] []: void setEndpoint(com.consol.citrus.endpoint.Endpoint endpoint) {
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!!