How to use setValidationContexts method of com.consol.citrus.actions.ReceiveMessageAction class

Best Citrus code snippet using com.consol.citrus.actions.ReceiveMessageAction.setValidationContexts

Source:ReceiveMessageActionTest.java Github

copy

Full Screen

...66 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");67 when(mockChannel.receive(15000)).thenReturn(new ChannelMessageConverter().convertOutbound(controlMessage, new ChannelEndpointConfiguration(), context));68 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();69 validationContexts.add(validationContext);70 receiveAction.setValidationContexts(validationContexts);71 receiveAction.execute(context);72 }73 @Test74 @SuppressWarnings({ "unchecked", "rawtypes" })75 public void testReceiveMessageWithVariableEndpointName() {76 ReceiveMessageAction receiveAction = new ReceiveMessageAction();77 receiveAction.setEndpointUri("${varEndpoint}");78 context.setVariable("varEndpoint", "channel:mockChannel");79 TestActor testActor = new TestActor();80 testActor.setName("TESTACTOR");81 receiveAction.setActor(testActor);82 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();83 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();84 receiveAction.setMessageBuilder(controlMessageBuilder);85 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");86 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");87 when(mockChannel.receive(5000)).thenReturn(new ChannelMessageConverter().convertOutbound(controlMessage, new ChannelEndpointConfiguration(), context));88 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();89 validationContexts.add(validationContext);90 receiveAction.setValidationContexts(validationContexts);91 receiveAction.execute(context);92 }93 @Test94 @SuppressWarnings({ "unchecked", "rawtypes" })95 public void testReceiveMessageWithMessagePayloadData() {96 ReceiveMessageAction receiveAction = new ReceiveMessageAction();97 receiveAction.setEndpoint(endpoint);98 99 TestActor testActor = new TestActor();100 testActor.setName("TESTACTOR");101 102 receiveAction.setActor(testActor);103 104 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();105 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();106 receiveAction.setMessageBuilder(controlMessageBuilder);107 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");108 109 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");110 reset(endpoint, consumer, endpointConfiguration);111 when(endpoint.createConsumer()).thenReturn(consumer);112 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);113 when(endpointConfiguration.getTimeout()).thenReturn(5000L);114 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);115 when(endpoint.getActor()).thenReturn(null);116 117 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 118 validationContexts.add(validationContext);119 receiveAction.setValidationContexts(validationContexts);120 receiveAction.execute(context);121 }122 123 @Test124 @SuppressWarnings({ "unchecked", "rawtypes" })125 public void testReceiveMessageWithMessagePayloadResource() {126 ReceiveMessageAction receiveAction = new ReceiveMessageAction();127 receiveAction.setEndpoint(endpoint);128 129 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();130 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();131 receiveAction.setMessageBuilder(controlMessageBuilder);132 controlMessageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload.xml");133 134 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");135 reset(endpoint, consumer, endpointConfiguration);136 when(endpoint.createConsumer()).thenReturn(consumer);137 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);138 when(endpointConfiguration.getTimeout()).thenReturn(5000L);139 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);140 when(endpoint.getActor()).thenReturn(null);141 142 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();143 validationContexts.add(validationContext);144 receiveAction.setValidationContexts(validationContexts);145 receiveAction.execute(context);146 }147 148 @Test149 @SuppressWarnings({ "unchecked", "rawtypes" })150 public void testReceiveMessageWithMessageBuilderScriptData() {151 ReceiveMessageAction receiveAction = new ReceiveMessageAction();152 receiveAction.setEndpoint(endpoint);153 StringBuilder sb = new StringBuilder();154 sb.append("markupBuilder.TestRequest(){\n");155 sb.append("Message('Hello World!')\n");156 sb.append("}");157 158 GroovyScriptMessageBuilder controlMessageBuilder = new GroovyScriptMessageBuilder();159 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();160 receiveAction.setMessageBuilder(controlMessageBuilder);161 controlMessageBuilder.setScriptData(sb.toString());162 163 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");164 reset(endpoint, consumer, endpointConfiguration);165 when(endpoint.createConsumer()).thenReturn(consumer);166 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);167 when(endpointConfiguration.getTimeout()).thenReturn(5000L);168 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);169 when(endpoint.getActor()).thenReturn(null);170 171 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 172 validationContexts.add(validationContext);173 receiveAction.setValidationContexts(validationContexts);174 receiveAction.execute(context);175 }176 177 @Test178 @SuppressWarnings({ "unchecked", "rawtypes" })179 public void testReceiveMessageWithMessageBuilderScriptDataVariableSupport() {180 context.setVariable("text", "Hello World!");181 182 ReceiveMessageAction receiveAction = new ReceiveMessageAction();183 receiveAction.setEndpoint(endpoint);184 StringBuilder sb = new StringBuilder();185 sb.append("markupBuilder.TestRequest(){\n");186 sb.append("Message('${text}')\n");187 sb.append("}");188 189 GroovyScriptMessageBuilder controlMessageBuilder = new GroovyScriptMessageBuilder();190 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();191 receiveAction.setMessageBuilder(controlMessageBuilder);192 controlMessageBuilder.setScriptData(sb.toString());193 194 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");195 reset(endpoint, consumer, endpointConfiguration);196 when(endpoint.createConsumer()).thenReturn(consumer);197 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);198 when(endpointConfiguration.getTimeout()).thenReturn(5000L);199 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);200 when(endpoint.getActor()).thenReturn(null);201 202 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 203 validationContexts.add(validationContext);204 receiveAction.setValidationContexts(validationContexts);205 receiveAction.execute(context);206 }207 208 @Test209 @SuppressWarnings({ "unchecked", "rawtypes" })210 public void testReceiveMessageWithMessageBuilderScriptResource() {211 ReceiveMessageAction receiveAction = new ReceiveMessageAction();212 receiveAction.setEndpoint(endpoint);213 GroovyScriptMessageBuilder controlMessageBuilder = new GroovyScriptMessageBuilder();214 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();215 receiveAction.setMessageBuilder(controlMessageBuilder);216 controlMessageBuilder.setScriptResourcePath("classpath:com/consol/citrus/actions/test-request-payload.groovy");217 218 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");219 reset(endpoint, consumer, endpointConfiguration);220 when(endpoint.createConsumer()).thenReturn(consumer);221 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);222 when(endpointConfiguration.getTimeout()).thenReturn(5000L);223 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);224 when(endpoint.getActor()).thenReturn(null);225 226 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 227 validationContexts.add(validationContext);228 receiveAction.setValidationContexts(validationContexts);229 receiveAction.execute(context);230 }231 232 @Test233 @SuppressWarnings({ "unchecked", "rawtypes" })234 public void testReceiveMessageWithMessagePayloadDataVariablesSupport() {235 ReceiveMessageAction receiveAction = new ReceiveMessageAction();236 receiveAction.setEndpoint(endpoint);237 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();238 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();239 receiveAction.setMessageBuilder(controlMessageBuilder);240 controlMessageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");241 242 context.setVariable("myText", "Hello World!");243 244 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");245 reset(endpoint, consumer, endpointConfiguration);246 when(endpoint.createConsumer()).thenReturn(consumer);247 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);248 when(endpointConfiguration.getTimeout()).thenReturn(5000L);249 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);250 when(endpoint.getActor()).thenReturn(null);251 252 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 253 validationContexts.add(validationContext);254 receiveAction.setValidationContexts(validationContexts);255 receiveAction.execute(context);256 }257 258 @Test259 @SuppressWarnings({ "unchecked", "rawtypes" })260 public void testReceiveMessageWithMessagePayloadResourceVariablesSupport() {261 ReceiveMessageAction receiveAction = new ReceiveMessageAction();262 receiveAction.setEndpoint(endpoint);263 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();264 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();265 receiveAction.setMessageBuilder(controlMessageBuilder);266 controlMessageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload-with-variables.xml");267 268 context.setVariable("myText", "Hello World!");269 270 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");271 reset(endpoint, consumer, endpointConfiguration);272 when(endpoint.createConsumer()).thenReturn(consumer);273 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);274 when(endpointConfiguration.getTimeout()).thenReturn(5000L);275 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);276 when(endpoint.getActor()).thenReturn(null);277 278 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 279 validationContexts.add(validationContext);280 receiveAction.setValidationContexts(validationContexts);281 receiveAction.execute(context);282 }283 284 @Test285 @SuppressWarnings({ "unchecked", "rawtypes" })286 public void testReceiveMessageWithMessagePayloadResourceFunctionsSupport() {287 ReceiveMessageAction receiveAction = new ReceiveMessageAction();288 receiveAction.setEndpoint(endpoint);289 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();290 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();291 receiveAction.setMessageBuilder(controlMessageBuilder);292 controlMessageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload-with-functions.xml");293 294 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");295 reset(endpoint, consumer, endpointConfiguration);296 when(endpoint.createConsumer()).thenReturn(consumer);297 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);298 when(endpointConfiguration.getTimeout()).thenReturn(5000L);299 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);300 when(endpoint.getActor()).thenReturn(null);301 302 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 303 validationContexts.add(validationContext);304 receiveAction.setValidationContexts(validationContexts);305 receiveAction.execute(context);306 }307 308 @Test309 @SuppressWarnings({ "unchecked", "rawtypes" })310 public void testReceiveMessageOverwriteMessageElementsXPath() {311 ReceiveMessageAction receiveAction = new ReceiveMessageAction();312 receiveAction.setEndpoint(endpoint);313 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();314 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();315 receiveAction.setMessageBuilder(controlMessageBuilder);316 controlMessageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>");317 318 Map<String, String> overwriteElements = new HashMap<String, String>();319 overwriteElements.put("/TestRequest/Message", "Hello World!");320 321 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);322 controlMessageBuilder.add(interceptor);323 324 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");325 reset(endpoint, consumer, endpointConfiguration);326 when(endpoint.createConsumer()).thenReturn(consumer);327 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);328 when(endpointConfiguration.getTimeout()).thenReturn(5000L);329 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);330 when(endpoint.getActor()).thenReturn(null);331 332 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 333 validationContexts.add(validationContext);334 receiveAction.setValidationContexts(validationContexts);335 receiveAction.execute(context);336 }337 @Test338 @SuppressWarnings({ "unchecked", "rawtypes" })339 public void testReceiveMessageOverwriteMessageElementsJsonPath() {340 ReceiveMessageAction receiveAction = new ReceiveMessageAction();341 receiveAction.setMessageType(MessageType.JSON.toString());342 receiveAction.setEndpoint(endpoint);343 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();344 JsonMessageValidationContext validationContext = new JsonMessageValidationContext();345 receiveAction.setMessageBuilder(controlMessageBuilder);346 controlMessageBuilder.setPayloadData("{ \"TestRequest\": { \"Message\": \"?\" }}");347 Map<String, String> overwriteElements = new HashMap<String, String>();348 overwriteElements.put("$.TestRequest.Message", "Hello World!");349 JsonPathMessageConstructionInterceptor interceptor = new JsonPathMessageConstructionInterceptor(overwriteElements);350 controlMessageBuilder.add(interceptor);351 Message controlMessage = new DefaultMessage("{ \"TestRequest\": { \"Message\": \"Hello World!\" }}");352 reset(endpoint, consumer, endpointConfiguration);353 when(endpoint.createConsumer()).thenReturn(consumer);354 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);355 when(endpointConfiguration.getTimeout()).thenReturn(5000L);356 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);357 when(endpoint.getActor()).thenReturn(null);358 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();359 validationContexts.add(validationContext);360 receiveAction.setValidationContexts(validationContexts);361 receiveAction.execute(context);362 }363 364 @Test365 @SuppressWarnings({ "unchecked", "rawtypes" })366 public void testReceiveMessageOverwriteMessageElementsDotNotation() {367 ReceiveMessageAction receiveAction = new ReceiveMessageAction();368 receiveAction.setEndpoint(endpoint);369 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();370 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();371 receiveAction.setMessageBuilder(controlMessageBuilder);372 controlMessageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>");373 374 Map<String, String> overwriteElements = new HashMap<String, String>();375 overwriteElements.put("TestRequest.Message", "Hello World!");376 377 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);378 controlMessageBuilder.add(interceptor);379 380 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");381 reset(endpoint, consumer, endpointConfiguration);382 when(endpoint.createConsumer()).thenReturn(consumer);383 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);384 when(endpointConfiguration.getTimeout()).thenReturn(5000L);385 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);386 when(endpoint.getActor()).thenReturn(null);387 388 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 389 validationContexts.add(validationContext);390 receiveAction.setValidationContexts(validationContexts);391 receiveAction.execute(context);392 }393 394 @Test395 @SuppressWarnings({ "unchecked", "rawtypes" })396 public void testReceiveMessageOverwriteMessageElementsXPathWithNamespaces() {397 ReceiveMessageAction receiveAction = new ReceiveMessageAction();398 receiveAction.setEndpoint(endpoint);399 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();400 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();401 receiveAction.setMessageBuilder(controlMessageBuilder);402 controlMessageBuilder.setPayloadData("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +403 "<ns0:Message>?</ns0:Message></ns0:TestRequest>");404 405 Map<String, String> overwriteElements = new HashMap<String, String>();406 overwriteElements.put("/ns0:TestRequest/ns0:Message", "Hello World!");407 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);408 controlMessageBuilder.add(interceptor);409 410 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +411 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");412 reset(endpoint, consumer, endpointConfiguration);413 when(endpoint.createConsumer()).thenReturn(consumer);414 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);415 when(endpointConfiguration.getTimeout()).thenReturn(5000L);416 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);417 when(endpoint.getActor()).thenReturn(null);418 validationContext.setSchemaValidation(false);419 420 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 421 validationContexts.add(validationContext);422 receiveAction.setValidationContexts(validationContexts);423 receiveAction.execute(context);424 }425 426 @Test427 @SuppressWarnings({ "unchecked", "rawtypes" })428 public void testReceiveMessageOverwriteMessageElementsXPathWithNestedNamespaces() {429 ReceiveMessageAction receiveAction = new ReceiveMessageAction();430 receiveAction.setEndpoint(endpoint);431 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();432 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();433 receiveAction.setMessageBuilder(controlMessageBuilder);434 controlMessageBuilder.setPayloadData("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +435 "<ns1:Message xmlns:ns1=\"http://citrusframework.org/unittest/message\">?</ns1:Message></ns0:TestRequest>");436 437 Map<String, String> overwriteElements = new HashMap<String, String>();438 overwriteElements.put("/ns0:TestRequest/ns1:Message", "Hello World!");439 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);440 controlMessageBuilder.add(interceptor);441 442 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +443 "<ns1:Message xmlns:ns1=\"http://citrusframework.org/unittest/message\">Hello World!</ns1:Message></ns0:TestRequest>");444 reset(endpoint, consumer, endpointConfiguration);445 when(endpoint.createConsumer()).thenReturn(consumer);446 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);447 when(endpointConfiguration.getTimeout()).thenReturn(5000L);448 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);449 when(endpoint.getActor()).thenReturn(null);450 validationContext.setSchemaValidation(false);451 452 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 453 validationContexts.add(validationContext);454 receiveAction.setValidationContexts(validationContexts);455 receiveAction.execute(context);456 }457 458 @Test459 @SuppressWarnings({ "unchecked", "rawtypes" })460 public void testReceiveMessageOverwriteMessageElementsXPathWithDefaultNamespaces() {461 ReceiveMessageAction receiveAction = new ReceiveMessageAction();462 receiveAction.setEndpoint(endpoint);463 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();464 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();465 receiveAction.setMessageBuilder(controlMessageBuilder);466 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +467 "<Message>?</Message></TestRequest>");468 469 Map<String, String> overwriteElements = new HashMap<String, String>();470 overwriteElements.put("/:TestRequest/:Message", "Hello World!");471 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);472 controlMessageBuilder.add(interceptor);473 474 Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\"><Message>Hello World!</Message></TestRequest>");475 reset(endpoint, consumer, endpointConfiguration);476 when(endpoint.createConsumer()).thenReturn(consumer);477 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);478 when(endpointConfiguration.getTimeout()).thenReturn(5000L);479 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);480 when(endpoint.getActor()).thenReturn(null);481 validationContext.setSchemaValidation(false);482 483 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 484 validationContexts.add(validationContext);485 receiveAction.setValidationContexts(validationContexts);486 receiveAction.execute(context);487 }488 489 @Test490 @SuppressWarnings({ "unchecked", "rawtypes" })491 public void testReceiveMessageWithMessageHeaders() {492 ReceiveMessageAction receiveAction = new ReceiveMessageAction();493 receiveAction.setEndpoint(endpoint);494 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();495 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();496 receiveAction.setMessageBuilder(controlMessageBuilder);497 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");498 Map<String, Object> headers = new HashMap<String, Object>();499 headers.put("Operation", "sayHello");500 controlMessageBuilder.setMessageHeaders(headers);501 Map<String, Object> controlHeaders = new HashMap<String, Object>();502 controlHeaders.put("Operation", "sayHello");503 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);504 reset(endpoint, consumer, endpointConfiguration);505 when(endpoint.createConsumer()).thenReturn(consumer);506 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);507 when(endpointConfiguration.getTimeout()).thenReturn(5000L);508 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);509 when(endpoint.getActor()).thenReturn(null);510 511 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 512 validationContexts.add(validationContext);513 receiveAction.setValidationContexts(validationContexts);514 receiveAction.execute(context);515 }516 517 @Test518 @SuppressWarnings({ "unchecked", "rawtypes" })519 public void testReceiveMessageWithMessageHeadersVariablesSupport() {520 ReceiveMessageAction receiveAction = new ReceiveMessageAction();521 receiveAction.setEndpoint(endpoint);522 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();523 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();524 receiveAction.setMessageBuilder(controlMessageBuilder);525 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");526 context.setVariable("myOperation", "sayHello");527 528 Map<String, Object> headers = new HashMap<String, Object>();529 headers.put("Operation", "${myOperation}");530 controlMessageBuilder.setMessageHeaders(headers);531 532 Map<String, Object> controlHeaders = new HashMap<String, Object>();533 controlHeaders.put("Operation", "sayHello");534 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);535 reset(endpoint, consumer, endpointConfiguration);536 when(endpoint.createConsumer()).thenReturn(consumer);537 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);538 when(endpointConfiguration.getTimeout()).thenReturn(5000L);539 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);540 when(endpoint.getActor()).thenReturn(null);541 542 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 543 validationContexts.add(validationContext);544 receiveAction.setValidationContexts(validationContexts);545 receiveAction.execute(context);546 }547 548 @Test549 @SuppressWarnings({ "unchecked", "rawtypes" })550 public void testReceiveMessageWithUnknownVariablesInMessageHeaders() {551 ReceiveMessageAction receiveAction = new ReceiveMessageAction();552 receiveAction.setEndpoint(endpoint);553 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();554 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();555 receiveAction.setMessageBuilder(controlMessageBuilder);556 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");557 Map<String, Object> headers = new HashMap<String, Object>();558 headers.put("Operation", "${myOperation}");559 controlMessageBuilder.setMessageHeaders(headers);560 561 Map<String, Object> controlHeaders = new HashMap<String, Object>();562 controlHeaders.put("Operation", "sayHello");563 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);564 reset(endpoint, consumer, endpointConfiguration);565 when(endpoint.createConsumer()).thenReturn(consumer);566 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);567 when(endpointConfiguration.getTimeout()).thenReturn(5000L);568 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);569 when(endpoint.getActor()).thenReturn(null);570 571 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 572 validationContexts.add(validationContext);573 receiveAction.setValidationContexts(validationContexts);574 try {575 receiveAction.execute(context);576 } catch(CitrusRuntimeException e) {577 Assert.assertEquals(e.getMessage(), "Unknown variable 'myOperation'");578 return;579 }580 }581 582 @Test583 @SuppressWarnings({ "unchecked", "rawtypes" })584 public void testReceiveMessageWithUnknownVariableInMessagePayload() {585 ReceiveMessageAction receiveAction = new ReceiveMessageAction();586 receiveAction.setEndpoint(endpoint);587 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();588 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();589 receiveAction.setMessageBuilder(controlMessageBuilder);590 controlMessageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");591 592 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");593 reset(endpoint, consumer, endpointConfiguration);594 when(endpoint.createConsumer()).thenReturn(consumer);595 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);596 when(endpointConfiguration.getTimeout()).thenReturn(5000L);597 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);598 when(endpoint.getActor()).thenReturn(null);599 600 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 601 validationContexts.add(validationContext);602 receiveAction.setValidationContexts(validationContexts);603 try {604 receiveAction.execute(context);605 } catch(CitrusRuntimeException e) {606 Assert.assertEquals(e.getMessage(), "Unknown variable 'myText'");607 return;608 }609 }610 611 @Test612 @SuppressWarnings({ "unchecked", "rawtypes" })613 public void testReceiveMessageWithExtractVariablesFromHeaders() {614 ReceiveMessageAction receiveAction = new ReceiveMessageAction();615 receiveAction.setEndpoint(endpoint);616 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();617 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();618 receiveAction.setMessageBuilder(controlMessageBuilder);619 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");620 Map<String, String> headers = new HashMap<String, String>();621 headers.put("Operation", "myOperation");622 623 MessageHeaderVariableExtractor headerVariableExtractor = new MessageHeaderVariableExtractor();624 headerVariableExtractor.setHeaderMappings(headers);625 List<VariableExtractor> variableExtractors = new ArrayList<VariableExtractor>();626 variableExtractors.add(headerVariableExtractor);627 receiveAction.addVariableExtractors(headerVariableExtractor);628 629 Map<String, Object> controlHeaders = new HashMap<String, Object>();630 controlHeaders.put("Operation", "sayHello");631 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);632 reset(endpoint, consumer, endpointConfiguration);633 when(endpoint.createConsumer()).thenReturn(consumer);634 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);635 when(endpointConfiguration.getTimeout()).thenReturn(5000L);636 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);637 when(endpoint.getActor()).thenReturn(null);638 639 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 640 validationContexts.add(validationContext);641 receiveAction.setValidationContexts(validationContexts);642 receiveAction.execute(context);643 644 Assert.assertNotNull(context.getVariable("myOperation"));645 Assert.assertEquals(context.getVariable("myOperation"), "sayHello");646 }647 648 @Test649 @SuppressWarnings({ "unchecked", "rawtypes" })650 public void testReceiveMessageWithValidateMessageElementsFromMessageXPath() {651 ReceiveMessageAction receiveAction = new ReceiveMessageAction();652 receiveAction.setEndpoint(endpoint);653 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();654 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();655 receiveAction.setMessageBuilder(controlMessageBuilder);656 Map<String, Object> messageElements = new HashMap<>();657 messageElements.put("/TestRequest/Message", "Hello World!");658 validationContext.setXpathExpressions(messageElements);659 660 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");661 reset(endpoint, consumer, endpointConfiguration);662 when(endpoint.createConsumer()).thenReturn(consumer);663 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);664 when(endpointConfiguration.getTimeout()).thenReturn(5000L);665 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);666 when(endpoint.getActor()).thenReturn(null);667 668 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 669 validationContexts.add(validationContext);670 receiveAction.setValidationContexts(validationContexts);671 receiveAction.execute(context);672 }673 674 @Test675 @SuppressWarnings({ "unchecked", "rawtypes" })676 public void testReceiveMessageWithValidateMessageElementsXPathDefaultNamespaceSupport() {677 ReceiveMessageAction receiveAction = new ReceiveMessageAction();678 receiveAction.setEndpoint(endpoint);679 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();680 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();681 receiveAction.setMessageBuilder(controlMessageBuilder);682 Map<String, Object> messageElements = new HashMap<>();683 messageElements.put("/:TestRequest/:Message", "Hello World!");684 validationContext.setXpathExpressions(messageElements);685 686 Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +687 "<Message>Hello World!</Message></TestRequest>");688 reset(endpoint, consumer, endpointConfiguration);689 when(endpoint.createConsumer()).thenReturn(consumer);690 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);691 when(endpointConfiguration.getTimeout()).thenReturn(5000L);692 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);693 when(endpoint.getActor()).thenReturn(null);694 validationContext.setSchemaValidation(false);695 696 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 697 validationContexts.add(validationContext);698 receiveAction.setValidationContexts(validationContexts);699 receiveAction.execute(context);700 }701 702 @Test703 @SuppressWarnings({ "unchecked", "rawtypes" })704 public void testReceiveMessageWithValidateMessageElementsXPathNamespaceSupport() {705 ReceiveMessageAction receiveAction = new ReceiveMessageAction();706 receiveAction.setEndpoint(endpoint);707 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();708 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();709 receiveAction.setMessageBuilder(controlMessageBuilder);710 Map<String, Object> messageElements = new HashMap<>();711 messageElements.put("/ns0:TestRequest/ns0:Message", "Hello World!");712 validationContext.setXpathExpressions(messageElements);713 714 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +715 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");716 reset(endpoint, consumer, endpointConfiguration);717 when(endpoint.createConsumer()).thenReturn(consumer);718 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);719 when(endpointConfiguration.getTimeout()).thenReturn(5000L);720 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);721 when(endpoint.getActor()).thenReturn(null);722 validationContext.setSchemaValidation(false);723 724 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 725 validationContexts.add(validationContext);726 receiveAction.setValidationContexts(validationContexts);727 receiveAction.execute(context);728 }729 730 @Test731 @SuppressWarnings({ "unchecked", "rawtypes" })732 public void testReceiveMessageWithValidateMessageElementsXPathNestedNamespaceSupport() {733 ReceiveMessageAction receiveAction = new ReceiveMessageAction();734 receiveAction.setEndpoint(endpoint);735 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();736 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();737 receiveAction.setMessageBuilder(controlMessageBuilder);738 Map<String, Object> messageElements = new HashMap<>();739 messageElements.put("/ns0:TestRequest/ns1:Message", "Hello World!");740 validationContext.setXpathExpressions(messageElements);741 742 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +743 "<ns1:Message xmlns:ns1=\"http://citrusframework.org/unittest/message\">Hello World!</ns1:Message></ns0:TestRequest>");744 reset(endpoint, consumer, endpointConfiguration);745 when(endpoint.createConsumer()).thenReturn(consumer);746 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);747 when(endpointConfiguration.getTimeout()).thenReturn(5000L);748 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);749 when(endpoint.getActor()).thenReturn(null);750 validationContext.setSchemaValidation(false);751 752 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 753 validationContexts.add(validationContext);754 receiveAction.setValidationContexts(validationContexts);755 receiveAction.execute(context);756 }757 758 @Test759 @SuppressWarnings({ "unchecked", "rawtypes" })760 public void testReceiveMessageWithValidateMessageElementsXPathNamespaceBindings() {761 ReceiveMessageAction receiveAction = new ReceiveMessageAction();762 receiveAction.setEndpoint(endpoint);763 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();764 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();765 receiveAction.setMessageBuilder(controlMessageBuilder);766 Map<String, Object> messageElements = new HashMap<>();767 messageElements.put("/pfx:TestRequest/pfx:Message", "Hello World!");768 validationContext.setXpathExpressions(messageElements);769 770 Map<String, String> namespaces = new HashMap<String, String>();771 namespaces.put("pfx", "http://citrusframework.org/unittest");772 validationContext.setNamespaces(namespaces);773 774 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +775 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");776 reset(endpoint, consumer, endpointConfiguration);777 when(endpoint.createConsumer()).thenReturn(consumer);778 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);779 when(endpointConfiguration.getTimeout()).thenReturn(5000L);780 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);781 when(endpoint.getActor()).thenReturn(null);782 validationContext.setSchemaValidation(false);783 784 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 785 validationContexts.add(validationContext);786 receiveAction.setValidationContexts(validationContexts);787 receiveAction.execute(context);788 }789 @Test790 @SuppressWarnings({ "unchecked", "rawtypes" })791 public void testReceiveMessageWithExtractVariablesFromMessageJsonPath() {792 ReceiveMessageAction receiveAction = new ReceiveMessageAction();793 receiveAction.setEndpoint(endpoint);794 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();795 JsonMessageValidationContext validationContext = new JsonMessageValidationContext();796 receiveAction.setMessageBuilder(controlMessageBuilder);797 controlMessageBuilder.setPayloadData("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");798 Map<String, String> extractMessageElements = new HashMap<String, String>();799 extractMessageElements.put("$.text", "messageVar");800 extractMessageElements.put("$.person", "person");801 JsonPathVariableExtractor variableExtractor = new JsonPathVariableExtractor();802 variableExtractor.setJsonPathExpressions(extractMessageElements);803 receiveAction.addVariableExtractors(variableExtractor);804 Message controlMessage = new DefaultMessage("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");805 reset(endpoint, consumer, endpointConfiguration);806 when(endpoint.createConsumer()).thenReturn(consumer);807 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);808 when(endpointConfiguration.getTimeout()).thenReturn(5000L);809 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);810 when(endpoint.getActor()).thenReturn(null);811 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();812 validationContexts.add(validationContext);813 receiveAction.setValidationContexts(validationContexts);814 receiveAction.execute(context);815 Assert.assertNotNull(context.getVariable("messageVar"));816 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");817 Assert.assertNotNull(context.getVariable("person"));818 Assert.assertTrue(context.getVariable("person").contains("\"John\""));819 }820 821 @Test822 @SuppressWarnings({ "unchecked", "rawtypes" })823 public void testReceiveMessageWithExtractVariablesFromMessageXPath() {824 ReceiveMessageAction receiveAction = new ReceiveMessageAction();825 receiveAction.setEndpoint(endpoint);826 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();827 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();828 receiveAction.setMessageBuilder(controlMessageBuilder);829 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");830 Map<String, String> extractMessageElements = new HashMap<String, String>();831 extractMessageElements.put("/TestRequest/Message", "messageVar");832 833 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();834 variableExtractor.setXpathExpressions(extractMessageElements);835 receiveAction.addVariableExtractors(variableExtractor);836 837 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");838 reset(endpoint, consumer, endpointConfiguration);839 when(endpoint.createConsumer()).thenReturn(consumer);840 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);841 when(endpointConfiguration.getTimeout()).thenReturn(5000L);842 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);843 when(endpoint.getActor()).thenReturn(null);844 845 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 846 validationContexts.add(validationContext);847 receiveAction.setValidationContexts(validationContexts);848 receiveAction.execute(context);849 850 Assert.assertNotNull(context.getVariable("messageVar"));851 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");852 }853 @Test854 @SuppressWarnings({ "unchecked", "rawtypes" })855 public void testReceiveMessageWithExtractVariablesFromMessageXPathNodeList() {856 ReceiveMessageAction receiveAction = new ReceiveMessageAction();857 receiveAction.setEndpoint(endpoint);858 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();859 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();860 receiveAction.setMessageBuilder(controlMessageBuilder);861 controlMessageBuilder.setPayloadData("<TestRequest>" +862 "<Message>Hello</Message>" +863 "<Message>ByeBye</Message>" +864 "</TestRequest>");865 Map<String, String> extractMessageElements = new HashMap<String, String>();866 extractMessageElements.put("node-set://TestRequest/Message", "messageVar");867 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();868 variableExtractor.setXpathExpressions(extractMessageElements);869 receiveAction.addVariableExtractors(variableExtractor);870 Message controlMessage = new DefaultMessage("<TestRequest>" +871 "<Message>Hello</Message>" +872 "<Message>ByeBye</Message>" +873 "</TestRequest>");874 reset(endpoint, consumer, endpointConfiguration);875 when(endpoint.createConsumer()).thenReturn(consumer);876 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);877 when(endpointConfiguration.getTimeout()).thenReturn(5000L);878 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);879 when(endpoint.getActor()).thenReturn(null);880 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();881 validationContexts.add(validationContext);882 receiveAction.setValidationContexts(validationContexts);883 receiveAction.execute(context);884 Assert.assertNotNull(context.getVariable("messageVar"));885 Assert.assertEquals(context.getVariable("messageVar"), "Hello,ByeBye");886 }887 @Test888 @SuppressWarnings({ "unchecked", "rawtypes" })889 public void testReceiveMessageWithExtractVariablesFromMessageXPathDefaultNamespaceSupport() {890 ReceiveMessageAction receiveAction = new ReceiveMessageAction();891 receiveAction.setEndpoint(endpoint);892 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();893 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();894 receiveAction.setMessageBuilder(controlMessageBuilder);895 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +896 "<Message>Hello World!</Message></TestRequest>");897 Map<String, String> extractMessageElements = new HashMap<String, String>();898 extractMessageElements.put("/:TestRequest/:Message", "messageVar");899 900 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();901 variableExtractor.setXpathExpressions(extractMessageElements);902 receiveAction.addVariableExtractors(variableExtractor);903 904 Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +905 "<Message>Hello World!</Message></TestRequest>");906 reset(endpoint, consumer, endpointConfiguration);907 when(endpoint.createConsumer()).thenReturn(consumer);908 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);909 when(endpointConfiguration.getTimeout()).thenReturn(5000L);910 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);911 when(endpoint.getActor()).thenReturn(null);912 913 validationContext.setSchemaValidation(false);914 915 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 916 validationContexts.add(validationContext);917 receiveAction.setValidationContexts(validationContexts);918 receiveAction.execute(context);919 920 Assert.assertNotNull(context.getVariable("messageVar"));921 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");922 }923 924 @Test925 @SuppressWarnings({ "unchecked", "rawtypes" })926 public void testReceiveMessageWithExtractVariablesFromMessageXPathNamespaceSupport() {927 ReceiveMessageAction receiveAction = new ReceiveMessageAction();928 receiveAction.setEndpoint(endpoint);929 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();930 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();931 receiveAction.setMessageBuilder(controlMessageBuilder);932 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +933 "<Message>Hello World!</Message></TestRequest>");934 935 Map<String, String> extractMessageElements = new HashMap<String, String>();936 extractMessageElements.put("/ns0:TestRequest/ns0:Message", "messageVar");937 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();938 variableExtractor.setXpathExpressions(extractMessageElements);939 receiveAction.addVariableExtractors(variableExtractor);940 941 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +942 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");943 reset(endpoint, consumer, endpointConfiguration);944 when(endpoint.createConsumer()).thenReturn(consumer);945 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);946 when(endpointConfiguration.getTimeout()).thenReturn(5000L);947 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);948 when(endpoint.getActor()).thenReturn(null);949 950 validationContext.setSchemaValidation(false);951 952 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 953 validationContexts.add(validationContext);954 receiveAction.setValidationContexts(validationContexts);955 receiveAction.execute(context);956 957 Assert.assertNotNull(context.getVariable("messageVar"));958 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");959 }960 961 @Test962 @SuppressWarnings({ "unchecked", "rawtypes" })963 public void testReceiveMessageWithExtractVariablesFromMessageXPathNestedNamespaceSupport() {964 ReceiveMessageAction receiveAction = new ReceiveMessageAction();965 receiveAction.setEndpoint(endpoint);966 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();967 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();968 receiveAction.setMessageBuilder(controlMessageBuilder);969 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\" xmlns:ns1=\"http://citrusframework.org/unittest/message\">" +970 "<ns1:Message>Hello World!</ns1:Message></TestRequest>");971 Map<String, String> extractMessageElements = new HashMap<String, String>();972 extractMessageElements.put("/ns0:TestRequest/ns1:Message", "messageVar");973 974 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();975 variableExtractor.setXpathExpressions(extractMessageElements);976 receiveAction.addVariableExtractors(variableExtractor);977 978 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +979 "<ns1:Message xmlns:ns1=\"http://citrusframework.org/unittest/message\">Hello World!</ns1:Message></ns0:TestRequest>");980 reset(endpoint, consumer, endpointConfiguration);981 when(endpoint.createConsumer()).thenReturn(consumer);982 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);983 when(endpointConfiguration.getTimeout()).thenReturn(5000L);984 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);985 when(endpoint.getActor()).thenReturn(null);986 987 validationContext.setSchemaValidation(false);988 989 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 990 validationContexts.add(validationContext);991 receiveAction.setValidationContexts(validationContexts);992 receiveAction.execute(context);993 994 Assert.assertNotNull(context.getVariable("messageVar"));995 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");996 }997 998 @Test999 @SuppressWarnings({ "unchecked", "rawtypes" })1000 public void testReceiveMessageWithExtractVariablesFromMessageXPathNamespaceBindings() {1001 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1002 receiveAction.setEndpoint(endpoint);1003 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1004 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1005 receiveAction.setMessageBuilder(controlMessageBuilder);1006 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +1007 "<Message>Hello World!</Message></TestRequest>");1008 Map<String, String> extractMessageElements = new HashMap<String, String>();1009 extractMessageElements.put("/pfx:TestRequest/pfx:Message", "messageVar");1010 1011 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();1012 variableExtractor.setXpathExpressions(extractMessageElements);1013 receiveAction.addVariableExtractors(variableExtractor);1014 1015 Map<String, String> namespaces = new HashMap<String, String>();1016 namespaces.put("pfx", "http://citrusframework.org/unittest");1017 variableExtractor.setNamespaces(namespaces);1018 1019 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +1020 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");1021 reset(endpoint, consumer, endpointConfiguration);1022 when(endpoint.createConsumer()).thenReturn(consumer);1023 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1024 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1025 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1026 when(endpoint.getActor()).thenReturn(null);1027 1028 validationContext.setSchemaValidation(false);1029 1030 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1031 validationContexts.add(validationContext);1032 receiveAction.setValidationContexts(validationContexts);1033 receiveAction.execute(context);1034 1035 Assert.assertNotNull(context.getVariable("messageVar"));1036 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");1037 }1038 @Test1039 public void testReceiveMessageWithJsonPathValidation() {1040 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1041 receiveAction.setEndpoint(endpoint);1042 receiveAction.setMessageType(MessageType.JSON.toString());1043 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1044 JsonPathMessageValidationContext validationContext = new JsonPathMessageValidationContext();1045 receiveAction.setMessageBuilder(controlMessageBuilder);1046 Map<String, Object> jsonPathExpressions = new HashMap<>();1047 jsonPathExpressions.put("$..text", "Hello World!");1048 jsonPathExpressions.put("$.person.name", "John");1049 jsonPathExpressions.put("$.person.surname", "Doe");1050 jsonPathExpressions.put("$.index", "5");1051 validationContext.setJsonPathExpressions(jsonPathExpressions);1052 Message controlMessage = new DefaultMessage("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");1053 reset(endpoint, consumer, endpointConfiguration);1054 when(endpoint.createConsumer()).thenReturn(consumer);1055 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1056 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1057 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1058 when(endpoint.getActor()).thenReturn(null);1059 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();1060 validationContexts.add(validationContext);1061 receiveAction.setValidationContexts(validationContexts);1062 receiveAction.execute(context);1063 }1064 @Test(expectedExceptions = ValidationException.class)1065 public void testReceiveMessageWithJsonPathValidationFailure() {1066 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1067 receiveAction.setEndpoint(endpoint);1068 receiveAction.setMessageType(MessageType.JSON.toString());1069 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1070 JsonPathMessageValidationContext validationContext = new JsonPathMessageValidationContext();1071 receiveAction.setMessageBuilder(controlMessageBuilder);1072 Map<String, Object> jsonPathExpressions = new HashMap<>();1073 jsonPathExpressions.put("$..text", "Hello Citrus!");1074 validationContext.setJsonPathExpressions(jsonPathExpressions);1075 Message controlMessage = new DefaultMessage("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");1076 reset(endpoint, consumer, endpointConfiguration);1077 when(endpoint.createConsumer()).thenReturn(consumer);1078 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1079 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1080 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1081 when(endpoint.getActor()).thenReturn(null);1082 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();1083 validationContexts.add(validationContext);1084 receiveAction.setValidationContexts(validationContexts);1085 receiveAction.execute(context);1086 }1087 @Test(expectedExceptions = CitrusRuntimeException.class)1088 public void testReceiveMessageWithJsonPathValidationNoPathResult() {1089 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1090 receiveAction.setEndpoint(endpoint);1091 receiveAction.setMessageType(MessageType.JSON.toString());1092 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1093 JsonPathMessageValidationContext validationContext = new JsonPathMessageValidationContext();1094 receiveAction.setMessageBuilder(controlMessageBuilder);1095 Map<String, Object> jsonPathExpressions = new HashMap<>();1096 jsonPathExpressions.put("$.person.age", "50");1097 validationContext.setJsonPathExpressions(jsonPathExpressions);1098 Message controlMessage = new DefaultMessage("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");1099 reset(endpoint, consumer, endpointConfiguration);1100 when(endpoint.createConsumer()).thenReturn(consumer);1101 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1102 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1103 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1104 when(endpoint.getActor()).thenReturn(null);1105 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();1106 validationContexts.add(validationContext);1107 receiveAction.setValidationContexts(validationContexts);1108 receiveAction.execute(context);1109 }1110 1111 @Test1112 @SuppressWarnings({ "unchecked", "rawtypes" })1113 public void testReceiveMessageWithTimeout() {1114 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1115 receiveAction.setEndpoint(endpoint);1116 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1117 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1118 receiveAction.setMessageBuilder(controlMessageBuilder);1119 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1120 1121 receiveAction.setReceiveTimeout(3000L);1122 1123 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");1124 reset(endpoint, consumer, endpointConfiguration);1125 when(endpoint.createConsumer()).thenReturn(consumer);1126 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1127 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1128 when(consumer.receive(context, 3000L)).thenReturn(controlMessage);1129 when(endpoint.getActor()).thenReturn(null);1130 1131 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1132 validationContexts.add(validationContext);1133 receiveAction.setValidationContexts(validationContexts);1134 receiveAction.execute(context);1135 }1136 1137 @Test1138 @SuppressWarnings({ "unchecked", "rawtypes" })1139 public void testReceiveSelectedWithMessageSelector() {1140 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1141 receiveAction.setEndpoint(endpoint);1142 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1143 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1144 receiveAction.setMessageBuilder(controlMessageBuilder);1145 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1146 1147 String messageSelector = "Operation = 'sayHello'";1148 receiveAction.setMessageSelector(messageSelector);1149 1150 Map<String, Object> headers = new HashMap<String, Object>();1151 headers.put("Operation", "sayHello");1152 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);1153 reset(endpoint, consumer, endpointConfiguration);1154 when(endpoint.createConsumer()).thenReturn(consumer);1155 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1156 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1157 when(consumer.receive(messageSelector, context, 5000L)).thenReturn(controlMessage);1158 when(endpoint.getActor()).thenReturn(null);1159 1160 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1161 validationContexts.add(validationContext);1162 receiveAction.setValidationContexts(validationContexts);1163 receiveAction.execute(context);1164 }1165 1166 @Test1167 @SuppressWarnings({ "unchecked", "rawtypes" })1168 public void testReceiveSelectedWithMessageSelectorAndTimeout() {1169 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1170 receiveAction.setEndpoint(endpoint);1171 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1172 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1173 receiveAction.setMessageBuilder(controlMessageBuilder);1174 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1175 1176 receiveAction.setReceiveTimeout(5000L);1177 1178 String messageSelector = "Operation = 'sayHello'";1179 receiveAction.setMessageSelector(messageSelector);1180 1181 Map<String, Object> headers = new HashMap<String, Object>();1182 headers.put("Operation", "sayHello");1183 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);1184 reset(endpoint, consumer, endpointConfiguration);1185 when(endpoint.createConsumer()).thenReturn(consumer);1186 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1187 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1188 when(consumer.receive(messageSelector, context, 5000L)).thenReturn(controlMessage);1189 when(endpoint.getActor()).thenReturn(null);1190 1191 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1192 validationContexts.add(validationContext);1193 receiveAction.setValidationContexts(validationContexts);1194 receiveAction.execute(context);1195 }1196 1197 @Test1198 @SuppressWarnings({ "unchecked", "rawtypes" })1199 public void testReceiveSelectedWithMessageSelectorMap() {1200 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1201 receiveAction.setEndpoint(endpoint);1202 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1203 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1204 receiveAction.setMessageBuilder(controlMessageBuilder);1205 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1206 1207 Map<String, Object> messageSelector = new HashMap<>();1208 messageSelector.put("Operation", "sayHello");1209 receiveAction.setMessageSelectorMap(messageSelector);1210 1211 Map<String, Object> headers = new HashMap<String, Object>();1212 headers.put("Operation", "sayHello");1213 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);1214 reset(endpoint, consumer, endpointConfiguration);1215 when(endpoint.createConsumer()).thenReturn(consumer);1216 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1217 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1218 when(consumer.receive("Operation = 'sayHello'", context, 5000L)).thenReturn(controlMessage);1219 when(endpoint.getActor()).thenReturn(null);1220 1221 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();1222 validationContexts.add(validationContext);1223 receiveAction.setValidationContexts(validationContexts);1224 receiveAction.execute(context);1225 }1226 1227 @Test1228 @SuppressWarnings({ "unchecked", "rawtypes" })1229 public void testReceiveSelectedWithMessageSelectorMapAndTimeout() {1230 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1231 receiveAction.setEndpoint(endpoint);1232 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1233 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1234 receiveAction.setMessageBuilder(controlMessageBuilder);1235 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1236 1237 receiveAction.setReceiveTimeout(5000L);1238 1239 Map<String, Object> messageSelector = new HashMap<>();1240 messageSelector.put("Operation", "sayHello");1241 receiveAction.setMessageSelectorMap(messageSelector);1242 1243 Map<String, Object> headers = new HashMap<String, Object>();1244 headers.put("Operation", "sayHello");1245 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);1246 reset(endpoint, consumer, endpointConfiguration);1247 when(endpoint.createConsumer()).thenReturn(consumer);1248 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1249 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1250 when(consumer.receive("Operation = 'sayHello'", context, 5000L)).thenReturn(controlMessage);1251 when(endpoint.getActor()).thenReturn(null);1252 1253 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1254 validationContexts.add(validationContext);1255 receiveAction.setValidationContexts(validationContexts);1256 receiveAction.execute(context);1257 }1258 1259 @Test1260 public void testMessageTimeout() {1261 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1262 receiveAction.setEndpoint(endpoint);1263 1264 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1265 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1266 receiveAction.setMessageBuilder(controlMessageBuilder);1267 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1268 reset(endpoint, consumer, endpointConfiguration);1269 when(endpoint.createConsumer()).thenReturn(consumer);1270 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1271 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1272 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(null);1273 when(endpoint.getActor()).thenReturn(null);1274 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();1275 validationContexts.add(validationContext);1276 receiveAction.setValidationContexts(validationContexts);1277 try {1278 receiveAction.execute(context);1279 } catch(CitrusRuntimeException e) {1280 Assert.assertEquals(e.getMessage(), "Failed to receive message - message is not available");1281 return;1282 }1283 1284 Assert.fail("Missing " + CitrusRuntimeException.class + " for receiving no message");1285 }1286 1287 @Test1288 @SuppressWarnings({ "unchecked", "rawtypes" })1289 public void testReceiveEmptyMessagePayloadAsExpected() {1290 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1291 receiveAction.setEndpoint(endpoint);1292 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1293 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1294 receiveAction.setMessageBuilder(controlMessageBuilder);1295 controlMessageBuilder.setPayloadData("");1296 1297 Message controlMessage = new DefaultMessage("");1298 reset(endpoint, consumer, endpointConfiguration);1299 when(endpoint.createConsumer()).thenReturn(consumer);1300 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1301 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1302 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1303 when(endpoint.getActor()).thenReturn(null);1304 1305 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1306 validationContexts.add(validationContext);1307 receiveAction.setValidationContexts(validationContexts);1308 receiveAction.execute(context);1309 }1310 1311 @Test1312 @SuppressWarnings({ "unchecked", "rawtypes" })1313 public void testReceiveEmptyMessagePayloadUnexpected() {1314 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1315 receiveAction.setEndpoint(endpoint);1316 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1317 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1318 receiveAction.setMessageBuilder(controlMessageBuilder);1319 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1320 1321 Message controlMessage = new DefaultMessage("");1322 reset(endpoint, consumer, endpointConfiguration);1323 when(endpoint.createConsumer()).thenReturn(consumer);1324 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1325 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1326 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1327 when(endpoint.getActor()).thenReturn(null);1328 1329 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1330 validationContexts.add(validationContext);1331 receiveAction.setValidationContexts(validationContexts);1332 try {1333 receiveAction.execute(context);1334 } catch(CitrusRuntimeException e) {1335 Assert.assertEquals(e.getMessage(), "Validation failed: Unable to validate message payload - received message payload was empty, control message payload is not");1336 return;1337 }1338 1339 Assert.fail("Missing " + CitrusRuntimeException.class + " for receiving unexpected empty message payload");1340 }1341 1342 @Test1343 @SuppressWarnings({ "unchecked", "rawtypes" })1344 public void testReceiveMessageWithValidationScript() {1345 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1346 receiveAction.setEndpoint(endpoint);1347 receiveAction.addValidator(new GroovyXmlMessageValidator());1348 1349 ScriptValidationContext validationContext = new ScriptValidationContext(ScriptTypes.GROOVY);1350 validationContext.setValidationScript("assert root.Message.name() == 'Message'\n" + 1351 "assert root.Message.text() == 'Hello World!'");1352 1353 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");1354 reset(endpoint, consumer, endpointConfiguration);1355 when(endpoint.createConsumer()).thenReturn(consumer);1356 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1357 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1358 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1359 when(endpoint.getActor()).thenReturn(null);1360 1361 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1362 validationContexts.add(validationContext);1363 receiveAction.setValidationContexts(validationContexts);1364 receiveAction.execute(context);1365 }1366 1367 @Test1368 @SuppressWarnings({ "unchecked", "rawtypes" })1369 public void testReceiveMessageWithValidationScriptResource() {1370 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1371 receiveAction.setEndpoint(endpoint);1372 receiveAction.addValidator(new GroovyXmlMessageValidator());1373 ScriptValidationContext validationContext = new ScriptValidationContext(ScriptTypes.GROOVY);1374 validationContext.setValidationScriptResourcePath("classpath:com/consol/citrus/actions/test-validation-script.groovy");1375 1376 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");1377 reset(endpoint, consumer, endpointConfiguration);1378 when(endpoint.createConsumer()).thenReturn(consumer);1379 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1380 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1381 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1382 when(endpoint.getActor()).thenReturn(null);1383 1384 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1385 validationContexts.add(validationContext);1386 receiveAction.setValidationContexts(validationContexts);1387 receiveAction.execute(context);1388 }1389 1390 @Test1391 @SuppressWarnings({ "unchecked", "rawtypes" })1392 public void testInjectedMessageValidators() {1393 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1394 receiveAction.setEndpoint(endpoint);1395 1396 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1397 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1398 receiveAction.setMessageBuilder(controlMessageBuilder);1399 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1400 1401 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");1402 reset(endpoint, consumer, endpointConfiguration);1403 when(endpoint.createConsumer()).thenReturn(consumer);1404 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1405 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1406 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1407 when(endpoint.getActor()).thenReturn(null);1408 1409 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1410 validationContexts.add(validationContext);1411 1412 receiveAction.setValidationContexts(validationContexts);1413 receiveAction.execute(context);1414 1415 // now inject multiple validators1416 List<MessageValidator<? extends ValidationContext>> validators = new ArrayList<MessageValidator<? extends ValidationContext>>();1417 validators.add(new DomXmlMessageValidator());1418 validators.add(new GroovyXmlMessageValidator());1419 1420 MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();1421 messageValidatorRegistry.setMessageValidators(validators);1422 TestContext newContext = createTestContext();1423 newContext.setMessageValidatorRegistry(messageValidatorRegistry);1424 1425 validationContexts = new ArrayList<ValidationContext>();1426 validationContexts.add(validationContext);1427 ScriptValidationContext scriptValidationContext = new ScriptValidationContext(Citrus.DEFAULT_MESSAGE_TYPE);1428 validationContexts.add(scriptValidationContext);1429 receiveAction.setValidationContexts(validationContexts);1430 receiveAction.execute(newContext);1431 }1432 1433 @Test1434 public void testDisabledReceiveMessage() {1435 TestCase testCase = new TestCase();1436 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1437 receiveAction.setEndpoint(endpoint);1438 TestActor disabledActor = new TestActor();1439 disabledActor.setDisabled(true);1440 receiveAction.setActor(disabledActor);1441 1442 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1443 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1444 receiveAction.setMessageBuilder(controlMessageBuilder);1445 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1446 reset(endpoint, consumer, endpointConfiguration);1447 when(endpoint.createConsumer()).thenReturn(consumer);1448 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1449 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1450 when(endpoint.getActor()).thenReturn(null);1451 1452 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1453 validationContexts.add(validationContext);1454 receiveAction.setValidationContexts(validationContexts);1455 testCase.addTestAction(receiveAction);1456 testCase.execute(context);1457 }1458 1459 @Test1460 public void testDisabledReceiveMessageByEndpointActor() {1461 TestCase testCase = new TestCase();1462 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1463 receiveAction.setEndpoint(endpoint);1464 1465 TestActor disabledActor = new TestActor();1466 disabledActor.setDisabled(true);1467 1468 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1469 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1470 receiveAction.setMessageBuilder(controlMessageBuilder);1471 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");1472 reset(endpoint, consumer, endpointConfiguration);1473 when(endpoint.createConsumer()).thenReturn(consumer);1474 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1475 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1476 when(endpoint.getActor()).thenReturn(disabledActor);1477 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1478 validationContexts.add(validationContext);1479 receiveAction.setValidationContexts(validationContexts);1480 testCase.addTestAction(receiveAction);1481 testCase.execute(context);1482 }1483}...

Full Screen

Full Screen

Source:DTDValidationTest.java Github

copy

Full Screen

...89 + "</root>");90 91 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();92 validationContexts.add(validationContext);93 receiveMessageBean.setValidationContexts(validationContexts);94 receiveMessageBean.execute(context);95 }96 97 @Test98 @SuppressWarnings({ "unchecked", "rawtypes" })99 public void testSystemId() {100 reset(endpoint, consumer, endpointConfiguration);101 when(endpoint.createConsumer()).thenReturn(consumer);102 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);103 when(endpointConfiguration.getTimeout()).thenReturn(5000L);104 105 Message message = new DefaultMessage("<!DOCTYPE root SYSTEM \"com/consol/citrus/validation/example.dtd\">"106 + "<root>"107 + "<message>"108 + "<text>Hello TestFramework!</text>"109 + "</message>"110 + "</root>");111 112 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);113 when(endpoint.getActor()).thenReturn(null);114 115 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();116 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();117 receiveMessageBean.setMessageBuilder(controlMessageBuilder);118 controlMessageBuilder.setPayloadData("<!DOCTYPE root SYSTEM \"com/consol/citrus/validation/example.dtd\">"119 + "<root>"120 + "<message>"121 + "<text>Hello TestFramework!</text>"122 + "</message>"123 + "</root>");124 125 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();126 validationContexts.add(validationContext);127 receiveMessageBean.setValidationContexts(validationContexts);128 receiveMessageBean.execute(context);129 }130 131 @Test132 @SuppressWarnings({ "unchecked", "rawtypes" })133 public void testPublicId() {134 reset(endpoint, consumer, endpointConfiguration);135 when(endpoint.createConsumer()).thenReturn(consumer);136 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);137 when(endpointConfiguration.getTimeout()).thenReturn(5000L);138 139 Message message = new DefaultMessage("<!DOCTYPE root PUBLIC \"example\" \"com/consol/citrus/validation/example.dtd\">"140 + "<root>"141 + "<message>"142 + "<text>Hello TestFramework!</text>"143 + "</message>"144 + "</root>");145 146 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);147 when(endpoint.getActor()).thenReturn(null);148 149 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();150 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();151 receiveMessageBean.setMessageBuilder(controlMessageBuilder);152 controlMessageBuilder.setPayloadData("<!DOCTYPE root PUBLIC \"example\" \"com/consol/citrus/validation/example.dtd\">"153 + "<root>"154 + "<message>"155 + "<text>Hello TestFramework!</text>"156 + "</message>"157 + "</root>");158 159 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();160 validationContexts.add(validationContext);161 receiveMessageBean.setValidationContexts(validationContexts);162 receiveMessageBean.execute(context);163 }164 165 @Test166 @SuppressWarnings({ "unchecked", "rawtypes" })167 public void testPublicIdError() {168 reset(endpoint, consumer, endpointConfiguration);169 when(endpoint.createConsumer()).thenReturn(consumer);170 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);171 when(endpointConfiguration.getTimeout()).thenReturn(5000L);172 173 Message message = new DefaultMessage("<!DOCTYPE root PUBLIC \"example\" \"com/consol/citrus/validation/example.dtd\">"174 + "<root>"175 + "<message>"176 + "<text>Hello TestFramework!</text>"177 + "</message>"178 + "</root>");179 180 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);181 when(endpoint.getActor()).thenReturn(null);182 183 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();184 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();185 receiveMessageBean.setMessageBuilder(controlMessageBuilder);186 controlMessageBuilder.setPayloadData("<!DOCTYPE root PUBLIC \"foo\" \"com/consol/citrus/validation/example.dtd\">"187 + "<root>"188 + "<message>"189 + "<text>Hello TestFramework!</text>"190 + "</message>"191 + "</root>");192 193 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();194 validationContexts.add(validationContext);195 receiveMessageBean.setValidationContexts(validationContexts);196 197 try {198 receiveMessageBean.execute(context);199 Assert.fail("Missing validation exception due to mismatch in public id");200 } catch (ValidationException e) {201 Assert.assertTrue(e.getMessage().contains("expected 'foo' but was 'example'"));202 }203 }204 205 @Test206 @SuppressWarnings({ "unchecked", "rawtypes" })207 public void testSystemIdError() {208 reset(endpoint, consumer, endpointConfiguration);209 when(endpoint.createConsumer()).thenReturn(consumer);210 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);211 when(endpointConfiguration.getTimeout()).thenReturn(5000L);212 213 Message message = new DefaultMessage("<!DOCTYPE root PUBLIC \"example\" \"com/consol/citrus/validation/example.dtd\">"214 + "<root>"215 + "<message>"216 + "<text>Hello TestFramework!</text>"217 + "</message>"218 + "</root>");219 220 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);221 when(endpoint.getActor()).thenReturn(null);222 223 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();224 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();225 receiveMessageBean.setMessageBuilder(controlMessageBuilder);226 controlMessageBuilder.setPayloadData("<!DOCTYPE root PUBLIC \"example\" \"org/w3/xhtml/xhtml1-transitional.dtd\">"227 + "<root>"228 + "<message>"229 + "<text>Hello TestFramework!</text>"230 + "</message>"231 + "</root>");232 233 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();234 validationContexts.add(validationContext);235 receiveMessageBean.setValidationContexts(validationContexts);236 237 try {238 receiveMessageBean.execute(context);239 Assert.fail("Missing validation exception due to mismatch in public id");240 } catch (ValidationException e) {241 Assert.assertTrue(e.getMessage().contains("expected 'org/w3/xhtml/xhtml1-transitional.dtd' but was 'com/consol/citrus/validation/example.dtd'"));242 }243 }244}...

Full Screen

Full Screen

Source:IgnoreElementsLegacyTest.java Github

copy

Full Screen

...82 validationContext.setIgnoreExpressions(ignoreMessageElements);83 84 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();85 validationContexts.add(validationContext);86 receiveMessageBean.setValidationContexts(validationContexts);87 88 receiveMessageBean.execute(context);89 }90 91 @Test92 public void testIgnoreAttributes() {93 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();94 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();95 receiveMessageBean.setMessageBuilder(controlMessageBuilder);96 controlMessageBuilder.setPayloadData("<root>"97 + "<element attributeA='attribute-value' attributeB='attribute-value' >"98 + "<sub-elementA attribute='no validation'>text-value</sub-elementA>"99 + "<sub-elementB attribute='no validation'>text-value</sub-elementB>"100 + "<sub-elementC attribute='C'>text-value</sub-elementC>"101 + "</element>" 102 + "</root>");103 104 Set<String> ignoreMessageElements = new HashSet<String>();105 ignoreMessageElements.add("root.element.sub-elementA.attribute");106 ignoreMessageElements.add("sub-elementB.attribute");107 validationContext.setIgnoreExpressions(ignoreMessageElements);108 109 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();110 validationContexts.add(validationContext);111 receiveMessageBean.setValidationContexts(validationContexts);112 113 receiveMessageBean.execute(context);114 }115 116 @Test117 @SuppressWarnings({ "unchecked", "rawtypes" })118 public void testIgnoreRootElement() {119 reset(endpoint, consumer, endpointConfiguration);120 when(endpoint.createConsumer()).thenReturn(consumer);121 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);122 when(endpointConfiguration.getTimeout()).thenReturn(5000L);123 124 Message message = new DefaultMessage("<root>"125 + "<element>Text</element>" 126 + "</root>");127 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);128 when(endpoint.getActor()).thenReturn(null);129 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();130 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();131 receiveMessageBean.setMessageBuilder(controlMessageBuilder);132 controlMessageBuilder.setPayloadData("<root>"133 + "<element additonal-attribute='some'>Wrong text</element>" 134 + "</root>");135 136 Set<String> ignoreMessageElements = new HashSet<String>();137 ignoreMessageElements.add("root");138 validationContext.setIgnoreExpressions(ignoreMessageElements);139 140 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();141 validationContexts.add(validationContext);142 receiveMessageBean.setValidationContexts(validationContexts);143 144 receiveMessageBean.execute(context);145 }146 147 @Test148 public void testIgnoreElementsAndValidate() {149 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();150 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();151 receiveMessageBean.setMessageBuilder(controlMessageBuilder);152 controlMessageBuilder.setPayloadData("<root>"153 + "<element attributeA='attribute-value' attributeB='attribute-value' >"154 + "<sub-elementA attribute='A'>no validation</sub-elementA>"155 + "<sub-elementB attribute='B'>no validation</sub-elementB>"156 + "<sub-elementC attribute='C'>text-value</sub-elementC>"157 + "</element>" 158 + "</root>");159 160 Set<String> ignoreMessageElements = new HashSet<String>();161 ignoreMessageElements.add("root.element.sub-elementA");162 ignoreMessageElements.add("sub-elementB");163 validationContext.setIgnoreExpressions(ignoreMessageElements);164 165 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();166 validationContexts.add(validationContext);167 receiveMessageBean.setValidationContexts(validationContexts);168 169 Map<String, Object> validateElements = new HashMap<>();170 validateElements.put("root.element.sub-elementA", "wrong value");171 validateElements.put("sub-elementB", "wrong value");172 validationContext.setXpathExpressions(validateElements);173 174 receiveMessageBean.execute(context);175 }176}...

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.testng.AbstractTestNGUnitTest;5import com.consol.citrus.validation.builder.DefaultMessageBuilder;6import com.consol.citrus.validation.context.ValidationContext;7import com.consol.citrus.validation.xml.XmlMessageValidationContext;8import org.mockito.Mockito;9import org.testng.annotations.Test;10import java.util.HashMap;11import java.util.Map;12import static org.mockito.Mockito.*;13public class ReceiveMessageActionTest extends AbstractTestNGUnitTest {14 private ValidationContext validationContext = Mockito.mock(XmlMessageValidationContext.class);15 public void testReceiveMessageBuilder() {16 reset(applicationContext);17 Map<String, ValidationContext> validationContexts = new HashMap<>();18 validationContexts.put("foo", validationContext);19 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();20 receiveMessageAction.setApplicationContext(applicationContext);21 receiveMessageAction.setMessageType(MessageType.PLAINTEXT.name());22 receiveMessageAction.setValidationContexts(validationContexts);23 receiveMessageAction.setMessageBuilder(new DefaultMessageBuilder("Foo"));24 receiveMessageAction.setEndpointUri("foo:bar");25 receiveMessageAction.execute(context);26 verify(applicationContext).getBean("foo", ValidationContext.class);27 verify(validationContext).initialize(context);28 verifyNoMoreInteractions(applicationContext, validationContext);29 }30}

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import org.testng.annotations.Test;6public class ReceiveMessageActionTest extends TestNGCitrusTestDesigner {7 public void configure() {8 echo("This is a sample test");9 ReceiveMessageActionBuilder receiveMessageActionBuilder = receive(builder -> builder.messageType("text")10 .payload("Hello World!"));11 receiveMessageActionBuilder.setValidationContexts("validationContext");12 }13}14package com.consol.citrus.dsl.testng;15import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;16import com.consol.citrus.dsl.runner.TestRunner;17import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;18import org.testng.annotations.Test;19public class ReceiveMessageActionTest extends TestNGCitrusTestDesigner {20 public void configure() {21 echo("This is a sample test");22 ReceiveMessageActionBuilder receiveMessageActionBuilder = receive(builder -> builder.messageType("text")23 .payload("Hello World!"));24 receiveMessageActionBuilder.setValidationContexts("validationContext");25 }26}27package com.consol.citrus.dsl.testng;28import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;29import com.consol.citrus.dsl.runner.TestRunner;30import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;31import org.testng.annotations.Test;32public class ReceiveMessageActionTest extends TestNGCitrusTestDesigner {33 public void configure() {34 echo("This is a sample test");35 ReceiveMessageActionBuilder receiveMessageActionBuilder = receive(builder -> builder.messageType("text")36 .payload("Hello World!"));37 receiveMessageActionBuilder.setValidationContexts("validationContext");38 }39}

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.message.MessageType;5import org.springframework.context.ApplicationContext;6public class ReceiveMessageAction extends AbstractTestContainerBuilder<ReceiveMessageActionBuilder> {7 public ReceiveMessageAction(TestRunner runner) {8 super(runner, new ReceiveMessageActionBuilder());9 }10 public ReceiveMessageAction(TestRunner runner, String endpointUri) {11 super(runner, new ReceiveMessageActionBuilder().endpoint(endpointUri));12 }13 public ReceiveMessageAction(TestRunner runner, String endpointUri, String messageSelector) {14 super(runner, new ReceiveMessageActionBuilder().endpoint(endpointUri).selector(messageSelector));15 }16 public ReceiveMessageAction(TestRunner runner, String endpointUri, String messageSelector, String messageCorrelator) {17 super(runner, new ReceiveMessageActionBuilder().endpoint(endpointUri).selector(messageSelector).correlator(messageCorrelator));18 }19 public ReceiveMessageAction(TestRunner runner, String endpointUri, String messageSelector, String messageCorrelator, String messageCorrelatorType) {20 super(runner, new ReceiveMessageActionBuilder().endpoint(endpointUri).selector(messageSelector).correlator(messageCorrelator).correlatorType(messageCorrelatorType));21 }22 public ReceiveMessageAction(TestRunner runner, String endpointUri, String messageSelector, String messageCorrelator, String messageCorrelatorType, String messageCorrelatorExpression) {23 super(runner, new ReceiveMessageActionBuilder().endpoint(endpointUri).selector(messageSelector).correlator(messageCorrelator).correlatorType(messageCorrelatorType).correlatorExpression(messageCorrelatorExpression));24 }25 public ReceiveMessageAction(TestRunner runner, String endpointUri, String messageSelector, String messageCorrelator, String messageCorrelatorType, String messageCorrelatorExpression, String messageCorrelatorResource) {26 super(runner, new ReceiveMessageActionBuilder().endpoint(endpointUri).selector(messageSelector).correlator(messageCorrelator).correlatorType(messageCorrelatorType).correlatorExpression(messageCorrelatorExpression).correlatorResource(messageCorrelatorResource));27 }28 public ReceiveMessageAction(TestRunner runner, String endpointUri, String messageSelector, String messageCor

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.message.MessageType;5import org.springframework.http.HttpStatus;6import org.springframework.http.MediaType;7import org.testng.annotations.Test;8public class ReceiveMessageActionTest extends TestNGCitrusTestDesigner {9 public void receiveMessageActionTest() {10 variable("myVariable", "citrus:concat('Hello ', 'Citrus!')");11 echo("Hello Citrus!");12 http()13 .client("httpClient")14 .send()15 .post("/test")16 .payload("<TestRequestMessage><text>Hello Citrus!</text></TestRequestMessage>");17 http()18 .client("httpClient")19 .receive()20 .response(HttpStatus.OK)21 .contentType(MediaType.APPLICATION_XML_VALUE)22 .payload("<TestResponseMessage><text>Hello Citrus!</text></TestResponseMessage>");23 http()24 .client("httpClient")25 .receive()26 .response(HttpStatus.OK)27 .contentType(MediaType.APPLICATION_XML_VALUE)28 .payload("<TestResponseMessage><text>Hello Citrus!</text></TestResponseMessage>");29 http()30 .client("httpClient")31 .receive()32 .response(HttpStatus.OK)33 .contentType(MediaType.APPLICATION_XML_VALUE)34 .payload("<TestResponseMessage><text>Hello Citrus!</text></TestResponseMessage>");35 http()36 .client("httpClient")37 .receive()38 .response(HttpStatus.OK)39 .contentType(MediaType.APPLICATION_XML_VALUE)40 .payload("<TestResponseMessage><text>Hello Citrus!</text></TestResponseMessage>");41 http()42 .client("httpClient")43 .receive()44 .response(HttpStatus.OK)45 .contentType(MediaType.APPLICATION_XML_VALUE)46 .payload("<TestResponseMessage><text>Hello Citrus!</text></TestResponseMessage>");47 http()48 .client("httpClient")49 .receive()50 .response(HttpStatus.OK)51 .contentType(MediaType.APPLICATION_XML_VALUE)52 .payload("<TestResponseMessage><text>Hello Citrus!</text></TestResponseMessage>");53 http()54 .client("httpClient")55 .receive()56 .response(HttpStatus.OK)57 .contentType(MediaType.APPLICATION_XML_VALUE)58 .payload("<TestResponseMessage><text>Hello Citrus!</text></TestResponseMessage>");59 http()60 .client("httpClient")61 .receive()

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import org.testng.annotations.Test;3import com.consol.citrus.dsl.design.TestDesigner;4import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.validation.xml.XmlMessageValidationContext;7import com.consol.citrus.xml.XsdSchemaRepository;8public class ReceiveMessageActionJavaITest extends TestDesignerBeforeTestSupport {9 public void receiveMessageActionJavaITest() {10 variable("myVar", "citrus:concat('Hello ', 'World!')");11 variable("myVar2", "citrus:concat('Hello ', 'World!')");12 variable("myVar3", "citrus:concat('Hello ', 'World!')");13 variable("myVar4", "citrus:concat('Hello ', 'World!')");14 variable("myVar5", "citrus:concat('Hello ', 'World!')");15 variable("myVar6", "citrus:concat('Hello ', 'World!')");16 variable("myVar7", "citrus:concat('Hello ', 'World!')");17 variable("myVar8", "citrus:concat('Hello ', 'World!')");18 variable("myVar9", "citrus:concat('Hello ', 'World!')");19 variable("myVar10", "citrus:concat('Hello ', 'World!')");20 variable("myVar11", "citrus:concat('Hello ', 'World!')");21 variable("myVar12", "citrus:concat('Hello ', 'World!')");22 variable("myVar13", "citrus:concat('Hello ', 'World!')");23 variable("myVar14", "citrus:concat('Hello ', 'World!')");24 variable("myVar15", "citrus:concat('Hello ', 'World!')");25 variable("myVar16", "citrus:concat('Hello ', 'World!')");26 variable("myVar17", "citrus:concat('Hello ', 'World!')");27 variable("myVar18", "citrus:concat('Hello ', 'World!')");28 variable("myVar19", "citrus:concat('Hello ', 'World!')");29 variable("myVar20", "citrus:concat('Hello ', 'World!')");30 variable("myVar21", "

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import org.springframework.context.annotation.Bean;3import org.springframework.context.annotation.Configuration;4import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;5import com.consol.citrus.dsl.builder.ReceiveTimeoutBuilder;6import com.consol.citrus.dsl.builder.ReceiveTimeoutBuilder.ReceiveTimeoutBuilderSupport;7import com.consol.citrus.dsl.builder.SendMessageActionBuilder;8import com.consol.citrus.dsl.builder.TimeoutBuilder;9import com.consol.citrus.dsl.builder.TimeoutBuilder.TimeoutBuilderSupport;10import com.consol.citrus.dsl.builder.VariableBuilder;11import com.consol.citrus.dsl.builder.VariableBuilder.VariableBuilderSupport;12import com.consol.citrus.dsl.builder.WaitBuilder;13import com.consol.citrus.dsl.builder.WaitBuilder.WaitBuilderSupport;14import com.consol.citrus.dsl.builder.XpathMessageHeaderSupport;15import com.consol.citrus.dsl.builder.XpathPayloadVariableSupport;16import com.consol.citrus.dsl.runner.TestRunnerSupport;17import com.consol.citrus.message.MessageType;18import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;19import com.consol.citrus.validation.context.ValidationContext;20import com.consol.citrus.validation.xml.XmlMessageValidationContext;21import com.consol.citrus.xml.XsdSchemaRepository;22import com.consol.citrus.xml.namespace.NamespaceContextBuilder;23import com.consol.citrus.xml.namespace.SimpleNamespaceContextBuilder;24import com.consol.citrus.xml.schema.XsdSchemaValidationContext;25import com.consol.citrus.xml.schema.XsdSchemaValidationContext.ValidationType;26import com.consol.citrus.xml.xpath.XpathMessageHeaderProcessor;27import com.consol.citrus.xml.xpath.XpathPayloadVariableExtractor;28public class ReceiveMessageActionRunner extends TestRunnerSupport {29 public ReceiveMessageActionBuilder receive(ReceiveMessageActionBuilder.ReceiveMessageActionBuilderSupport builder) {30 return builder(builder);31 }32 public ReceiveMessageActionBuilder receive() {33 return receive(new ReceiveMessageActionBuilderSupportImpl());34 }35 public interface ReceiveMessageActionBuilder extends TestRunnerSupport.Builder<ReceiveMessageAction>, ReceiveMessageActionBuilderSupport {36 }37 public interface ReceiveMessageActionBuilderSupport {38 ReceiveMessageActionBuilder message(Object message);39 ReceiveMessageActionBuilder message(Object message, MessageType messageType);40 ReceiveMessageActionBuilder message(String message);41 ReceiveMessageActionBuilder message(String message, MessageType messageType);

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.testng.CitrusParameters;7import com.consol.citrus.validation.context.ValidationContext;8import org.testng.annotations.Test;9import org.testng.annotations.DataProvider;10import java.util.ArrayList;11import java.util.List;12import com.consol.citrus.context.TestContext;13import com.consol.citrus.exceptions.ValidationException;14import com.consol.citrus.validation.context.DefaultValidationContext;15import com.consol.citrus.validation.json.JsonTextMessageValidator;16import com.consol.citrus.validation.xml.XmlSchemaValidationContext;17import com.consol.citrus.validation.xml.XsdSchemaRepository;18import com.consol.citrus.validation.xml.XmlTextMessageValidator;19import org.springframework.core.io.ClassPathResource;20import org.springframework.xml.xsd.SimpleXsdSchema;21import org.springframework.xml.xsd.XsdSchema;22public class ReceiveMessageAction_SetValidationContexts_ITest extends TestNGCitrusTestDesigner {23@CitrusParameters({"param1"})24@Test(dataProvider = "param1")25public void receiveMessageAction_SetValidationContexts_ITest(String param1) {26TestDesigner designer = new TestDesigner(applicationContext, context) {27public void configure() {28receive(receiveBuilder -> receiveBuilder29.endpoint(endpoint)30.messageType(MessageType.PLAINTEXT)31.payload("<TestMessage>Hello World!</TestMessage>")32.validationContexts(validationContexts)33);34}35};36designer.run();37}38@DataProvider(name = "param1")39public Object[][] getData1() {40return new Object[][] {41new Object[] { "1" },42};43}44}

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;3import org.testng.annotations.Test;4import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;5public class ReceiveMessageActionBuilderTest extends AbstractTestNGCitrusTest {6 public void receiveMessageActionBuilder() {7 variable("var1", "value1");8 variable("var2", "value2");9 run(receive()10 .messageType("XML")11 .message("<TestMessage><text>Hello World!</text></TestMessage>")12 .validationContext("var1", "var2")13 .description("Test description"));14 }15}16package com.consol.citrus.dsl.testng;17import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;18import org.testng.annotations.Test;19import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;20public class ReceiveMessageActionBuilderTest extends AbstractTestNGCitrusTest {21 public void receiveMessageActionBuilder() {22 variable("var1", "value1");23 variable("var2", "value2");24 run(receive()25 .messageType("XML")26 .message("<TestMessage><text>Hello World!</text></TestMessage>")27 .validationContext("var1", "var2")28 .description("Test description"));29 }30}31package com.consol.citrus.dsl.testng;32import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;33import org.testng.annotations.Test;34import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;35public class ReceiveMessageActionBuilderTest extends AbstractTestNGCitrusTest {36 public void receiveMessageActionBuilder() {37 variable("var1", "value1");38 variable("var2", "value2");39 run(receive()40 .messageType("XML")41 .message("<TestMessage><text>Hello World!</text></TestMessage>")42 .validationContext("var1", "var2")43 .description("Test description"));44 }45}

Full Screen

Full Screen

setValidationContexts

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.xml.XmlMessageValidationContext;6import com.consol.citrus.xml.XsdSchemaRepository;7import org.springframework.context.ApplicationContext;8import org.springframework.context.support.ClassPathXmlApplicationContext;9import org.testng.annotations.Test;10public class SetValidationContextsJavaITest extends TestDesignerBeforeTestSupport {11 public void setValidationContextsJavaITest() {12 ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:com/consol/citrus/dsl/design/SetValidationContextsJavaITest-context.xml");13 variable("variable", "value");14 TestDesigner builder = new TestDesigner(applicationContext) {15 public void configure() {16 receive(builder -> builder.endpoint("foo")17 .messageType(MessageType.PLAINTEXT)18 .payload("Hello Citrus!")19 .validationContexts(new XmlMessageValidationContext()20 .schemaRepository(new XsdSchemaRepository()21 .schemas("classpath:com/consol/citrus/dsl/design/SetValidationContextsJavaITest-context.xml"))));22 }23 };24 builder.run(context);25 }26}27package com.consol.citrus.dsl.design;28import com.consol.citrus.dsl.design.TestDesigner;29import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;30import com.consol.citrus.message.MessageType;31import com.consol.citrus.validation.xml.XmlMessageValidationContext;32import com.consol.citrus.xml.XsdSchemaRepository;33import org.springframework.context.ApplicationContext;34import org.springframework.context.support.ClassPathXmlApplicationContext;35import org.testng.annotations.Test;36import java.util.Collections;37public class SetValidationContextsJavaITest extends TestDesignerBeforeTestSupport {38 public void setValidationContextsJavaITest() {39 ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:com/consol/citrus/dsl/design/SetValidationContextsJavaITest-context.xml");

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