Best Citrus code snippet using com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder.setPayloadResourcePath
Source:SendMessageActionTest.java
...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 {772 DomXmlMessageValidator validator = new DomXmlMessageValidator();773 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();774 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);775 return null;...
Source:PayloadTemplateMessageBuilderTest.java
...58 @Test59 public void testMessageBuilderWithPayloadResource() {60 messageBuilder = new PayloadTemplateMessageBuilder();61 62 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/builder/payload-data-resource.txt");63 64 Message resultingMessage = messageBuilder.buildMessageContent(context, Citrus.DEFAULT_MESSAGE_TYPE);65 66 Assert.assertEquals(resultingMessage.getPayload(), "TestMessageData");67 }68 @Test69 public void testMessageBuilderWithPayloadResourceVariableSupport() {70 messageBuilder = new PayloadTemplateMessageBuilder();71 72 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/builder/variable-data-resource.txt");73 context.setVariable("placeholder", "payload data");74 75 Message resultingMessage = messageBuilder.buildMessageContent(context, Citrus.DEFAULT_MESSAGE_TYPE);76 77 Assert.assertEquals(resultingMessage.getPayload(), "This payload data contains variables!");78 }79 @Test80 public void testMessageBuilderWithPayloadResourceBinary() {81 messageBuilder = new PayloadTemplateMessageBuilder();82 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/builder/button.png");83 Message resultingMessage = messageBuilder.buildMessageContent(context, MessageType.BINARY.name());84 Assert.assertEquals(resultingMessage.getPayload().getClass(), byte[].class);85 }86 @Test87 public void testMessageBuilderWithPayloadResourceGzip() {88 messageBuilder = new PayloadTemplateMessageBuilder();89 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/builder/button.png");90 Message resultingMessage = messageBuilder.buildMessageContent(context, MessageType.GZIP.name());91 Assert.assertEquals(resultingMessage.getPayload().getClass(), byte[].class);92 }93 94 @Test95 public void testMessageBuilderWithHeaders() {96 Map<String, Object> headers = new HashMap<String, Object>();97 headers.put("operation", "unitTesting");98 messageBuilder.setMessageHeaders(headers);99 100 Message resultingMessage = messageBuilder.buildMessageContent(context, Citrus.DEFAULT_MESSAGE_TYPE);101 102 Assert.assertEquals(resultingMessage.getPayload(), "TestMessagePayload");103 Assert.assertNotNull(resultingMessage.getHeader("operation"));...
Source:AbstractMessageActionParser.java
...113 }114 Element xmlResourceElement = DomUtils.getChildElementByTagName(messageElement, "resource");115 if (xmlResourceElement != null) {116 messageBuilder = new PayloadTemplateMessageBuilder();117 messageBuilder.setPayloadResourcePath(xmlResourceElement.getAttribute("file"));118 if (xmlResourceElement.hasAttribute("charset")) {119 messageBuilder.setPayloadResourceCharset(xmlResourceElement.getAttribute("charset"));120 }121 }122 123 if (messageBuilder != null) {124 Map<String, String> overwriteXpath = new HashMap<>();125 Map<String, String> overwriteJsonPath = new HashMap<>();126 List<?> messageValueElements = DomUtils.getChildElementsByTagName(messageElement, "element");127 for (Iterator<?> iter = messageValueElements.iterator(); iter.hasNext();) {128 Element messageValue = (Element) iter.next();129 String pathExpression = messageValue.getAttribute("path");130 if (JsonPathMessageValidationContext.isJsonPathExpression(pathExpression)) {131 overwriteJsonPath.put(pathExpression, messageValue.getAttribute("value"));...
setPayloadResourcePath
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.TestAction;3import com.consol.citrus.actions.SendMessageAction;4import com.consol.citrus.context.TestContext;5import com.consol.citrus.dsl.builder.AbstractTestBuilder;6import com.consol.citrus.dsl.builder.SendMessageBuilder;7import com.consol.citrus.message.MessageType;8import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;9import java.util.Map;10import java.util.HashMap;11import java.util.Iterator;12import java.util.Map.Entry;13public class PayloadTemplateMessageBuilder1 extends PayloadTemplateMessageBuilder {14public PayloadTemplateMessageBuilder1() {15super();16}17public PayloadTemplateMessageBuilder1(String payloadResourcePath) {18super(payloadResourcePath);19}20public PayloadTemplateMessageBuilder1(String payloadResourcePath, Map<String, Object> variables) {21super(payloadResourcePath, variables);22}23public PayloadTemplateMessageBuilder1(String payloadResourcePath, Map<String, Object> variables, String characterSet) {24super(payloadResourcePath, variables, characterSet);25}26public PayloadTemplateMessageBuilder1(String payloadResourcePath, Map<String, Object> variables, String characterSet, MessageType messageType) {27super(payloadResourcePath, variables, characterSet, messageType);28}29public PayloadTemplateMessageBuilder1(String payloadResourcePath, Map<String, Object> variables, String characterSet, MessageType messageType, String controlCharacter) {30super(payloadResourcePath, variables, characterSet, messageType, controlCharacter);31}32public PayloadTemplateMessageBuilder1(String payloadResourcePath, Map<String, Object> variables, String characterSet, MessageType messageType, String controlCharacter, boolean ignoreWhitespaces) {33super(payloadResourcePath, variables, characterSet, messageType, controlCharacter, ignoreWhitespaces);34}35public PayloadTemplateMessageBuilder1(String payloadResourcePath, Map<String, Object> variables, String characterSet, MessageType messageType, String controlCharacter, boolean ignoreWhitespaces, boolean ignoreLineEndings) {36super(payloadResourcePath, variables, characterSet, messageType, controlCharacter, ignoreWhitespaces, ignoreLineEndings);37}38public PayloadTemplateMessageBuilder1(String payloadResourcePath, Map<String, Object> variables, String characterSet, MessageType messageType, String controlCharacter, boolean ignoreWhitespaces, boolean ignoreLineEndings, boolean ignoreDiffBetweenCRandCRLF) {39super(payloadResourcePath, variables, characterSet, messageType, controlCharacter, ignoreWhitespaces, ignore
setPayloadResourcePath
Using AI Code Generation
1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.testng.annotations.Test;4public class SetPayloadResourcePathJavaITest extends TestNGCitrusTestDesigner {5 protected void configure() {6 echo("Hello World!");7 send("foo")8 .payload("<TestRequestMessage><text>Hello World!</text></TestRequestMessage>")9 .header("operation", "foo");10 receive("bar")11 .payload("<TestResponseMessage><text>Hello World!</text></TestResponseMessage>")12 .header("operation", "bar");13 }14}15package com.consol.citrus.dsl.design;16import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;17import org.testng.annotations.Test;18public class SetPayloadResourcePathJavaITest extends TestNGCitrusTestDesigner {19 protected void configure() {20 echo("Hello World!");21 send("foo")22 .payload("<TestRequestMessage><text>Hello World!</text></TestRequestMessage>")23 .header("operation", "foo");24 receive("bar")25 .payload("<TestResponseMessage><text>Hello World!</text></TestResponseMessage>")26 .header("operation", "bar");27 }28}29package com.consol.citrus.dsl.design;30import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;31import org.testng.annotations.Test;32public class SetPayloadResourcePathJavaITest extends TestNGCitrusTestDesigner {33 protected void configure() {34 echo("Hello World!");35 send("foo")36 .payload("<TestRequestMessage><text>Hello World!</text></TestResponseMessage>")37 .header("operation", "foo");38 receive("bar")39 .payload("<TestResponseMessage><text>Hello World!</text></TestResponseMessage>")40 .header("operation", "bar");41 }42}
setPayloadResourcePath
Using AI Code Generation
1import com.consol.citrus.dsl.runner.TestRunner;2import com.consol.citrus.dsl.builder.BuilderSupport;3import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;4import com.consol.citrus.dsl.builder.SendMessageBuilder;5import com.consol.citrus.dsl.builder.HttpActionBuilder;6import com.consol.citrus.dsl.builder.HttpClientActionBuilder;7import com.consol.citrus.dsl.builder.HttpServerActionBuilder;8import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpActionBuilderSupport;9import com.consol.citrus.dsl.builder.HttpClientActionBuilder.HttpClientActionBuilderSupport;10import com.consol.citrus.dsl.builder.HttpServerActionBuilder.HttpServerActionBuilderSupport;11import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpClientActionBuilderSupport.HttpClientSendActionBuilder;12import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpClientActionBuilderSupport.HttpClientReceiveActionBuilder;13import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpServerActionBuilderSupport.HttpServerSendActionBuilder;14import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpServerActionBuilderSupport.HttpServerReceiveActionBuilder;15import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpActionBuilderSupport.HttpSendActionBuilder;16import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpActionBuilderSupport.HttpReceiveActionBuilder;17import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpClientActionBuilderSupport.HttpClientSendActionBuilder.HttpClientSendBuilder;18import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpClientActionBuilderSupport.HttpClientReceiveActionBuilder.HttpClientReceiveBuilder;19import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpServerActionBuilderSupport.HttpServerSendActionBuilder.HttpServerSendBuilder;20import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpServerActionBuilderSupport.HttpServerReceiveActionBuilder.HttpServerReceiveBuilder;21import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpActionBuilderSupport.HttpSendActionBuilder.HttpSendBuilder;22import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpActionBuilderSupport.HttpReceiveActionBuilder.HttpReceiveBuilder;23import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpSendBuilderSupport;24import com.consol.citrus.dsl.builder.HttpActionBuilder.HttpReceiveBuilderSupport;25import com.consol.citrus.dsl.builder.HttpClientActionBuilder.HttpClientSendBuilderSupport;26import com.consol.citrus.dsl.builder.Http
setPayloadResourcePath
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.message.MessageType;3import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;4import org.springframework.core.io.Resource;5public class PayloadTemplateMessageBuilderSupport extends AbstractMessageContentBuilder<PayloadTemplateMessageBuilderSupport, PayloadTemplateMessageBuilder> {6 public PayloadTemplateMessageBuilderSupport(PayloadTemplateMessageBuilder builder) {7 super(builder);8 }9 public PayloadTemplateMessageBuilderSupport payload(String data) {10 builder.setPayloadData(data);11 return this;12 }13 public PayloadTemplateMessageBuilderSupport payloadResourcePath(String resourcePath) {14 builder.setPayloadResourcePath(resourcePath);15 return this;16 }17 public PayloadTemplateMessageBuilderSupport payloadResource(Resource resource) {18 builder.setPayloadResource(resource);19 return this;20 }21 public PayloadTemplateMessageBuilderSupport payloadFile(String filePath) {22 builder.setPayloadResourcePath(filePath);23 return this;24 }25 public PayloadTemplateMessageBuilderSupport messageType(MessageType messageType) {26 builder.setMessageType(messageType);27 return this;28 }29 public PayloadTemplateMessageBuilderSupport charset(String charsetName) {30 builder.setCharsetName(charsetName);31 return this;32 }33 public PayloadTemplateMessageBuilderSupport name(String name) {34 builder.setMessageName(name);35 return this;36 }37 public PayloadTemplateMessageBuilderSupport header(String data) {38 builder.setHeaderData(data
setPayloadResourcePath
Using AI Code Generation
1public class 4 {2 public static void main(String[] args) {3 PayloadTemplateMessageBuilder payloadTemplateMessageBuilder = new PayloadTemplateMessageBuilder();4 payloadTemplateMessageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/template/payload-template.xml");5 }6}7public class 5 {8 public static void main(String[] args) {9 PayloadTemplateMessageBuilder payloadTemplateMessageBuilder = new PayloadTemplateMessageBuilder();10 payloadTemplateMessageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/template/payload-template.xml");11 }12}13public class 6 {14 public static void main(String[] args) {15 PayloadTemplateMessageBuilder payloadTemplateMessageBuilder = new PayloadTemplateMessageBuilder();16 payloadTemplateMessageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/template/payload-template.xml");17 }18}19public class 7 {20 public static void main(String[] args) {21 PayloadTemplateMessageBuilder payloadTemplateMessageBuilder = new PayloadTemplateMessageBuilder();22 payloadTemplateMessageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/template/payload-template.xml");23 }24}25public class 8 {26 public static void main(String[] args) {27 PayloadTemplateMessageBuilder payloadTemplateMessageBuilder = new PayloadTemplateMessageBuilder();28 payloadTemplateMessageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/validation/template/payload-template.xml");29 }30}31public class 9 {32 public static void main(String[] args) {33 PayloadTemplateMessageBuilder payloadTemplateMessageBuilder = new PayloadTemplateMessageBuilder();34 payloadTemplateMessageBuilder.setPayloadResourcePath("classpath:
setPayloadResourcePath
Using AI Code Generation
1import com.consol.citrus.dsl.builder.PayloadTemplateMessageBuilder;2import com.consol.citrus.dsl.builder.SendMessageBuilder;3import com.consol.citrus.dsl.builder.ValidationMessageBuilder;4import com.consol.citrus.dsl.runner.TestRunner;5import com.consol.citrus.dsl.testng.TestNGCitrusTest;6import com.consol.citrus.message.MessageType;7import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;8import org.testng.annotations.Test;9public class 4 extends TestNGCitrusTest {10 public void 4() {11 SendMessageBuilder send = citrus().http()12 .client("httpClient")13 .send()14 .post("/api/test")15 .messageType(MessageType.JSON)16 .payload("{\"id\": \"${id}\", \"name\": \"${name}\"}");17 PayloadTemplateMessageBuilder payloadTemplateMessageBuilder = new PayloadTemplateMessageBuilder();18 payloadTemplateMessageBuilder.setPayloadResourcePath("classpath:templates/4.json");19 send.message(payloadTemplateMessageBuilder);20 ValidationMessageBuilder receive = citrus().http()21 .client("httpClient")22 .receive()23 .post("/api/test")24 .messageType(MessageType.JSON)25 .payload("{\"id\": \"${id}\", \"name\": \"${name}\"}");26 PayloadTemplateMessageBuilder payloadTemplateMessageBuilder = new PayloadTemplateMessageBuilder();27 payloadTemplateMessageBuilder.setPayloadResourcePath("classpath:templates/4.json");28 receive.message(payloadTemplateMessageBuilder);29 runner().run(send, receive);30 }31}32import com.consol.citrus.dsl.builder.PayloadTemplateMessageBuilder;33import com.consol.citrus.dsl.builder.SendMessageBuilder;34import com.consol.citrus.dsl.builder.ValidationMessageBuilder;35import com.consol.citrus.dsl.runner.TestRunner;36import com.consol.citrus.dsl.testng.TestNGCitrusTest;37import com.consol.citrus.message.MessageType;38import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;39import org.testng.annotations.Test;40public class 5 extends TestNGCitrusTest {
setPayloadResourcePath
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.validation.builder.AbstractMessageContentBuilder;5import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;6import com.consol.citrus.validation.json.JsonTextMessageValidator;7import com.consol.citrus.validation.xml.XmlMessageValidationContext;8import com.consol.citrus.validation.xml.XmlTextMessageValidator;9import org.springframework.core.io.Resource;10import java.util.List;11public class PayloadTemplateMessageBuilderSupport extends AbstractMessageContentBuilder<PayloadTemplateMessageBuilderSupport> {12 private final String payloadResourcePath;13 private final Resource payloadResource;14 public PayloadTemplateMessageBuilderSupport(String payloadResourcePath) {15 this.payloadResourcePath = payloadResourcePath;16 this.payloadResource = null;17 }18 public PayloadTemplateMessageBuilderSupport(Resource payloadResource) {19 this.payloadResourcePath = null;20 this.payloadResource = payloadResource;21 }22 public void validateMessage(String message, TestContext context) {23 if (messageType == null) {24 messageType = MessageType.PLAINTEXT.name();25 }26 if (messageType.equalsIgnoreCase(MessageType.PLAINTEXT.name())) {27 if (messageValidator == null) {28 messageValidator = new XmlTextMessageValidator();29 }30 } else if (messageType.equalsIgnoreCase(MessageType.XML.name())) {31 if (messageValidator == null) {32 messageValidator = new XmlTextMessageValidator();33 }34 if (validationContext == null) {35 validationContext = new XmlMessageValidationContext();36 }37 } else if (messageType.equalsIgnoreCase(MessageType.JSON.name())) {38 if (messageValidator == null) {39 messageValidator = new JsonTextMessageValidator();40 }41 }42 super.validateMessage(message
setPayloadResourcePath
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.validation.builder.AbstractMessageContentBuilder;5import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;6import org.springframework.core.io.Resource;7public class SetPayloadResourcePath extends AbstractMessageContentBuilder<SetPayloadResourcePath> {8 private final PayloadTemplateMessageBuilder builder;9 public SetPayloadResourcePath(TestDesigner designer, Resource resource) {10 builder = new PayloadTemplateMessageBuilder(designer, resource);11 }12 public SetPayloadResourcePath(TestDesigner designer, String resourcePath) {13 builder = new PayloadTemplateMessageBuilder(designer, resourcePath);14 }15 public SetPayloadResourcePath(TestDesigner designer, Resource resource, MessageType messageType) {16 builder = new PayloadTemplateMessageBuilder(designer, resource, messageType);17 }18 public SetPayloadResourcePath(TestDesigner designer, String resourcePath, MessageType messageType) {19 builder = new PayloadTemplateMessageBuilder(designer, resourcePath, messageType);20 }21 public void apply(TestDesigner designer) {22 builder.apply(designer);23 }24}25package com.consol.citrus.dsl.builder;26import com.consol.citrus.dsl.design.TestDesigner;27import com.consol.citrus.message.MessageType;28import com.consol.citrus.validation.builder.AbstractMessageContentBuilder;29import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;30import org.springframework.core.io.Resource;31public class SetPayloadResourcePath extends AbstractMessageContentBuilder<SetPayloadResourcePath> {32 private final PayloadTemplateMessageBuilder builder;33 public SetPayloadResourcePath(TestDesigner designer, Resource resource) {34 builder = new PayloadTemplateMessageBuilder(designer, resource);35 }36 public SetPayloadResourcePath(TestDesigner designer, String resourcePath) {37 builder = new PayloadTemplateMessageBuilder(designer, resourcePath);38 }39 public SetPayloadResourcePath(TestDesigner designer, Resource resource, MessageType messageType) {40 builder = new PayloadTemplateMessageBuilder(designer, resource, messageType);41 }42 public SetPayloadResourcePath(TestDesigner designer
setPayloadResourcePath
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.dsl.builder.AbstractMessageContentBuilder;3import com.consol.citrus.dsl.builder.BuilderSupport;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;6import org.springframework.core.io.Resource;7public class PayloadTemplateMessageBuilderSupport extends AbstractMessageContentBuilder<PayloadTemplateMessageBuilderSupport> {8 private final PayloadTemplateMessageBuilder messageBuilder;9 public PayloadTemplateMessageBuilderSupport(PayloadTemplateMessageBuilder messageBuilder) {10 super(messageBuilder);11 this.messageBuilder = messageBuilder;12 }13 public PayloadTemplateMessageBuilderSupport payloadResourcePath(String payloadResourcePath) {14 messageBuilder.setPayloadResourcePath(payloadResourcePath);15 return this;16 }17 public PayloadTemplateMessageBuilderSupport payloadResource(Resource payloadResource) {18 messageBuilder.setPayloadResource(payloadResource);19 return this;20 }21 public PayloadTemplateMessageBuilderSupport payloadData(String payloadData) {22 messageBuilder.setPayloadData(payloadData);23 return this;24 }25 public PayloadTemplateMessageBuilderSupport payloadData(byte[] payloadData) {26 messageBuilder.setPayloadData(payloadData);27 return this;28 }29 public PayloadTemplateMessageBuilderSupport messageType(MessageType messageType) {30 messageBuilder.setMessageType(messageType);31 return this;32 }33 public PayloadTemplateMessageBuilderSupport messageTypeName(String messageTypeName) {34 messageBuilder.setMessageTypeName(messageTypeName);35 return this;36 }
setPayloadResourcePath
Using AI Code Generation
1package com.consol.citrus.dsl.builder;2import com.consol.citrus.dsl.builder.AbstractMessageContentBuilder;3import com.consol.citrus.dsl.builder.PayloadTemplateMessageBuilder;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.xml.XmlMessageValidationContext;6import com.consol.citrus.validation.xml.XmlValidationContext;7import com.consol.citrus.xml.XsdSchemaRepository;8import com.consol.citrus.xml.namespace.NamespaceContextBuilder;9import com.consol.citrus.xml.schema.XsdSchema;10import org.springframework.core.io.Resource;11import java.util.ArrayList;12import java.util.HashMap;13import java.util.List;14import java.util.Map;15public class PayloadTemplateMessageBuilder extends AbstractMessageContentBuilder<PayloadTemplateMessageBuilder> {16 private final Map<String, Object> variables = new HashMap<>();17 private final List<XsdSchema> xsdSchemas = new ArrayList<>();18 private final List<Resource> xsdSchemaResources = new ArrayList<>();19 private final List<String> xsdSchemaRepositoryIds = new ArrayList<>();20 private final List<NamespaceContextBuilder> namespaceContextBuilders = new ArrayList<>();21 private final List<XmlValidationContext> validationContexts = new ArrayList<>();22 private final List<String> controlNamespaces = new ArrayList<>();23 private final List<String> ignoreNamespaces = new ArrayList<>();24 private final List<String> ignorePaths = new ArrayList<>();25 private final List<String> ignoreValues = new ArrayList<>();26 private final List<String> ignoreWhitespace = new ArrayList<>();27 private final List<String> ignoreComments = new ArrayList<>();28 private final List<String> ignoreDiff = new ArrayList<>();29 private final List<String> ignoreXPathExpressions = new ArrayList<>();30 private final List<String> ignoreDtd = new ArrayList<>();31 private final List<String> ignoreSchemaLocations = new ArrayList<>();32 private final List<String> ignoreSchemaLocationsPaths = new ArrayList<>();33 private final List<String> ignoreSchemaLocationsExpressions = new ArrayList<>();34 private final List<String> ignoreSchemaLocationsValues = new ArrayList<>();35 private final List<String> ignoreSchemaLocationsNamespaces = new ArrayList<>();36 private String payloadData;37 private String payloadResourcePath;38 private String payloadResourcePathRoot;39 private boolean isXml = true;40 private boolean isJson = false;
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!!