How to use testSendMessageWithMessagePayloadResource method of com.consol.citrus.actions.SendMessageActionTest class

Best Citrus code snippet using com.consol.citrus.actions.SendMessageActionTest.testSendMessageWithMessagePayloadResource

Source:SendMessageActionTest.java Github

copy

Full Screen

...80 }81 82 @Test83 @SuppressWarnings("rawtypes")84 public void testSendMessageWithMessagePayloadResource() {85 SendMessageAction sendAction = new SendMessageAction();86 sendAction.setEndpoint(endpoint);87 88 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();89 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload.xml");90 91 sendAction.setMessageBuilder(messageBuilder);92 93 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");94 reset(endpoint, producer, endpointConfiguration);95 when(endpoint.createProducer()).thenReturn(producer);96 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);97 doAnswer(new Answer() {98 @Override99 public Object answer(InvocationOnMock invocation) throws Throwable {100 DomXmlMessageValidator validator = new DomXmlMessageValidator();101 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();102 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);103 return null;104 }105 }).when(producer).send(any(Message.class), any(TestContext.class));106 when(endpoint.getActor()).thenReturn(null);107 108 sendAction.execute(context);109 }110 111 @Test112 @SuppressWarnings("rawtypes")113 public void testSendMessageWithMessageBuilderScriptData() {114 SendMessageAction sendAction = new SendMessageAction();115 sendAction.setEndpoint(endpoint);116 StringBuilder sb = new StringBuilder();117 sb.append("markupBuilder.TestRequest(){\n");118 sb.append("Message('Hello World!')\n");119 sb.append("}");120 121 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();122 scriptMessageBuidler.setScriptData(sb.toString());123 124 sendAction.setMessageBuilder(scriptMessageBuidler);125 126 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");127 reset(endpoint, producer, endpointConfiguration);128 when(endpoint.createProducer()).thenReturn(producer);129 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);130 doAnswer(new Answer() {131 @Override132 public Object answer(InvocationOnMock invocation) throws Throwable {133 DomXmlMessageValidator validator = new DomXmlMessageValidator();134 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();135 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);136 return null;137 }138 }).when(producer).send(any(Message.class), any(TestContext.class));139 when(endpoint.getActor()).thenReturn(null);140 141 sendAction.execute(context);142 }143 144 @Test145 @SuppressWarnings("rawtypes")146 public void testSendMessageWithMessageBuilderScriptDataVariableSupport() {147 context.setVariable("text", "Hello World!");148 149 SendMessageAction sendAction = new SendMessageAction();150 sendAction.setEndpoint(endpoint);151 StringBuilder sb = new StringBuilder();152 sb.append("markupBuilder.TestRequest(){\n");153 sb.append("Message('${text}')\n");154 sb.append("}");155 156 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();157 scriptMessageBuidler.setScriptData(sb.toString());158 159 sendAction.setMessageBuilder(scriptMessageBuidler);160 161 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");162 reset(endpoint, producer, endpointConfiguration);163 when(endpoint.createProducer()).thenReturn(producer);164 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);165 doAnswer(new Answer() {166 @Override167 public Object answer(InvocationOnMock invocation) throws Throwable {168 DomXmlMessageValidator validator = new DomXmlMessageValidator();169 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();170 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);171 return null;172 }173 }).when(producer).send(any(Message.class), any(TestContext.class));174 when(endpoint.getActor()).thenReturn(null);175 176 sendAction.execute(context);177 }178 179 @Test180 @SuppressWarnings("rawtypes")181 public void testSendMessageWithMessageBuilderScriptResource() {182 SendMessageAction sendAction = new SendMessageAction();183 sendAction.setEndpoint(endpoint);184 185 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();186 scriptMessageBuidler.setScriptResourcePath("classpath:com/consol/citrus/actions/test-request-payload.groovy");187 188 sendAction.setMessageBuilder(scriptMessageBuidler);189 190 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");191 reset(endpoint, producer, endpointConfiguration);192 when(endpoint.createProducer()).thenReturn(producer);193 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);194 doAnswer(new Answer() {195 @Override196 public Object answer(InvocationOnMock invocation) throws Throwable {197 DomXmlMessageValidator validator = new DomXmlMessageValidator();198 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();199 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);200 return null;201 }202 }).when(producer).send(any(Message.class), any(TestContext.class));203 when(endpoint.getActor()).thenReturn(null);204 205 sendAction.execute(context);206 }207 208 @Test209 @SuppressWarnings("rawtypes")210 public void testSendMessageWithMessagePayloadDataVariablesSupport() {211 SendMessageAction sendAction = new SendMessageAction();212 sendAction.setEndpoint(endpoint);213 214 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();215 messageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");216 217 sendAction.setMessageBuilder(messageBuilder);218 219 context.setVariable("myText", "Hello World!");220 221 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");222 reset(endpoint, producer, endpointConfiguration);223 when(endpoint.createProducer()).thenReturn(producer);224 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);225 doAnswer(new Answer() {226 @Override227 public Object answer(InvocationOnMock invocation) throws Throwable {228 DomXmlMessageValidator validator = new DomXmlMessageValidator();229 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();230 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);231 return null;232 }233 }).when(producer).send(any(Message.class), any(TestContext.class));234 when(endpoint.getActor()).thenReturn(null);235 236 sendAction.execute(context);237 }238 239 @Test240 @SuppressWarnings("rawtypes")241 public void testSendMessageWithMessagePayloadResourceVariablesSupport() {242 SendMessageAction sendAction = new SendMessageAction();243 sendAction.setEndpoint(endpoint);244 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();245 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload-with-variables.xml");246 247 sendAction.setMessageBuilder(messageBuilder);248 249 context.setVariable("myText", "Hello World!");250 251 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");252 reset(endpoint, producer, endpointConfiguration);253 when(endpoint.createProducer()).thenReturn(producer);254 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);255 doAnswer(new Answer() {256 @Override257 public Object answer(InvocationOnMock invocation) throws Throwable {258 DomXmlMessageValidator validator = new DomXmlMessageValidator();259 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();260 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);261 return null;262 }263 }).when(producer).send(any(Message.class), any(TestContext.class));264 when(endpoint.getActor()).thenReturn(null);265 266 sendAction.execute(context);267 }268 269 @Test270 @SuppressWarnings("rawtypes")271 public void testSendMessageWithMessagePayloadResourceFunctionsSupport() {272 SendMessageAction sendAction = new SendMessageAction();273 sendAction.setEndpoint(endpoint);274 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();275 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload-with-functions.xml");276 277 sendAction.setMessageBuilder(messageBuilder);278 279 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");280 reset(endpoint, producer, endpointConfiguration);281 when(endpoint.createProducer()).thenReturn(producer);282 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);283 doAnswer(new Answer() {284 @Override285 public Object answer(InvocationOnMock invocation) throws Throwable {286 DomXmlMessageValidator validator = new DomXmlMessageValidator();287 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();288 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);289 return null;290 }291 }).when(producer).send(any(Message.class), any(TestContext.class));292 when(endpoint.getActor()).thenReturn(null);293 294 sendAction.execute(context);295 }296 297 @Test298 @SuppressWarnings("rawtypes")299 public void testSendMessageOverwriteMessageElementsXPath() {300 SendMessageAction sendAction = new SendMessageAction();301 sendAction.setEndpoint(endpoint);302 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();303 messageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>");304 305 Map<String, String> overwriteElements = new HashMap<String, String>();306 overwriteElements.put("/TestRequest/Message", "Hello World!");307 308 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);309 messageBuilder.add(interceptor);310 311 sendAction.setMessageBuilder(messageBuilder);312 313 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");314 reset(endpoint, producer, endpointConfiguration);315 when(endpoint.createProducer()).thenReturn(producer);316 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);317 doAnswer(new Answer() {318 @Override319 public Object answer(InvocationOnMock invocation) throws Throwable {320 DomXmlMessageValidator validator = new DomXmlMessageValidator();321 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();322 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);323 return null;324 }325 }).when(producer).send(any(Message.class), any(TestContext.class));326 when(endpoint.getActor()).thenReturn(null);327 328 sendAction.execute(context);329 }330 @Test331 @SuppressWarnings("rawtypes")332 public void testSendMessageOverwriteMessageElementsJsonPath() {333 SendMessageAction sendAction = new SendMessageAction();334 sendAction.setMessageType(MessageType.JSON.toString());335 sendAction.setEndpoint(endpoint);336 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();337 messageBuilder.setPayloadData("{ \"TestRequest\": { \"Message\": \"?\" }}");338 Map<String, String> overwriteElements = new HashMap<String, String>();339 overwriteElements.put("$.TestRequest.Message", "Hello World!");340 JsonPathMessageConstructionInterceptor interceptor = new JsonPathMessageConstructionInterceptor(overwriteElements);341 messageBuilder.add(interceptor);342 sendAction.setMessageBuilder(messageBuilder);343 final Message controlMessage = new DefaultMessage("{ \"TestRequest\": { \"Message\": \"Hello World!\" }}");344 reset(endpoint, producer, endpointConfiguration);345 when(endpoint.createProducer()).thenReturn(producer);346 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);347 doAnswer(new Answer() {348 @Override349 public Object answer(InvocationOnMock invocation) throws Throwable {350 JsonTextMessageValidator validator = new JsonTextMessageValidator();351 JsonMessageValidationContext validationContext = new JsonMessageValidationContext();352 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);353 return null;354 }355 }).when(producer).send(any(Message.class), any(TestContext.class));356 when(endpoint.getActor()).thenReturn(null);357 sendAction.execute(context);358 }359 360 @Test361 @SuppressWarnings("rawtypes")362 public void testSendMessageOverwriteMessageElementsDotNotation() {363 SendMessageAction sendAction = new SendMessageAction();364 sendAction.setEndpoint(endpoint);365 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();366 messageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>");367 368 Map<String, String> overwriteElements = new HashMap<String, String>();369 overwriteElements.put("TestRequest.Message", "Hello World!");370 371 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);372 messageBuilder.add(interceptor);373 374 sendAction.setMessageBuilder(messageBuilder);375 376 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");377 reset(endpoint, producer, endpointConfiguration);378 when(endpoint.createProducer()).thenReturn(producer);379 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);380 doAnswer(new Answer() {381 @Override382 public Object answer(InvocationOnMock invocation) throws Throwable {383 DomXmlMessageValidator validator = new DomXmlMessageValidator();384 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();385 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);386 return null;387 }388 }).when(producer).send(any(Message.class), any(TestContext.class));389 when(endpoint.getActor()).thenReturn(null);390 391 sendAction.execute(context);392 }393 394 @Test395 @SuppressWarnings("rawtypes")396 public void testSendMessageOverwriteMessageElementsXPathWithNamespace() {397 SendMessageAction sendAction = new SendMessageAction();398 sendAction.setEndpoint(endpoint);399 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();400 messageBuilder.setPayloadData("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +401 "<ns0:Message>?</ns0:Message></ns0:TestRequest>");402 403 Map<String, String> overwriteElements = new HashMap<String, String>();404 overwriteElements.put("/ns0:TestRequest/ns0:Message", "Hello World!");405 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);406 messageBuilder.add(interceptor);407 408 sendAction.setMessageBuilder(messageBuilder);409 410 final Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\"><ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");411 reset(endpoint, producer, endpointConfiguration);412 when(endpoint.createProducer()).thenReturn(producer);413 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);414 doAnswer(new Answer() {415 @Override416 public Object answer(InvocationOnMock invocation) throws Throwable {417 DomXmlMessageValidator validator = new DomXmlMessageValidator();418 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();419 validationContext.setSchemaValidation(false);420 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);421 return null;422 }423 }).when(producer).send(any(Message.class), any(TestContext.class));424 when(endpoint.getActor()).thenReturn(null);425 426 sendAction.execute(context);427 }428 429 @Test430 @SuppressWarnings("rawtypes")431 public void testSendMessageOverwriteMessageElementsXPathWithDefaultNamespace() {432 SendMessageAction sendAction = new SendMessageAction();433 sendAction.setEndpoint(endpoint);434 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();435 messageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +436 "<Message>?</Message></TestRequest>");437 438 Map<String, String> overwriteElements = new HashMap<String, String>();439 overwriteElements.put("/:TestRequest/:Message", "Hello World!");440 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);441 messageBuilder.add(interceptor);442 443 sendAction.setMessageBuilder(messageBuilder);444 445 final Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\"><Message>Hello World!</Message></TestRequest>");446 reset(endpoint, producer, endpointConfiguration);447 when(endpoint.createProducer()).thenReturn(producer);448 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);449 doAnswer(new Answer() {450 @Override451 public Object answer(InvocationOnMock invocation) throws Throwable {452 DomXmlMessageValidator validator = new DomXmlMessageValidator();453 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();454 validationContext.setSchemaValidation(false);455 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);456 return null;457 }458 }).when(producer).send(any(Message.class), any(TestContext.class));459 when(endpoint.getActor()).thenReturn(null);460 461 sendAction.execute(context);462 }463 464 @Test465 @SuppressWarnings("rawtypes")466 public void testSendMessageWithMessageHeaders() {467 SendMessageAction sendAction = new SendMessageAction();468 sendAction.setEndpoint(endpoint);469 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();470 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");471 472 final Map<String, Object> controlHeaders = new HashMap<String, Object>();473 controlHeaders.put("Operation", "sayHello");474 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);475 final Map<String, Object> headers = new HashMap<String, Object>();476 headers.put("Operation", "sayHello");477 messageBuilder.setMessageHeaders(headers);478 479 sendAction.setMessageBuilder(messageBuilder);480 reset(endpoint, producer, endpointConfiguration);481 when(endpoint.createProducer()).thenReturn(producer);482 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);483 doAnswer(new Answer() {484 @Override485 public Object answer(InvocationOnMock invocation) throws Throwable {486 DomXmlMessageValidator validator = new DomXmlMessageValidator();487 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();488 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);489 return null;490 }491 }).when(producer).send(any(Message.class), any(TestContext.class));492 when(endpoint.getActor()).thenReturn(null);493 494 sendAction.execute(context);495 }496 497 @Test498 @SuppressWarnings("rawtypes")499 public void testSendMessageWithHeaderValuesVariableSupport() {500 SendMessageAction sendAction = new SendMessageAction();501 sendAction.setEndpoint(endpoint);502 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();503 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");504 505 context.setVariable("myOperation", "sayHello");506 507 final Map<String, Object> controlHeaders = new HashMap<String, Object>();508 controlHeaders.put("Operation", "sayHello");509 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);510 final Map<String, Object> headers = new HashMap<String, Object>();511 headers.put("Operation", "${myOperation}");512 messageBuilder.setMessageHeaders(headers);513 514 sendAction.setMessageBuilder(messageBuilder);515 reset(endpoint, producer, endpointConfiguration);516 when(endpoint.createProducer()).thenReturn(producer);517 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);518 doAnswer(new Answer() {519 @Override520 public Object answer(InvocationOnMock invocation) throws Throwable {521 DomXmlMessageValidator validator = new DomXmlMessageValidator();522 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();523 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);524 return null;525 }526 }).when(producer).send(any(Message.class), any(TestContext.class));527 when(endpoint.getActor()).thenReturn(null);528 529 sendAction.execute(context);530 }531 532 @Test533 public void testSendMessageWithUnknwonVariableInMessagePayload() {534 SendMessageAction sendAction = new SendMessageAction();535 sendAction.setEndpoint(endpoint);536 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();537 messageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");538 539 sendAction.setMessageBuilder(messageBuilder);540 reset(endpoint, producer, endpointConfiguration);541 when(endpoint.createProducer()).thenReturn(producer);542 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);543 when(endpoint.getActor()).thenReturn(null);544 545 try {546 sendAction.execute(context);547 } catch(CitrusRuntimeException e) {548 Assert.assertEquals(e.getMessage(), "Unknown variable 'myText'");549 return;550 }551 552 Assert.fail("Missing " + CitrusRuntimeException.class + " with unknown variable error message");553 }554 555 @Test556 public void testSendMessageWithUnknwonVariableInHeaders() {557 SendMessageAction sendAction = new SendMessageAction();558 sendAction.setEndpoint(endpoint);559 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();560 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");561 562 final Map<String, Object> headers = new HashMap<String, Object>();563 headers.put("Operation", "${myOperation}");564 messageBuilder.setMessageHeaders(headers);565 566 sendAction.setMessageBuilder(messageBuilder);567 reset(endpoint, producer, endpointConfiguration);568 when(endpoint.createProducer()).thenReturn(producer);569 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);570 when(endpoint.getActor()).thenReturn(null);571 572 try {573 sendAction.execute(context);574 } catch(CitrusRuntimeException e) {575 Assert.assertEquals(e.getMessage(), "Unknown variable 'myOperation'");576 return;577 }578 579 Assert.fail("Missing " + CitrusRuntimeException.class + " with unknown variable error message");580 }581 582 @Test583 @SuppressWarnings("rawtypes")584 public void testSendMessageWithExtractHeaderValues() {585 SendMessageAction sendAction = new SendMessageAction();586 sendAction.setEndpoint(endpoint);587 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();588 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");589 590 final Map<String, Object> controlHeaders = new HashMap<String, Object>();591 controlHeaders.put("Operation", "sayHello");592 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);593 final Map<String, Object> headers = new HashMap<String, Object>();594 headers.put("Operation", "sayHello");595 messageBuilder.setMessageHeaders(headers);596 597 sendAction.setMessageBuilder(messageBuilder);598 599 Map<String, String> extractVars = new HashMap<String, String>();600 extractVars.put("Operation", "myOperation");601 extractVars.put(MessageHeaders.ID, "correlationId");602 603 List<VariableExtractor> variableExtractors = new ArrayList<VariableExtractor>();604 MessageHeaderVariableExtractor variableExtractor = new MessageHeaderVariableExtractor();605 variableExtractor.setHeaderMappings(extractVars);606 607 variableExtractors.add(variableExtractor);608 sendAction.setVariableExtractors(variableExtractors);609 reset(endpoint, producer, endpointConfiguration);610 when(endpoint.createProducer()).thenReturn(producer);611 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);612 doAnswer(new Answer() {613 @Override614 public Object answer(InvocationOnMock invocation) throws Throwable {615 DomXmlMessageValidator validator = new DomXmlMessageValidator();616 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();617 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);618 return null;619 }620 }).when(producer).send(any(Message.class), any(TestContext.class));621 when(endpoint.getActor()).thenReturn(null);622 623 sendAction.execute(context);624 625 Assert.assertNotNull(context.getVariable("myOperation"));626 Assert.assertNotNull(context.getVariable("correlationId"));627 }628 629 @Test630 @SuppressWarnings("rawtypes")631 public void testMissingMessagePayload() {632 SendMessageAction sendAction = new SendMessageAction();633 sendAction.setEndpoint(endpoint);634 reset(endpoint, producer, endpointConfiguration);635 when(endpoint.createProducer()).thenReturn(producer);636 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);637 doAnswer(new Answer() {638 @Override639 public Object answer(InvocationOnMock invocation) throws Throwable {640 DomXmlMessageValidator validator = new DomXmlMessageValidator();641 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();642 validator.validateMessage(((Message)invocation.getArguments()[0]), new DefaultMessage(""), context, validationContext);643 return null;644 }645 }).when(producer).send(any(Message.class), any(TestContext.class));646 when(endpoint.getActor()).thenReturn(null);647 648 sendAction.execute(context);649 }650 651 @Test652 @SuppressWarnings("rawtypes")653 public void testSendMessageWithXmlDeclaration() {654 SendMessageAction sendAction = new SendMessageAction();655 sendAction.setEndpoint(endpoint);656 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();657 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");658 659 sendAction.setMessageBuilder(messageBuilder);660 661 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");662 reset(endpoint, producer, endpointConfiguration);663 when(endpoint.createProducer()).thenReturn(producer);664 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);665 doAnswer(new Answer() {666 @Override667 public Object answer(InvocationOnMock invocation) throws Throwable {668 DomXmlMessageValidator validator = new DomXmlMessageValidator();669 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();670 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);671 return null;672 }673 }).when(producer).send(any(Message.class), any(TestContext.class));674 when(endpoint.getActor()).thenReturn(null);675 676 sendAction.execute(context);677 }678 679 @Test680 @SuppressWarnings("rawtypes")681 public void testSendMessageWithUTF16Encoding() {682 SendMessageAction sendAction = new SendMessageAction();683 sendAction.setEndpoint(endpoint);684 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();685 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"UTF-16\"?><TestRequest><Message>Hello World!</Message></TestRequest>");686 687 sendAction.setMessageBuilder(messageBuilder);688 689 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-16\"?><TestRequest><Message>Hello World!</Message></TestRequest>");690 reset(endpoint, producer, endpointConfiguration);691 when(endpoint.createProducer()).thenReturn(producer);692 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);693 doAnswer(new Answer() {694 @Override695 public Object answer(InvocationOnMock invocation) throws Throwable {696 DomXmlMessageValidator validator = new DomXmlMessageValidator();697 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();698 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);699 return null;700 }701 }).when(producer).send(any(Message.class), any(TestContext.class));702 when(endpoint.getActor()).thenReturn(null);703 704 sendAction.execute(context);705 }706 707 @Test708 @SuppressWarnings("rawtypes")709 public void testSendMessageWithISOEncoding() {710 SendMessageAction sendAction = new SendMessageAction();711 sendAction.setEndpoint(endpoint);712 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();713 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");714 715 sendAction.setMessageBuilder(messageBuilder);716 717 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");718 reset(endpoint, producer, endpointConfiguration);719 when(endpoint.createProducer()).thenReturn(producer);720 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);721 doAnswer(new Answer() {722 @Override723 public Object answer(InvocationOnMock invocation) throws Throwable {724 DomXmlMessageValidator validator = new DomXmlMessageValidator();725 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();726 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);727 return null;728 }729 }).when(producer).send(any(Message.class), any(TestContext.class));730 when(endpoint.getActor()).thenReturn(null);731 732 sendAction.execute(context);733 }734 735 @Test736 @SuppressWarnings("rawtypes")737 public void testSendMessageWithUnsupportedEncoding() {738 SendMessageAction sendAction = new SendMessageAction();739 sendAction.setEndpoint(endpoint);740 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();741 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"MyUnsupportedEncoding\"?><TestRequest><Message>Hello World!</Message></TestRequest>");742 743 sendAction.setMessageBuilder(messageBuilder);744 reset(endpoint, producer, endpointConfiguration);745 when(endpoint.createProducer()).thenReturn(producer);746 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);747 when(endpoint.getActor()).thenReturn(null);748 try {749 sendAction.execute(context);750 } catch (CitrusRuntimeException e) {751 Assert.assertTrue(e.getCause() instanceof UnsupportedEncodingException);752 }753 verify(producer).send(any(Message.class), any(TestContext.class));754 }755 @Test756 @SuppressWarnings("rawtypes")757 public void testSendMessageWithMessagePayloadResourceISOEncoding() {758 SendMessageAction sendAction = new SendMessageAction();759 sendAction.setEndpoint(endpoint);760 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();761 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-iso-encoding.xml");762 763 sendAction.setMessageBuilder(messageBuilder);764 765 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");766 reset(endpoint, producer, endpointConfiguration);767 when(endpoint.createProducer()).thenReturn(producer);768 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);769 doAnswer(new Answer() {770 @Override771 public Object answer(InvocationOnMock invocation) throws Throwable {...

Full Screen

Full Screen

testSendMessageWithMessagePayloadResource

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;2import com.consol.citrus.message.MessageType;3import org.springframework.http.HttpStatus;4import org.testng.annotations.Test;5public class SendMessageActionTestIT extends TestNGCitrusTestDesigner {6 public void testSendMessageWithMessagePayloadResource() {7 variable("message", "Hello Citrus!");8 http()9 .client("httpClient")10 .send()11 .post("/test")12 .messageType(MessageType.PLAINTEXT)13 .payload(resource("classpath:com/consol/citrus/actions/test.txt"));14 http()15 .client("httpClient")16 .receive()17 .response(HttpStatus.OK)18 .messageType(MessageType.PLAINTEXT)19 .payload("${message}");20 }21}

Full Screen

Full Screen

testSendMessageWithMessagePayloadResource

Using AI Code Generation

copy

Full Screen

1public void testSendMessageWithMessagePayloadResource() {2 variable("greeting", "Hello Citrus!");3 sendMessage(messageBuilder()4 .messageType(MessageType.PLAINTEXT)5 .body(new ClassPathResource("templates/greeting.txt"))6 .contentType("text/plain")7 .header("operation", "greet")8 .header("citrus_jms_messageId", "1234567890")9 .build());10 receiveMessage(messageBuilder()11 .messageType(MessageType.PLAINTEXT)12 .body("Hello Citrus!")13 .contentType("text/plain")14 .header("operation", "greet")15 .header("citrus_jms_messageId", "1234567890")16 .build());17}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful