Best Citrus code snippet using com.consol.citrus.dsl.design.SendMessageTestDesignerTest.configure
Source:SendMessageTestDesignerTest.java
...68 @Test69 public void testSendBuilderWithMessageInstance() {70 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {71 @Override72 public void configure() {73 send(messageEndpoint)74 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))75 .header("additional", "additionalValue");76 }77 };78 builder.configure();79 final TestCase test = builder.getTestCase();80 Assert.assertEquals(test.getActionCount(), 1);81 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);82 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);83 84 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();85 Assert.assertEquals(action.getName(), "send");86 87 Assert.assertEquals(action.getEndpoint(), messageEndpoint);88 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);89 90 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();91 Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");92 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");93 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");94 }95 @Test96 public void testSendBuilderWithObjectMessageInstance() {97 final Message message = new DefaultMessage(10).setHeader("operation", "foo");98 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {99 @Override100 public void configure() {101 send(messageEndpoint)102 .message(message);103 }104 };105 builder.configure();106 final TestCase test = builder.getTestCase();107 Assert.assertEquals(test.getActionCount(), 1);108 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);109 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);110 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();111 Assert.assertEquals(action.getName(), "send");112 Assert.assertEquals(action.getEndpoint(), messageEndpoint);113 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);114 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();115 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);116 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);117 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());118 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));119 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");120 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());121 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 1);122 Assert.assertEquals(constructed.getHeader("operation"), "foo");123 Assert.assertEquals(constructed.getHeader(MessageHeaders.MESSAGE_TYPE), MessageType.PLAINTEXT.name());124 Assert.assertNotEquals(constructed.getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));125 }126 @Test127 public void testSendBuilderWithObjectMessageInstanceAdditionalHeader() {128 final Message message = new DefaultMessage(10).setHeader("operation", "foo");129 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {130 @Override131 public void configure() {132 send(messageEndpoint)133 .message(message)134 .header("additional", "new");135 }136 };137 builder.configure();138 final TestCase test = builder.getTestCase();139 Assert.assertEquals(test.getActionCount(), 1);140 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);141 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);142 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();143 Assert.assertEquals(action.getName(), "send");144 Assert.assertEquals(action.getEndpoint(), messageEndpoint);145 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);146 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();147 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);148 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);149 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "new");150 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());151 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));152 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");153 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());154 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 2);155 Assert.assertEquals(constructed.getHeader("operation"), "foo");156 Assert.assertEquals(constructed.getHeader("additional"), "new");157 Assert.assertEquals(constructed.getHeader(MessageHeaders.MESSAGE_TYPE), MessageType.PLAINTEXT.name());158 }159 @Test160 public void testSendBuilderWithPayloadModel() {161 reset(applicationContextMock);162 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());163 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());164 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());165 when(applicationContextMock.getBeansOfType(Marshaller.class)).thenReturn(Collections.singletonMap("marshaller", marshaller));166 when(applicationContextMock.getBean(Marshaller.class)).thenReturn(marshaller);167 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {168 @Override169 public void configure() {170 send(messageEndpoint)171 .payloadModel(new TestRequest("Hello Citrus!"));172 }173 };174 builder.configure();175 final TestCase test = builder.getTestCase();176 Assert.assertEquals(test.getActionCount(), 1);177 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);178 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);179 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();180 Assert.assertEquals(action.getName(), "send");181 Assert.assertEquals(action.getEndpoint(), messageEndpoint);182 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);183 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();184 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");185 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);186 }187 @Test188 public void testSendBuilderWithPayloadModelExplicitMarshaller() {189 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {190 @Override191 public void configure() {192 send(messageEndpoint)193 .payload(new TestRequest("Hello Citrus!"), marshaller);194 }195 };196 builder.configure();197 final TestCase test = builder.getTestCase();198 Assert.assertEquals(test.getActionCount(), 1);199 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);200 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);201 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();202 Assert.assertEquals(action.getName(), "send");203 Assert.assertEquals(action.getEndpoint(), messageEndpoint);204 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);205 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();206 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");207 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);208 }209 @Test210 public void testSendBuilderWithPayloadModelExplicitMarshallerName() {211 reset(applicationContextMock);212 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());213 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());214 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());215 when(applicationContextMock.containsBean("myMarshaller")).thenReturn(true);216 when(applicationContextMock.getBean("myMarshaller")).thenReturn(marshaller);217 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {218 @Override219 public void configure() {220 send(messageEndpoint)221 .payload(new TestRequest("Hello Citrus!"), "myMarshaller");222 }223 };224 builder.configure();225 final TestCase test = builder.getTestCase();226 Assert.assertEquals(test.getActionCount(), 1);227 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);228 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);229 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();230 Assert.assertEquals(action.getName(), "send");231 Assert.assertEquals(action.getEndpoint(), messageEndpoint);232 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);233 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();234 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");235 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);236 }237 238 @Test239 public void testSendBuilderWithPayloadData() {240 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {241 @Override242 public void configure() {243 send(messageEndpoint)244 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");245 }246 };247 builder.configure();248 final TestCase test = builder.getTestCase();249 Assert.assertEquals(test.getActionCount(), 1);250 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);251 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);252 253 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();254 Assert.assertEquals(action.getName(), "send");255 256 Assert.assertEquals(action.getEndpoint(), messageEndpoint);257 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);258 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();259 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");260 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);261 }262 @Test263 public void testSendBuilderWithPayloadResource() throws IOException {264 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {265 @Override266 public void configure() {267 send(messageEndpoint)268 .payload(resource);269 }270 };271 272 reset(resource);273 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("somePayloadData".getBytes()));274 builder.configure();275 final TestCase test = builder.getTestCase();276 Assert.assertEquals(test.getActionCount(), 1);277 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);278 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);279 280 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();281 Assert.assertEquals(action.getName(), "send");282 283 Assert.assertEquals(action.getEndpoint(), messageEndpoint);284 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);285 286 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();287 Assert.assertEquals(messageBuilder.getPayloadData(), "somePayloadData");288 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);289 }290 291 @Test292 public void testSendBuilderWithEndpointName() {293 reset(applicationContextMock);294 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());295 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());296 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());297 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {298 @Override299 public void configure() {300 send("fooMessageEndpoint")301 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");302 }303 };304 builder.configure();305 final TestCase test = builder.getTestCase();306 Assert.assertEquals(test.getActionCount(), 1);307 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);308 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);309 310 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();311 Assert.assertEquals(action.getName(), "send");312 Assert.assertEquals(action.getEndpointUri(), "fooMessageEndpoint");313 }314 315 @Test316 public void testSendBuilderWithHeaders() {317 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {318 @Override319 public void configure() {320 send(messageEndpoint)321 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")322 .headers(Collections.singletonMap("some", "value"))323 .header("operation", "foo")324 .header("language", "eng");325 }326 };327 builder.configure();328 final TestCase test = builder.getTestCase();329 Assert.assertEquals(test.getActionCount(), 1);330 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);331 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);332 333 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();334 Assert.assertEquals(action.getName(), "send");335 336 Assert.assertEquals(action.getEndpoint(), messageEndpoint);337 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);338 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();339 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");340 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 3L);341 Assert.assertEquals(messageBuilder.getMessageHeaders().get("some"), "value");342 Assert.assertEquals(messageBuilder.getMessageHeaders().get("operation"), "foo");343 Assert.assertEquals(messageBuilder.getMessageHeaders().get("language"), "eng");344 }345 346 @Test347 public void testSendBuilderWithHeaderData() {348 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {349 @Override350 public void configure() {351 send(messageEndpoint)352 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")353 .header("<Header><Name>operation</Name><Value>foo</Value></Header>");354 355 send(messageEndpoint)356 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))357 .header("<Header><Name>operation</Name><Value>foo</Value></Header>");358 }359 };360 builder.configure();361 final TestCase test = builder.getTestCase();362 Assert.assertEquals(test.getActionCount(), 2);363 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);364 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);365 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);366 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);367 368 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();369 Assert.assertEquals(action.getName(), "send");370 371 Assert.assertEquals(action.getEndpoint(), messageEndpoint);372 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);373 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();374 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");375 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);376 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);377 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");378 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);379 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();380 Assert.assertEquals(action.getName(), "send");381 Assert.assertEquals(action.getEndpoint(), messageEndpoint);382 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);383 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();384 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");385 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);386 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);387 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");388 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);389 }390 @Test391 public void testSendBuilderWithMultipleHeaderData() {392 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {393 @Override394 public void configure() {395 send(messageEndpoint)396 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")397 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")398 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");399 send(messageEndpoint)400 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))401 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")402 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");403 }404 };405 builder.configure();406 final TestCase test = builder.getTestCase();407 Assert.assertEquals(test.getActionCount(), 2);408 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);409 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);410 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);411 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);412 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();413 Assert.assertEquals(action.getName(), "send");414 Assert.assertEquals(action.getEndpoint(), messageEndpoint);415 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);416 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();417 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");418 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);419 Assert.assertEquals(messageBuilder.getHeaderData().size(), 2L);420 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");421 Assert.assertEquals(messageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");422 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);423 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();424 Assert.assertEquals(action.getName(), "send");425 Assert.assertEquals(action.getEndpoint(), messageEndpoint);426 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);427 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();428 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");429 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);430 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 2L);431 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");432 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");433 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);434 }435 436 @Test437 public void testSendBuilderWithHeaderDataResource() throws IOException {438 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {439 @Override440 public void configure() {441 send(messageEndpoint)442 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")443 .header(resource);444 445 send(messageEndpoint)446 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))447 .header(resource);448 }449 };450 451 reset(resource);452 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someHeaderData".getBytes()))453 .thenReturn(new ByteArrayInputStream("otherHeaderData".getBytes()));454 builder.configure();455 final TestCase test = builder.getTestCase();456 Assert.assertEquals(test.getActionCount(), 2);457 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);458 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);459 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);460 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);461 462 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();463 Assert.assertEquals(action.getName(), "send");464 465 Assert.assertEquals(action.getEndpoint(), messageEndpoint);466 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);467 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();468 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");469 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);470 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);471 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "someHeaderData");472 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);473 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();474 Assert.assertEquals(action.getName(), "send");475 Assert.assertEquals(action.getEndpoint(), messageEndpoint);476 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);477 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();478 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");479 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);480 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);481 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "otherHeaderData");482 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);483 }484 485 @Test486 public void testSendBuilderExtractFromPayload() {487 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {488 @Override489 public void configure() {490 send(messageEndpoint)491 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")492 .extractFromPayload("/TestRequest/Message", "text")493 .extractFromPayload("/TestRequest/Message/@lang", "language");494 }495 };496 builder.configure();497 final TestCase test = builder.getTestCase();498 Assert.assertEquals(test.getActionCount(), 1);499 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);500 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);501 502 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();503 Assert.assertEquals(action.getName(), "send");504 505 Assert.assertEquals(action.getEndpoint(), messageEndpoint);506 507 Assert.assertEquals(action.getVariableExtractors().size(), 1);508 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);509 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message"));510 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));511 }512 @Test513 public void testSendBuilderExtractJsonPathFromPayload() {514 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {515 @Override516 public void configure() {517 send(messageEndpoint)518 .messageType(MessageType.JSON)519 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")520 .extractFromPayload("$.text", "text")521 .extractFromPayload("$.person", "language");522 }523 };524 builder.configure();525 final TestCase test = builder.getTestCase();526 Assert.assertEquals(test.getActionCount(), 1);527 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);528 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);529 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();530 Assert.assertEquals(action.getName(), "send");531 Assert.assertEquals(action.getEndpoint(), messageEndpoint);532 Assert.assertEquals(action.getVariableExtractors().size(), 1);533 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);534 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.text"));535 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.person"));536 }537 538 @Test539 public void testSendBuilderExtractFromHeader() {540 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {541 @Override542 public void configure() {543 send(messageEndpoint)544 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")545 .extractFromHeader("operation", "ops")546 .extractFromHeader("requestId", "id");547 }548 };549 builder.configure();550 final TestCase test = builder.getTestCase();551 Assert.assertEquals(test.getActionCount(), 1);552 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);553 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);554 555 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();556 Assert.assertEquals(action.getName(), "send");557 558 Assert.assertEquals(action.getEndpoint(), messageEndpoint);559 560 Assert.assertEquals(action.getVariableExtractors().size(), 1);561 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);562 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));563 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));564 }565 @Test566 public void testXpathSupport() {567 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {568 @Override569 public void configure() {570 send(messageEndpoint)571 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")572 .xpath("/TestRequest/Message", "Hello World!");573 }574 };575 builder.configure();576 final TestCase test = builder.getTestCase();577 Assert.assertEquals(test.getActionCount(), 1);578 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);579 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);580 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();581 Assert.assertEquals(action.getName(), "send");582 Assert.assertEquals(action.getEndpoint(), messageEndpoint);583 Assert.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);584 Assert.assertEquals(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().size(), 1);585 Assert.assertTrue(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0) instanceof XpathMessageConstructionInterceptor);586 Assert.assertEquals(((XpathMessageConstructionInterceptor)((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)).getXPathExpressions().get("/TestRequest/Message"), "Hello World!");587 }588 @Test589 public void testJsonPathSupport() {590 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {591 @Override592 public void configure() {593 send(messageEndpoint)594 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")595 .jsonPath("$.TestRequest.Message", "Hello World!");596 }597 };598 builder.configure();599 final TestCase test = builder.getTestCase();600 Assert.assertEquals(test.getActionCount(), 1);601 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);602 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);603 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();604 Assert.assertEquals(action.getName(), "send");605 Assert.assertEquals(action.getEndpoint(), messageEndpoint);606 Assert.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);607 Assert.assertEquals(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().size(), 1);608 Assert.assertTrue(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0) instanceof JsonPathMessageConstructionInterceptor);609 Assert.assertEquals(((JsonPathMessageConstructionInterceptor)((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)).getJsonPathExpressions().get("$.TestRequest.Message"), "Hello World!");610 }611 @Test612 public void testSendBuilderWithDictionary() {613 final DataDictionary dictionary = new NodeMappingDataDictionary();614 reset(applicationContextMock);615 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());616 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());617 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());618 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {619 @Override620 public void configure() {621 send(messageEndpoint)622 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")623 .dictionary(dictionary);624 }625 };626 builder.configure();627 final TestCase test = builder.getTestCase();628 Assert.assertEquals(test.getActionCount(), 1);629 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);630 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);631 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();632 Assert.assertEquals(action.getName(), "send");633 Assert.assertEquals(action.getEndpoint(), messageEndpoint);634 Assert.assertEquals(action.getDataDictionary(), dictionary);635 }636 @Test637 public void testSendBuilderWithDictionaryName() {638 final DataDictionary dictionary = new NodeMappingDataDictionary();639 reset(applicationContextMock);640 when(applicationContextMock.getBean("customDictionary", DataDictionary.class)).thenReturn(dictionary);641 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());642 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());643 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());644 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {645 @Override646 public void configure() {647 send(messageEndpoint)648 .payload("TestMessage")649 .header("operation", "sayHello")650 .dictionary("customDictionary");651 }652 };653 builder.configure();654 final TestCase test = builder.getTestCase();655 Assert.assertEquals(test.getActionCount(), 1);656 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);657 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);658 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();659 Assert.assertEquals(action.getName(), "send");660 Assert.assertEquals(action.getEndpoint(), messageEndpoint);661 Assert.assertEquals(action.getDataDictionary(), dictionary);662 }663}...
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!!