How to use setXpathExpressions method of com.consol.citrus.validation.xml.XpathPayloadVariableExtractor class

Best Citrus code snippet using com.consol.citrus.validation.xml.XpathPayloadVariableExtractor.setXpathExpressions

Source:MessageElementsTest.java Github

copy

Full Screen

...76 77 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();78 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();79 receiveMessageBean.setMessageBuilder(controlMessageBuilder);80 validationContext.setXpathExpressions(validateMessageElements);81 82 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();83 validationContexts.add(validationContext);84 receiveMessageBean.setValidationContexts(validationContexts);85 86 receiveMessageBean.execute(context);87 }88 89 @Test90 @SuppressWarnings({ "unchecked", "rawtypes" })91 public void testValidateEmptyMessageElements() {92 reset(endpoint, consumer, endpointConfiguration);93 when(endpoint.createConsumer()).thenReturn(consumer);94 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);95 when(endpointConfiguration.getTimeout()).thenReturn(5000L);96 97 Message message = new DefaultMessage("<root>"98 + "<element attributeA='attribute-value' attributeB='attribute-value' >"99 + "<sub-elementA attribute='A'></sub-elementA>"100 + "<sub-elementB attribute='B'></sub-elementB>"101 + "<sub-elementC attribute='C'>text-value</sub-elementC>"102 + "</element>" 103 + "</root>");104 105 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);106 when(endpoint.getActor()).thenReturn(null);107 HashMap<String, Object> validateMessageElements = new HashMap<>();108 validateMessageElements.put("//root/element/sub-elementA", "");109 validateMessageElements.put("//sub-elementB", "");110 111 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();112 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();113 receiveMessageBean.setMessageBuilder(controlMessageBuilder);114 validationContext.setXpathExpressions(validateMessageElements);115 116 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();117 validationContexts.add(validationContext);118 receiveMessageBean.setValidationContexts(validationContexts);119 120 receiveMessageBean.execute(context);121 }122 123 @Test124 @SuppressWarnings({ "unchecked", "rawtypes" })125 public void testValidateEmptyMessageAttributes() {126 reset(endpoint, consumer, endpointConfiguration);127 when(endpoint.createConsumer()).thenReturn(consumer);128 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);129 when(endpointConfiguration.getTimeout()).thenReturn(5000L);130 131 Message message = new DefaultMessage("<root>"132 + "<element attributeA='attribute-value' attributeB='attribute-value' >"133 + "<sub-elementA attribute=''>text-value</sub-elementA>"134 + "<sub-elementB attribute=''>text-value</sub-elementB>"135 + "<sub-elementC attribute=''>text-value</sub-elementC>"136 + "</element>" 137 + "</root>");138 139 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);140 when(endpoint.getActor()).thenReturn(null);141 142 HashMap<String, Object> validateMessageElements = new HashMap<>();143 validateMessageElements.put("//root/element/sub-elementA/@attribute", "");144 validateMessageElements.put("//root/element/sub-elementB/@attribute", "");145 validateMessageElements.put("//root/element/sub-elementC/@attribute", "");146 147 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();148 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();149 receiveMessageBean.setMessageBuilder(controlMessageBuilder);150 validationContext.setXpathExpressions(validateMessageElements);151 152 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();153 validationContexts.add(validationContext);154 receiveMessageBean.setValidationContexts(validationContexts);155 156 receiveMessageBean.execute(context);157 }158 159 @Test(expectedExceptions = {ValidationException.class})160 @SuppressWarnings({ "unchecked", "rawtypes" })161 public void testValidateNullElements() {162 reset(endpoint, consumer, endpointConfiguration);163 when(endpoint.createConsumer()).thenReturn(consumer);164 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);165 when(endpointConfiguration.getTimeout()).thenReturn(5000L);166 167 Message message = new DefaultMessage("<root>"168 + "<element attributeA='attribute-value' attributeB='attribute-value' >"169 + "<sub-elementA attribute='A'></sub-elementA>"170 + "<sub-elementB attribute='B'></sub-elementB>"171 + "<sub-elementC attribute='C'>text-value</sub-elementC>"172 + "</element>" 173 + "</root>");174 175 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);176 when(endpoint.getActor()).thenReturn(null);177 HashMap<String, Object> validateMessageElements = new HashMap<>();178 validateMessageElements.put("//root/element/sub-elementA", "null");179 validateMessageElements.put("//sub-elementB", "null");180 181 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();182 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();183 receiveMessageBean.setMessageBuilder(controlMessageBuilder);184 validationContext.setXpathExpressions(validateMessageElements);185 186 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();187 validationContexts.add(validationContext);188 receiveMessageBean.setValidationContexts(validationContexts);189 190 receiveMessageBean.execute(context);191 }192 193 @Test194 @SuppressWarnings({ "unchecked", "rawtypes" })195 public void testValidateMessageElementAttributes() {196 reset(endpoint, consumer, endpointConfiguration);197 when(endpoint.createConsumer()).thenReturn(consumer);198 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);199 when(endpointConfiguration.getTimeout()).thenReturn(5000L);200 201 Message message = new DefaultMessage("<root>"202 + "<element attributeA='attribute-value' attributeB='attribute-value' >"203 + "<sub-elementA attribute='A'>text-value</sub-elementA>"204 + "<sub-elementB attribute='B'>text-value</sub-elementB>"205 + "<sub-elementC attribute='C'>text-value</sub-elementC>"206 + "</element>" 207 + "</root>");208 209 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);210 when(endpoint.getActor()).thenReturn(null);211 HashMap<String, Object> validateMessageElements = new HashMap<>();212 validateMessageElements.put("//root/element/sub-elementA/@attribute", "A");213 validateMessageElements.put("//sub-elementB/@attribute", "B");214 215 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();216 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();217 receiveMessageBean.setMessageBuilder(controlMessageBuilder);218 validationContext.setXpathExpressions(validateMessageElements);219 220 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();221 validationContexts.add(validationContext);222 receiveMessageBean.setValidationContexts(validationContexts);223 224 receiveMessageBean.execute(context);225 }226 227 @Test(expectedExceptions = {CitrusRuntimeException.class})228 @SuppressWarnings({ "unchecked", "rawtypes" })229 public void testValidateMessageElementsWrongExpectedElement() {230 reset(endpoint, consumer, endpointConfiguration);231 when(endpoint.createConsumer()).thenReturn(consumer);232 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);233 when(endpointConfiguration.getTimeout()).thenReturn(5000L);234 235 Message message = new DefaultMessage("<root>"236 + "<element attributeA='attribute-value' attributeB='attribute-value' >"237 + "<sub-elementA attribute='A'>text-value</sub-elementA>"238 + "<sub-elementB attribute='B'>text-value</sub-elementB>"239 + "<sub-elementC attribute='C'>text-value</sub-elementC>"240 + "</element>" 241 + "</root>");242 243 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);244 when(endpoint.getActor()).thenReturn(null);245 HashMap<String, Object> validateMessageElements = new HashMap<>();246 validateMessageElements.put("//root/element/sub-element-wrong", "text-value");247 validateMessageElements.put("//sub-element-wrong", "text-value");248 249 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();250 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();251 receiveMessageBean.setMessageBuilder(controlMessageBuilder);252 validationContext.setXpathExpressions(validateMessageElements);253 254 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();255 validationContexts.add(validationContext);256 receiveMessageBean.setValidationContexts(validationContexts);257 258 receiveMessageBean.execute(context);259 }260 261 @Test(expectedExceptions = {ValidationException.class})262 @SuppressWarnings({ "unchecked", "rawtypes" })263 public void testValidateMessageElementsWrongExpectedValue() {264 reset(endpoint, consumer, endpointConfiguration);265 when(endpoint.createConsumer()).thenReturn(consumer);266 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);267 when(endpointConfiguration.getTimeout()).thenReturn(5000L);268 269 Message message = new DefaultMessage("<root>"270 + "<element attributeA='attribute-value' attributeB='attribute-value' >"271 + "<sub-elementA attribute='A'>text-value</sub-elementA>"272 + "<sub-elementB attribute='B'>text-value</sub-elementB>"273 + "<sub-elementC attribute='C'>text-value</sub-elementC>"274 + "</element>" 275 + "</root>");276 277 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);278 when(endpoint.getActor()).thenReturn(null);279 HashMap<String, Object> validateMessageElements = new HashMap<>();280 validateMessageElements.put("//root/element/sub-elementA", "text-value-wrong");281 validateMessageElements.put("//sub-elementB", "text-value-wrong");282 283 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();284 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();285 receiveMessageBean.setMessageBuilder(controlMessageBuilder);286 validationContext.setXpathExpressions(validateMessageElements);287 288 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();289 validationContexts.add(validationContext);290 receiveMessageBean.setValidationContexts(validationContexts);291 292 receiveMessageBean.execute(context);293 }294 295 @Test(expectedExceptions = {ValidationException.class})296 @SuppressWarnings({ "unchecked", "rawtypes" })297 public void testValidateMessageElementAttributesWrongExpectedValue() {298 reset(endpoint, consumer, endpointConfiguration);299 when(endpoint.createConsumer()).thenReturn(consumer);300 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);301 when(endpointConfiguration.getTimeout()).thenReturn(5000L);302 303 Message message = new DefaultMessage("<root>"304 + "<element attributeA='attribute-value' attributeB='attribute-value' >"305 + "<sub-elementA attribute='A'>text-value</sub-elementA>"306 + "<sub-elementB attribute='B'>text-value</sub-elementB>"307 + "<sub-elementC attribute='C'>text-value</sub-elementC>"308 + "</element>" 309 + "</root>");310 311 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);312 when(endpoint.getActor()).thenReturn(null);313 HashMap<String, Object> validateMessageElements = new HashMap<>();314 validateMessageElements.put("//root/element/sub-elementA/@attribute", "wrong-value");315 validateMessageElements.put("//sub-elementB/@attribute", "wrong-value");316 317 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();318 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();319 receiveMessageBean.setMessageBuilder(controlMessageBuilder);320 validationContext.setXpathExpressions(validateMessageElements);321 322 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();323 validationContexts.add(validationContext);324 receiveMessageBean.setValidationContexts(validationContexts);325 326 receiveMessageBean.execute(context);327 }328 329 @Test(expectedExceptions = {CitrusRuntimeException.class})330 @SuppressWarnings({ "unchecked", "rawtypes" })331 public void testValidateMessageElementAttributesWrongExpectedAttribute() {332 reset(endpoint, consumer, endpointConfiguration);333 when(endpoint.createConsumer()).thenReturn(consumer);334 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);335 when(endpointConfiguration.getTimeout()).thenReturn(5000L);336 337 Message message = new DefaultMessage("<root>"338 + "<element attributeA='attribute-value' attributeB='attribute-value' >"339 + "<sub-elementA attribute='A'>text-value</sub-elementA>"340 + "<sub-elementB attribute='B'>text-value</sub-elementB>"341 + "<sub-elementC attribute='C'>text-value</sub-elementC>"342 + "</element>" 343 + "</root>");344 345 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);346 when(endpoint.getActor()).thenReturn(null);347 HashMap<String, Object> validateMessageElements = new HashMap<>();348 validateMessageElements.put("//root/element/sub-elementA/@attribute-wrong", "A");349 validateMessageElements.put("//sub-elementB/@attribute-wrong", "B");350 351 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();352 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();353 receiveMessageBean.setMessageBuilder(controlMessageBuilder);354 validationContext.setXpathExpressions(validateMessageElements);355 356 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();357 validationContexts.add(validationContext);358 receiveMessageBean.setValidationContexts(validationContexts);359 360 receiveMessageBean.execute(context);361 }362 363 @Test364 @SuppressWarnings({ "unchecked", "rawtypes" })365 public void testSetMessageElements() {366 reset(endpoint, consumer, endpointConfiguration);367 when(endpoint.createConsumer()).thenReturn(consumer);368 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);369 when(endpointConfiguration.getTimeout()).thenReturn(5000L);370 371 Message message = new DefaultMessage("<root>"372 + "<element attributeA='attribute-value' attributeB='attribute-value' >"373 + "<sub-elementA attribute='A'>text-value</sub-elementA>"374 + "<sub-elementB attribute='B'>text-value</sub-elementB>"375 + "<sub-elementC attribute='C'>text-value</sub-elementC>"376 + "</element>" 377 + "</root>");378 379 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);380 when(endpoint.getActor()).thenReturn(null);381 382 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();383 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();384 receiveMessageBean.setMessageBuilder(controlMessageBuilder);385 386 controlMessageBuilder.setPayloadData("<root>"387 + "<element attributeA='attribute-value' attributeB='attribute-value' >"388 + "<sub-elementA attribute='A'>to be overwritten</sub-elementA>"389 + "<sub-elementB attribute='B'>to be overwritten</sub-elementB>"390 + "<sub-elementC attribute='C'>text-value</sub-elementC>"391 + "</element>" 392 + "</root>");393 394 HashMap<String, String> messageElements = new HashMap<String, String>();395 messageElements.put("//root/element/sub-elementA", "text-value");396 messageElements.put("//sub-elementB", "text-value");397 398 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);399 controlMessageBuilder.add(interceptor);400 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();401 validationContexts.add(validationContext);402 receiveMessageBean.setValidationContexts(validationContexts);403 404 receiveMessageBean.execute(context);405 }406 407 @Test408 @SuppressWarnings({ "unchecked", "rawtypes" })409 public void testSetMessageElementsUsingEmptyString() {410 reset(endpoint, consumer, endpointConfiguration);411 when(endpoint.createConsumer()).thenReturn(consumer);412 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);413 when(endpointConfiguration.getTimeout()).thenReturn(5000L);414 415 Message message = new DefaultMessage("<root>"416 + "<element attributeA='attribute-value' attributeB='attribute-value' >"417 + "<sub-elementA attribute='A'></sub-elementA>"418 + "<sub-elementB attribute='B'></sub-elementB>"419 + "<sub-elementC attribute='C'>text-value</sub-elementC>"420 + "</element>" 421 + "</root>");422 423 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);424 when(endpoint.getActor()).thenReturn(null);425 426 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();427 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();428 receiveMessageBean.setMessageBuilder(controlMessageBuilder);429 430 controlMessageBuilder.setPayloadData("<root>"431 + "<element attributeA='attribute-value' attributeB='attribute-value' >"432 + "<sub-elementA attribute='A'>to be overwritten</sub-elementA>"433 + "<sub-elementB attribute='B'>to be overwritten</sub-elementB>"434 + "<sub-elementC attribute='C'>text-value</sub-elementC>"435 + "</element>" 436 + "</root>");437 438 HashMap<String, String> messageElements = new HashMap<String, String>();439 messageElements.put("//root/element/sub-elementA", "");440 messageElements.put("//sub-elementB", "");441 442 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);443 controlMessageBuilder.add(interceptor);444 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();445 validationContexts.add(validationContext);446 receiveMessageBean.setValidationContexts(validationContexts);447 448 receiveMessageBean.execute(context);449 }450 451 @Test452 @SuppressWarnings({ "unchecked", "rawtypes" })453 public void testSetMessageElementsAndValidate() {454 reset(endpoint, consumer, endpointConfiguration);455 when(endpoint.createConsumer()).thenReturn(consumer);456 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);457 when(endpointConfiguration.getTimeout()).thenReturn(5000L);458 459 Message message = new DefaultMessage("<root>"460 + "<element attributeA='attribute-value' attributeB='attribute-value' >"461 + "<sub-elementA attribute='A'>text-value</sub-elementA>"462 + "<sub-elementB attribute='B'>text-value</sub-elementB>"463 + "<sub-elementC attribute='C'>text-value</sub-elementC>"464 + "</element>" 465 + "</root>");466 467 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);468 when(endpoint.getActor()).thenReturn(null);469 470 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();471 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();472 receiveMessageBean.setMessageBuilder(controlMessageBuilder);473 474 controlMessageBuilder.setPayloadData("<root>"475 + "<element attributeA='attribute-value' attributeB='attribute-value' >"476 + "<sub-elementA attribute='A'>to be overwritten</sub-elementA>"477 + "<sub-elementB attribute='B'>to be overwritten</sub-elementB>"478 + "<sub-elementC attribute='C'>text-value</sub-elementC>"479 + "</element>" 480 + "</root>");481 482 HashMap<String, String> messageElements = new HashMap<String, String>();483 messageElements.put("//root/element/sub-elementA", "text-value");484 messageElements.put("//sub-elementB", "text-value");485 486 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);487 controlMessageBuilder.add(interceptor);488 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();489 validationContexts.add(validationContext);490 receiveMessageBean.setValidationContexts(validationContexts);491 492 HashMap<String, Object> validateElements = new HashMap<>();493 validateElements.put("//root/element/sub-elementA", "text-value");494 validateElements.put("//sub-elementB", "text-value");495 496 validationContext.setXpathExpressions(validateElements);497 498 receiveMessageBean.execute(context);499 }500 501 @Test502 @SuppressWarnings({ "unchecked", "rawtypes" })503 public void testSetMessageElementAttributes() {504 reset(endpoint, consumer, endpointConfiguration);505 when(endpoint.createConsumer()).thenReturn(consumer);506 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);507 when(endpointConfiguration.getTimeout()).thenReturn(5000L);508 509 Message message = new DefaultMessage("<root>"510 + "<element attributeA='attribute-value' attributeB='attribute-value' >"511 + "<sub-elementA attribute='A'>text-value</sub-elementA>"512 + "<sub-elementB attribute='B'>text-value</sub-elementB>"513 + "<sub-elementC attribute='C'>text-value</sub-elementC>"514 + "</element>" 515 + "</root>");516 517 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);518 when(endpoint.getActor()).thenReturn(null);519 520 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();521 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();522 receiveMessageBean.setMessageBuilder(controlMessageBuilder);523 524 controlMessageBuilder.setPayloadData("<root>"525 + "<element attributeA='attribute-value' attributeB='attribute-value' >"526 + "<sub-elementA attribute='to be overwritten'>text-value</sub-elementA>"527 + "<sub-elementB attribute='to be overwritten'>text-value</sub-elementB>"528 + "<sub-elementC attribute='C'>text-value</sub-elementC>"529 + "</element>" 530 + "</root>");531 532 HashMap<String, String> messageElements = new HashMap<String, String>();533 messageElements.put("//root/element/sub-elementA/@attribute", "A");534 messageElements.put("//sub-elementB/@attribute", "B");535 536 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);537 controlMessageBuilder.add(interceptor);538 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();539 validationContexts.add(validationContext);540 receiveMessageBean.setValidationContexts(validationContexts);541 542 receiveMessageBean.execute(context);543 }544 545 @Test(expectedExceptions = {CitrusRuntimeException.class})546 @SuppressWarnings({ "unchecked", "rawtypes" })547 public void testSetMessageElementsError() {548 reset(endpoint, consumer, endpointConfiguration);549 when(endpoint.createConsumer()).thenReturn(consumer);550 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);551 when(endpointConfiguration.getTimeout()).thenReturn(5000L);552 553 Message message = new DefaultMessage("<root>"554 + "<element attributeA='attribute-value' attributeB='attribute-value' >"555 + "<sub-elementA attribute='A'>text-value</sub-elementA>"556 + "<sub-elementB attribute='B'>text-value</sub-elementB>"557 + "<sub-elementC attribute='C'>text-value</sub-elementC>"558 + "</element>" 559 + "</root>");560 561 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);562 when(endpoint.getActor()).thenReturn(null);563 564 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();565 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();566 receiveMessageBean.setMessageBuilder(controlMessageBuilder);567 568 controlMessageBuilder.setPayloadData("<root>"569 + "<element attributeA='attribute-value' attributeB='attribute-value' >"570 + "<sub-elementA attribute='A'>to be overwritten</sub-elementA>"571 + "<sub-elementB attribute='B'>to be overwritten</sub-elementB>"572 + "<sub-elementC attribute='C'>text-value</sub-elementC>"573 + "</element>" 574 + "</root>");575 576 HashMap<String, String> messageElements = new HashMap<String, String>();577 messageElements.put("//root/element/sub-element-wrong", "text-value");578 messageElements.put("//sub-element-wrong", "text-value");579 580 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);581 controlMessageBuilder.add(interceptor);582 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();583 validationContexts.add(validationContext);584 receiveMessageBean.setValidationContexts(validationContexts);585 586 receiveMessageBean.execute(context);587 }588 589 @Test(expectedExceptions = {CitrusRuntimeException.class})590 @SuppressWarnings({ "unchecked", "rawtypes" })591 public void testSetMessageElementAttributesError() {592 reset(endpoint, consumer, endpointConfiguration);593 when(endpoint.createConsumer()).thenReturn(consumer);594 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);595 when(endpointConfiguration.getTimeout()).thenReturn(5000L);596 597 Message message = new DefaultMessage("<root>"598 + "<element attributeA='attribute-value' attributeB='attribute-value' >"599 + "<sub-elementA attribute='A'>text-value</sub-elementA>"600 + "<sub-elementB attribute='B'>text-value</sub-elementB>"601 + "<sub-elementC attribute='C'>text-value</sub-elementC>"602 + "</element>" 603 + "</root>");604 605 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);606 when(endpoint.getActor()).thenReturn(null);607 608 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();609 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();610 receiveMessageBean.setMessageBuilder(controlMessageBuilder);611 612 controlMessageBuilder.setPayloadData("<root>"613 + "<element attributeA='attribute-value' attributeB='attribute-value' >"614 + "<sub-elementA attribute='to be overwritten'>text-value</sub-elementA>"615 + "<sub-elementB attribute='to be overwritten'>text-value</sub-elementB>"616 + "<sub-elementC attribute='C'>text-value</sub-elementC>"617 + "</element>" 618 + "</root>");619 620 HashMap<String, String> messageElements = new HashMap<String, String>();621 messageElements.put("//root/element/sub-elementA/@attribute-wrong", "A");622 messageElements.put("//sub-elementB/@attribute-wrong", "B");623 624 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);625 controlMessageBuilder.add(interceptor);626 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();627 validationContexts.add(validationContext);628 receiveMessageBean.setValidationContexts(validationContexts);629 630 receiveMessageBean.execute(context);631 }632 633 @Test(expectedExceptions = {CitrusRuntimeException.class})634 @SuppressWarnings({ "unchecked", "rawtypes" })635 public void testSetMessageElementAttributesErrorWrongElement() {636 reset(endpoint, consumer, endpointConfiguration);637 when(endpoint.createConsumer()).thenReturn(consumer);638 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);639 when(endpointConfiguration.getTimeout()).thenReturn(5000L);640 641 Message message = new DefaultMessage("<root>"642 + "<element attributeA='attribute-value' attributeB='attribute-value' >"643 + "<sub-elementA attribute='A'>text-value</sub-elementA>"644 + "<sub-elementB attribute='B'>text-value</sub-elementB>"645 + "<sub-elementC attribute='C'>text-value</sub-elementC>"646 + "</element>" 647 + "</root>");648 649 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);650 when(endpoint.getActor()).thenReturn(null);651 652 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();653 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();654 receiveMessageBean.setMessageBuilder(controlMessageBuilder);655 656 controlMessageBuilder.setPayloadData("<root>"657 + "<element attributeA='attribute-value' attributeB='attribute-value' >"658 + "<sub-elementA attribute='to be overwritten'>text-value</sub-elementA>"659 + "<sub-elementB attribute='to be overwritten'>text-value</sub-elementB>"660 + "<sub-elementC attribute='C'>text-value</sub-elementC>"661 + "</element>" 662 + "</root>");663 664 HashMap<String, String> messageElements = new HashMap<String, String>();665 messageElements.put("//root/element/sub-elementA-wrong/@attribute", "A");666 messageElements.put("//sub-elementB-wrong/@attribute", "B");667 668 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);669 controlMessageBuilder.add(interceptor);670 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();671 validationContexts.add(validationContext);672 receiveMessageBean.setValidationContexts(validationContexts);673 674 receiveMessageBean.execute(context);675 }676 @Test677 @SuppressWarnings({ "unchecked", "rawtypes" })678 public void testExtractMessageElements() {679 reset(endpoint, consumer, endpointConfiguration);680 when(endpoint.createConsumer()).thenReturn(consumer);681 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);682 when(endpointConfiguration.getTimeout()).thenReturn(5000L);683 684 Message message = new DefaultMessage("<root>"685 + "<element attributeA='attribute-value' attributeB='attribute-value' >"686 + "<sub-elementA attribute='A'>text-value</sub-elementA>"687 + "<sub-elementB attribute='B'>text-value</sub-elementB>"688 + "<sub-elementC attribute='C'>text-value</sub-elementC>"689 + "</element>" 690 + "</root>");691 692 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);693 when(endpoint.getActor()).thenReturn(null);694 695 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();696 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();697 receiveMessageBean.setMessageBuilder(controlMessageBuilder);698 699 controlMessageBuilder.setPayloadData("<root>"700 + "<element attributeA='attribute-value' attributeB='attribute-value' >"701 + "<sub-elementA attribute='A'>text-value</sub-elementA>"702 + "<sub-elementB attribute='B'>text-value</sub-elementB>"703 + "<sub-elementC attribute='C'>text-value</sub-elementC>"704 + "</element>" 705 + "</root>");706 707 HashMap<String, String> extractMessageElements = new HashMap<String, String>();708 extractMessageElements.put("//root/element/sub-elementA", "${valueA}");709 extractMessageElements.put("//root/element/sub-elementB", "${valueB}");710 711 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();712 variableExtractor.setXpathExpressions(extractMessageElements);713 714 receiveMessageBean.addVariableExtractors(variableExtractor);715 716 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();717 validationContexts.add(validationContext);718 receiveMessageBean.setValidationContexts(validationContexts);719 720 receiveMessageBean.execute(context);721 722 Assert.assertTrue(context.getVariables().containsKey("valueA"));723 Assert.assertEquals(context.getVariables().get("valueA"), "text-value");724 Assert.assertTrue(context.getVariables().containsKey("valueB"));725 Assert.assertEquals(context.getVariables().get("valueB"), "text-value");726 }727 728 @Test729 @SuppressWarnings({ "unchecked", "rawtypes" })730 public void testExtractMessageAttributes() {731 reset(endpoint, consumer, endpointConfiguration);732 when(endpoint.createConsumer()).thenReturn(consumer);733 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);734 when(endpointConfiguration.getTimeout()).thenReturn(5000L);735 736 Message message = new DefaultMessage("<root>"737 + "<element attributeA='attribute-value' attributeB='attribute-value' >"738 + "<sub-elementA attribute='A'>text-value</sub-elementA>"739 + "<sub-elementB attribute='B'>text-value</sub-elementB>"740 + "<sub-elementC attribute='C'>text-value</sub-elementC>"741 + "</element>" 742 + "</root>");743 744 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);745 when(endpoint.getActor()).thenReturn(null);746 747 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();748 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();749 receiveMessageBean.setMessageBuilder(controlMessageBuilder);750 751 controlMessageBuilder.setPayloadData("<root>"752 + "<element attributeA='attribute-value' attributeB='attribute-value' >"753 + "<sub-elementA attribute='A'>text-value</sub-elementA>"754 + "<sub-elementB attribute='B'>text-value</sub-elementB>"755 + "<sub-elementC attribute='C'>text-value</sub-elementC>"756 + "</element>" 757 + "</root>");758 759 HashMap<String, String> extractMessageElements = new HashMap<String, String>();760 extractMessageElements.put("//root/element/sub-elementA/@attribute", "${valueA}");761 extractMessageElements.put("//root/element/sub-elementB/@attribute", "${valueB}");762 763 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();764 variableExtractor.setXpathExpressions(extractMessageElements);765 766 receiveMessageBean.addVariableExtractors(variableExtractor);767 768 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();769 validationContexts.add(validationContext);770 receiveMessageBean.setValidationContexts(validationContexts);771 772 receiveMessageBean.execute(context);773 774 Assert.assertTrue(context.getVariables().containsKey("valueA"));775 Assert.assertEquals(context.getVariables().get("valueA"), "A");776 Assert.assertTrue(context.getVariables().containsKey("valueB"));777 Assert.assertEquals(context.getVariables().get("valueB"), "B");778 }779 780 @Test(expectedExceptions = {CitrusRuntimeException.class})781 @SuppressWarnings({ "unchecked", "rawtypes" })782 public void testExtractMessageElementsForWrongElement() {783 reset(endpoint, consumer, endpointConfiguration);784 when(endpoint.createConsumer()).thenReturn(consumer);785 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);786 when(endpointConfiguration.getTimeout()).thenReturn(5000L);787 788 Message message = new DefaultMessage("<root>"789 + "<element attributeA='attribute-value' attributeB='attribute-value' >"790 + "<sub-elementA attribute='A'>text-value</sub-elementA>"791 + "<sub-elementB attribute='B'>text-value</sub-elementB>"792 + "<sub-elementC attribute='C'>text-value</sub-elementC>"793 + "</element>" 794 + "</root>");795 796 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);797 when(endpoint.getActor()).thenReturn(null);798 799 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();800 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();801 receiveMessageBean.setMessageBuilder(controlMessageBuilder);802 803 controlMessageBuilder.setPayloadData("<root>"804 + "<element attributeA='attribute-value' attributeB='attribute-value' >"805 + "<sub-elementA attribute='A'>text-value</sub-elementA>"806 + "<sub-elementB attribute='B'>text-value</sub-elementB>"807 + "<sub-elementC attribute='C'>text-value</sub-elementC>"808 + "</element>" 809 + "</root>");810 811 HashMap<String, String> extractMessageElements = new HashMap<String, String>();812 extractMessageElements.put("//root/element/sub-element-wrong", "${valueA}");813 extractMessageElements.put("//element/sub-element-wrong", "${valueB}");814 815 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();816 variableExtractor.setXpathExpressions(extractMessageElements);817 818 receiveMessageBean.addVariableExtractors(variableExtractor);819 820 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();821 validationContexts.add(validationContext);822 receiveMessageBean.setValidationContexts(validationContexts);823 824 receiveMessageBean.execute(context);825 826 Assert.assertFalse(context.getVariables().containsKey("valueA"));827 Assert.assertFalse(context.getVariables().containsKey("valueB"));828 }829 830 @Test(expectedExceptions = {CitrusRuntimeException.class})831 @SuppressWarnings({ "unchecked", "rawtypes" })832 public void testExtractMessageElementsForWrongAtribute() {833 reset(endpoint, consumer, endpointConfiguration);834 when(endpoint.createConsumer()).thenReturn(consumer);835 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);836 when(endpointConfiguration.getTimeout()).thenReturn(5000L);837 838 Message message = new DefaultMessage("<root>"839 + "<element attributeA='attribute-value' attributeB='attribute-value' >"840 + "<sub-elementA attribute='A'>text-value</sub-elementA>"841 + "<sub-elementB attribute='B'>text-value</sub-elementB>"842 + "<sub-elementC attribute='C'>text-value</sub-elementC>"843 + "</element>" 844 + "</root>");845 846 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);847 when(endpoint.getActor()).thenReturn(null);848 849 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();850 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();851 receiveMessageBean.setMessageBuilder(controlMessageBuilder);852 853 controlMessageBuilder.setPayloadData("<root>"854 + "<element attributeA='attribute-value' attributeB='attribute-value' >"855 + "<sub-elementA attribute='A'>text-value</sub-elementA>"856 + "<sub-elementB attribute='B'>text-value</sub-elementB>"857 + "<sub-elementC attribute='C'>text-value</sub-elementC>"858 + "</element>" 859 + "</root>");860 861 HashMap<String, String> extractMessageElements = new HashMap<String, String>();862 extractMessageElements.put("//root/element/sub-elementA/@attribute-wrong", "${attributeA}");863 864 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();865 variableExtractor.setXpathExpressions(extractMessageElements);866 867 receiveMessageBean.addVariableExtractors(variableExtractor);868 869 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();870 validationContexts.add(validationContext);871 receiveMessageBean.setValidationContexts(validationContexts);872 873 receiveMessageBean.execute(context);874 875 Assert.assertFalse(context.getVariables().containsKey("attributeA"));876 }877}...

Full Screen

Full Screen

Source:MessageElementsLegacyTest.java Github

copy

Full Screen

...76 77 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();78 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();79 receiveMessageBean.setMessageBuilder(controlMessageBuilder);80 validationContext.setXpathExpressions(validateMessageElements);81 82 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();83 validationContexts.add(validationContext);84 receiveMessageBean.setValidationContexts(validationContexts);85 receiveMessageBean.execute(context);86 }87 88 @Test89 @SuppressWarnings({ "unchecked", "rawtypes" })90 public void testValidateEmptyMessageElements() {91 reset(endpoint, consumer, endpointConfiguration);92 when(endpoint.createConsumer()).thenReturn(consumer);93 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);94 when(endpointConfiguration.getTimeout()).thenReturn(5000L);95 96 Message message = new DefaultMessage("<root>"97 + "<element attributeA='attribute-value' attributeB='attribute-value' >"98 + "<sub-elementA attribute='A'></sub-elementA>"99 + "<sub-elementB attribute='B'></sub-elementB>"100 + "<sub-elementC attribute='C'>text-value</sub-elementC>"101 + "</element>"102 + "</root>");103 104 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);105 when(endpoint.getActor()).thenReturn(null);106 107 HashMap<String, Object> validateMessageElements = new HashMap<>();108 validateMessageElements.put("root.element.sub-elementA", "");109 validateMessageElements.put("sub-elementB", "");110 111 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();112 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();113 receiveMessageBean.setMessageBuilder(controlMessageBuilder);114 validationContext.setXpathExpressions(validateMessageElements);115 116 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();117 validationContexts.add(validationContext);118 receiveMessageBean.setValidationContexts(validationContexts);119 receiveMessageBean.execute(context);120 }121 122 @Test123 @SuppressWarnings({ "unchecked", "rawtypes" })124 public void testValidateMessageElementAttributes() {125 reset(endpoint, consumer, endpointConfiguration);126 when(endpoint.createConsumer()).thenReturn(consumer);127 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);128 when(endpointConfiguration.getTimeout()).thenReturn(5000L);129 130 Message message = new DefaultMessage("<root>"131 + "<element attributeA='attribute-value' attributeB='attribute-value' >"132 + "<sub-elementA attribute='A'>text-value</sub-elementA>"133 + "<sub-elementB attribute='B'>text-value</sub-elementB>"134 + "<sub-elementC attribute='C'>text-value</sub-elementC>"135 + "</element>"136 + "</root>");137 138 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);139 when(endpoint.getActor()).thenReturn(null);140 HashMap<String, Object> validateMessageElements = new HashMap<>();141 validateMessageElements.put("root.element.sub-elementA.attribute", "A");142 validateMessageElements.put("sub-elementB.attribute", "B");143 144 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();145 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();146 receiveMessageBean.setMessageBuilder(controlMessageBuilder);147 validationContext.setXpathExpressions(validateMessageElements);148 149 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();150 validationContexts.add(validationContext);151 receiveMessageBean.setValidationContexts(validationContexts);152 receiveMessageBean.execute(context);153 }154 155 @Test(expectedExceptions = {CitrusRuntimeException.class})156 @SuppressWarnings({ "unchecked", "rawtypes" })157 public void testValidateMessageElementsWrongExpectedElement() {158 reset(endpoint, consumer, endpointConfiguration);159 when(endpoint.createConsumer()).thenReturn(consumer);160 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);161 when(endpointConfiguration.getTimeout()).thenReturn(5000L);162 163 Message message = new DefaultMessage("<root>"164 + "<element attributeA='attribute-value' attributeB='attribute-value' >"165 + "<sub-elementA attribute='A'>text-value</sub-elementA>"166 + "<sub-elementB attribute='B'>text-value</sub-elementB>"167 + "<sub-elementC attribute='C'>text-value</sub-elementC>"168 + "</element>"169 + "</root>");170 171 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);172 when(endpoint.getActor()).thenReturn(null);173 HashMap<String, Object> validateMessageElements = new HashMap<>();174 validateMessageElements.put("root.element.sub-element-wrong", "text-value");175 validateMessageElements.put("sub-element-wrong", "text-value");176 177 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();178 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();179 receiveMessageBean.setMessageBuilder(controlMessageBuilder);180 validationContext.setXpathExpressions(validateMessageElements);181 182 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();183 validationContexts.add(validationContext);184 receiveMessageBean.setValidationContexts(validationContexts);185 186 receiveMessageBean.execute(context);187 }188 189 @Test(expectedExceptions = {ValidationException.class})190 @SuppressWarnings({ "unchecked", "rawtypes" })191 public void testValidateMessageElementsWrongExpectedValue() {192 reset(endpoint, consumer, endpointConfiguration);193 when(endpoint.createConsumer()).thenReturn(consumer);194 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);195 when(endpointConfiguration.getTimeout()).thenReturn(5000L);196 197 Message message = new DefaultMessage("<root>"198 + "<element attributeA='attribute-value' attributeB='attribute-value' >"199 + "<sub-elementA attribute='A'>text-value</sub-elementA>"200 + "<sub-elementB attribute='B'>text-value</sub-elementB>"201 + "<sub-elementC attribute='C'>text-value</sub-elementC>"202 + "</element>"203 + "</root>");204 205 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);206 when(endpoint.getActor()).thenReturn(null);207 HashMap<String, Object> validateMessageElements = new HashMap<>();208 validateMessageElements.put("root.element.sub-elementA", "text-value-wrong");209 validateMessageElements.put("sub-elementB", "text-value-wrong");210 211 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();212 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();213 receiveMessageBean.setMessageBuilder(controlMessageBuilder);214 validationContext.setXpathExpressions(validateMessageElements);215 216 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();217 validationContexts.add(validationContext);218 receiveMessageBean.setValidationContexts(validationContexts);219 receiveMessageBean.execute(context);220 }221 222 @Test(expectedExceptions = {ValidationException.class})223 @SuppressWarnings({ "unchecked", "rawtypes" })224 public void testValidateMessageElementAttributesWrongExpectedValue() {225 reset(endpoint, consumer, endpointConfiguration);226 when(endpoint.createConsumer()).thenReturn(consumer);227 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);228 when(endpointConfiguration.getTimeout()).thenReturn(5000L);229 230 Message message = new DefaultMessage("<root>"231 + "<element attributeA='attribute-value' attributeB='attribute-value' >"232 + "<sub-elementA attribute='A'>text-value</sub-elementA>"233 + "<sub-elementB attribute='B'>text-value</sub-elementB>"234 + "<sub-elementC attribute='C'>text-value</sub-elementC>"235 + "</element>"236 + "</root>");237 238 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);239 when(endpoint.getActor()).thenReturn(null);240 HashMap<String, Object> validateMessageElements = new HashMap<>();241 validateMessageElements.put("root.element.sub-elementA.attribute", "wrong-value");242 validateMessageElements.put("sub-elementB.attribute", "wrong-value");243 244 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();245 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();246 receiveMessageBean.setMessageBuilder(controlMessageBuilder);247 validationContext.setXpathExpressions(validateMessageElements);248 249 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();250 validationContexts.add(validationContext);251 receiveMessageBean.setValidationContexts(validationContexts);252 receiveMessageBean.execute(context);253 }254 255 @Test(expectedExceptions = {CitrusRuntimeException.class})256 @SuppressWarnings({ "unchecked", "rawtypes" })257 public void testValidateMessageElementAttributesWrongExpectedAttribute() {258 reset(endpoint, consumer, endpointConfiguration);259 when(endpoint.createConsumer()).thenReturn(consumer);260 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);261 when(endpointConfiguration.getTimeout()).thenReturn(5000L);262 263 Message message = new DefaultMessage("<root>"264 + "<element attributeA='attribute-value' attributeB='attribute-value' >"265 + "<sub-elementA attribute='A'>text-value</sub-elementA>"266 + "<sub-elementB attribute='B'>text-value</sub-elementB>"267 + "<sub-elementC attribute='C'>text-value</sub-elementC>"268 + "</element>"269 + "</root>");270 271 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);272 when(endpoint.getActor()).thenReturn(null);273 HashMap<String, Object> validateMessageElements = new HashMap<>();274 validateMessageElements.put("root.element.sub-elementA.attribute-wrong", "A");275 validateMessageElements.put("sub-elementB.attribute-wrong", "B");276 277 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();278 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();279 receiveMessageBean.setMessageBuilder(controlMessageBuilder);280 validationContext.setXpathExpressions(validateMessageElements);281 282 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();283 validationContexts.add(validationContext);284 receiveMessageBean.setValidationContexts(validationContexts);285 receiveMessageBean.execute(context);286 }287 288 @Test289 @SuppressWarnings({ "unchecked", "rawtypes" })290 public void testSetMessageElements() {291 reset(endpoint, consumer, endpointConfiguration);292 when(endpoint.createConsumer()).thenReturn(consumer);293 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);294 when(endpointConfiguration.getTimeout()).thenReturn(5000L);295 296 Message message = new DefaultMessage("<root>"297 + "<element attributeA='attribute-value' attributeB='attribute-value' >"298 + "<sub-elementA attribute='A'>text-value</sub-elementA>"299 + "<sub-elementB attribute='B'>text-value</sub-elementB>"300 + "<sub-elementC attribute='C'>text-value</sub-elementC>"301 + "</element>"302 + "</root>");303 304 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);305 when(endpoint.getActor()).thenReturn(null);306 307 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();308 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();309 receiveMessageBean.setMessageBuilder(controlMessageBuilder);310 controlMessageBuilder.setPayloadData("<root>"311 + "<element attributeA='attribute-value' attributeB='attribute-value' >"312 + "<sub-elementA attribute='A'>to be overwritten</sub-elementA>"313 + "<sub-elementB attribute='B'>to be overwritten</sub-elementB>"314 + "<sub-elementC attribute='C'>text-value</sub-elementC>"315 + "</element>" 316 + "</root>");317 318 HashMap<String, String> messageElements = new HashMap<String, String>();319 messageElements.put("root.element.sub-elementA", "text-value");320 messageElements.put("sub-elementB", "text-value");321 322 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);323 controlMessageBuilder.add(interceptor);324 325 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();326 validationContexts.add(validationContext);327 receiveMessageBean.setValidationContexts(validationContexts);328 receiveMessageBean.execute(context);329 }330 331 @Test332 @SuppressWarnings({ "unchecked", "rawtypes" })333 public void testSetMessageElementsUsingEmptyString() {334 reset(endpoint, consumer, endpointConfiguration);335 when(endpoint.createConsumer()).thenReturn(consumer);336 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);337 when(endpointConfiguration.getTimeout()).thenReturn(5000L);338 339 Message message = new DefaultMessage("<root>"340 + "<element attributeA='attribute-value' attributeB='attribute-value' >"341 + "<sub-elementA attribute='A'></sub-elementA>"342 + "<sub-elementB attribute='B'></sub-elementB>"343 + "<sub-elementC attribute='C'>text-value</sub-elementC>"344 + "</element>"345 + "</root>");346 347 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);348 when(endpoint.getActor()).thenReturn(null);349 350 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();351 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();352 receiveMessageBean.setMessageBuilder(controlMessageBuilder);353 controlMessageBuilder.setPayloadData("<root>"354 + "<element attributeA='attribute-value' attributeB='attribute-value' >"355 + "<sub-elementA attribute='A'>to be overwritten</sub-elementA>"356 + "<sub-elementB attribute='B'>to be overwritten</sub-elementB>"357 + "<sub-elementC attribute='C'>text-value</sub-elementC>"358 + "</element>" 359 + "</root>");360 361 HashMap<String, String> messageElements = new HashMap<String, String>();362 messageElements.put("root.element.sub-elementA", "");363 messageElements.put("sub-elementB", "");364 365 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);366 controlMessageBuilder.add(interceptor);367 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();368 validationContexts.add(validationContext);369 receiveMessageBean.setValidationContexts(validationContexts);370 receiveMessageBean.execute(context);371 }372 373 @Test374 @SuppressWarnings({ "unchecked", "rawtypes" })375 public void testSetMessageElementsAndValidate() {376 reset(endpoint, consumer, endpointConfiguration);377 when(endpoint.createConsumer()).thenReturn(consumer);378 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);379 when(endpointConfiguration.getTimeout()).thenReturn(5000L);380 381 Message message = new DefaultMessage("<root>"382 + "<element attributeA='attribute-value' attributeB='attribute-value' >"383 + "<sub-elementA attribute='A'>text-value</sub-elementA>"384 + "<sub-elementB attribute='B'>text-value</sub-elementB>"385 + "<sub-elementC attribute='C'>text-value</sub-elementC>"386 + "</element>"387 + "</root>");388 389 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);390 when(endpoint.getActor()).thenReturn(null);391 392 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();393 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();394 receiveMessageBean.setMessageBuilder(controlMessageBuilder);395 controlMessageBuilder.setPayloadData("<root>"396 + "<element attributeA='attribute-value' attributeB='attribute-value' >"397 + "<sub-elementA attribute='A'>to be overwritten</sub-elementA>"398 + "<sub-elementB attribute='B'>to be overwritten</sub-elementB>"399 + "<sub-elementC attribute='C'>text-value</sub-elementC>"400 + "</element>" 401 + "</root>");402 403 HashMap<String, String> messageElements = new HashMap<String, String>();404 messageElements.put("root.element.sub-elementA", "text-value");405 messageElements.put("sub-elementB", "text-value");406 407 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);408 controlMessageBuilder.add(interceptor);409 410 HashMap<String, Object> validateElements = new HashMap<>();411 validateElements.put("root.element.sub-elementA", "text-value");412 validateElements.put("sub-elementB", "text-value");413 414 validationContext.setXpathExpressions(validateElements);415 416 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();417 validationContexts.add(validationContext);418 receiveMessageBean.setValidationContexts(validationContexts);419 receiveMessageBean.execute(context);420 }421 422 @Test423 @SuppressWarnings({ "unchecked", "rawtypes" })424 public void testSetMessageElementAttributes() {425 reset(endpoint, consumer, endpointConfiguration);426 when(endpoint.createConsumer()).thenReturn(consumer);427 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);428 when(endpointConfiguration.getTimeout()).thenReturn(5000L);429 430 Message message = new DefaultMessage("<root>"431 + "<element attributeA='attribute-value' attributeB='attribute-value' >"432 + "<sub-elementA attribute='A'>text-value</sub-elementA>"433 + "<sub-elementB attribute='B'>text-value</sub-elementB>"434 + "<sub-elementC attribute='C'>text-value</sub-elementC>"435 + "</element>"436 + "</root>");437 438 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);439 when(endpoint.getActor()).thenReturn(null);440 441 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();442 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();443 receiveMessageBean.setMessageBuilder(controlMessageBuilder);444 controlMessageBuilder.setPayloadData("<root>"445 + "<element attributeA='attribute-value' attributeB='attribute-value' >"446 + "<sub-elementA attribute='to be overwritten'>text-value</sub-elementA>"447 + "<sub-elementB attribute='to be overwritten'>text-value</sub-elementB>"448 + "<sub-elementC attribute='C'>text-value</sub-elementC>"449 + "</element>" 450 + "</root>");451 452 HashMap<String, String> messageElements = new HashMap<String, String>();453 messageElements.put("root.element.sub-elementA.attribute", "A");454 messageElements.put("sub-elementB.attribute", "B");455 456 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);457 controlMessageBuilder.add(interceptor);458 459 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();460 validationContexts.add(validationContext);461 receiveMessageBean.setValidationContexts(validationContexts);462 receiveMessageBean.execute(context);463 }464 465 @Test(expectedExceptions = {CitrusRuntimeException.class})466 @SuppressWarnings({ "unchecked", "rawtypes" })467 public void testSetMessageElementsError() {468 reset(endpoint, consumer, endpointConfiguration);469 when(endpoint.createConsumer()).thenReturn(consumer);470 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);471 when(endpointConfiguration.getTimeout()).thenReturn(5000L);472 473 Message message = new DefaultMessage("<root>"474 + "<element attributeA='attribute-value' attributeB='attribute-value' >"475 + "<sub-elementA attribute='A'>text-value</sub-elementA>"476 + "<sub-elementB attribute='B'>text-value</sub-elementB>"477 + "<sub-elementC attribute='C'>text-value</sub-elementC>"478 + "</element>"479 + "</root>");480 481 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);482 when(endpoint.getActor()).thenReturn(null);483 484 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();485 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();486 receiveMessageBean.setMessageBuilder(controlMessageBuilder);487 controlMessageBuilder.setPayloadData("<root>"488 + "<element attributeA='attribute-value' attributeB='attribute-value' >"489 + "<sub-elementA attribute='A'>to be overwritten</sub-elementA>"490 + "<sub-elementB attribute='B'>to be overwritten</sub-elementB>"491 + "<sub-elementC attribute='C'>text-value</sub-elementC>"492 + "</element>" 493 + "</root>");494 495 HashMap<String, String> messageElements = new HashMap<String, String>();496 messageElements.put("root.element.sub-element-wrong", "text-value");497 messageElements.put("sub-element-wrong", "text-value");498 499 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);500 controlMessageBuilder.add(interceptor);501 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();502 validationContexts.add(validationContext);503 receiveMessageBean.setValidationContexts(validationContexts);504 receiveMessageBean.execute(context);505 }506 507 @Test(expectedExceptions = {CitrusRuntimeException.class})508 @SuppressWarnings({ "unchecked", "rawtypes" })509 public void testSetMessageElementAttributesError() {510 reset(endpoint, consumer, endpointConfiguration);511 when(endpoint.createConsumer()).thenReturn(consumer);512 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);513 when(endpointConfiguration.getTimeout()).thenReturn(5000L);514 515 Message message = new DefaultMessage("<root>"516 + "<element attributeA='attribute-value' attributeB='attribute-value' >"517 + "<sub-elementA attribute='A'>text-value</sub-elementA>"518 + "<sub-elementB attribute='B'>text-value</sub-elementB>"519 + "<sub-elementC attribute='C'>text-value</sub-elementC>"520 + "</element>"521 + "</root>");522 523 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);524 when(endpoint.getActor()).thenReturn(null);525 526 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();527 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();528 receiveMessageBean.setMessageBuilder(controlMessageBuilder);529 controlMessageBuilder.setPayloadData("<root>"530 + "<element attributeA='attribute-value' attributeB='attribute-value' >"531 + "<sub-elementA attribute='to be overwritten'>text-value</sub-elementA>"532 + "<sub-elementB attribute='to be overwritten'>text-value</sub-elementB>"533 + "<sub-elementC attribute='C'>text-value</sub-elementC>"534 + "</element>" 535 + "</root>");536 537 HashMap<String, String> messageElements = new HashMap<String, String>();538 messageElements.put("root.element.sub-elementA.attribute-wrong", "A");539 messageElements.put("sub-elementB.attribute-wrong", "B");540 541 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);542 controlMessageBuilder.add(interceptor);543 544 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();545 validationContexts.add(validationContext);546 receiveMessageBean.setValidationContexts(validationContexts);547 receiveMessageBean.execute(context);548 }549 550 @Test(expectedExceptions = {CitrusRuntimeException.class})551 @SuppressWarnings({ "unchecked", "rawtypes" })552 public void testSetMessageElementAttributesErrorWrongElement() {553 reset(endpoint, consumer, endpointConfiguration);554 when(endpoint.createConsumer()).thenReturn(consumer);555 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);556 when(endpointConfiguration.getTimeout()).thenReturn(5000L);557 558 Message message = new DefaultMessage("<root>"559 + "<element attributeA='attribute-value' attributeB='attribute-value' >"560 + "<sub-elementA attribute='A'>text-value</sub-elementA>"561 + "<sub-elementB attribute='B'>text-value</sub-elementB>"562 + "<sub-elementC attribute='C'>text-value</sub-elementC>"563 + "</element>"564 + "</root>");565 566 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);567 when(endpoint.getActor()).thenReturn(null);568 569 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();570 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();571 receiveMessageBean.setMessageBuilder(controlMessageBuilder);572 controlMessageBuilder.setPayloadData("<root>"573 + "<element attributeA='attribute-value' attributeB='attribute-value' >"574 + "<sub-elementA attribute='to be overwritten'>text-value</sub-elementA>"575 + "<sub-elementB attribute='to be overwritten'>text-value</sub-elementB>"576 + "<sub-elementC attribute='C'>text-value</sub-elementC>"577 + "</element>" 578 + "</root>");579 580 HashMap<String, String> messageElements = new HashMap<String, String>();581 messageElements.put("root.element.sub-elementA-wrong.attribute", "A");582 messageElements.put("sub-elementB-wrong.attribute", "B");583 584 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(messageElements);585 controlMessageBuilder.add(interceptor);586 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();587 validationContexts.add(validationContext);588 receiveMessageBean.setValidationContexts(validationContexts);589 receiveMessageBean.execute(context);590 } 591 @Test592 @SuppressWarnings({ "unchecked", "rawtypes" })593 public void testExtractMessageElements() {594 reset(endpoint, consumer, endpointConfiguration);595 when(endpoint.createConsumer()).thenReturn(consumer);596 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);597 when(endpointConfiguration.getTimeout()).thenReturn(5000L);598 599 Message message = new DefaultMessage("<root>"600 + "<element attributeA='attribute-value' attributeB='attribute-value' >"601 + "<sub-elementA attribute='A'>text-value</sub-elementA>"602 + "<sub-elementB attribute='B'>text-value</sub-elementB>"603 + "<sub-elementC attribute='C'>text-value</sub-elementC>"604 + "</element>"605 + "</root>");606 607 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);608 when(endpoint.getActor()).thenReturn(null);609 610 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();611 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();612 receiveMessageBean.setMessageBuilder(controlMessageBuilder);613 controlMessageBuilder.setPayloadData("<root>"614 + "<element attributeA='attribute-value' attributeB='attribute-value' >"615 + "<sub-elementA attribute='A'>text-value</sub-elementA>"616 + "<sub-elementB attribute='B'>text-value</sub-elementB>"617 + "<sub-elementC attribute='C'>text-value</sub-elementC>"618 + "</element>" 619 + "</root>");620 621 HashMap<String, String> extractMessageElements = new HashMap<String, String>();622 extractMessageElements.put("root.element.sub-elementA", "${valueA}");623 extractMessageElements.put("root.element.sub-elementB", "${valueB}");624 625 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();626 variableExtractor.setXpathExpressions(extractMessageElements);627 628 receiveMessageBean.addVariableExtractors(variableExtractor);629 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();630 validationContexts.add(validationContext);631 receiveMessageBean.setValidationContexts(validationContexts);632 receiveMessageBean.execute(context);633 634 Assert.assertTrue(context.getVariables().containsKey("valueA"));635 Assert.assertEquals(context.getVariables().get("valueA"), "text-value");636 Assert.assertTrue(context.getVariables().containsKey("valueB"));637 Assert.assertEquals(context.getVariables().get("valueB"), "text-value");638 }639 640 @Test641 @SuppressWarnings({ "unchecked", "rawtypes" })642 public void testExtractMessageAttributes() {643 reset(endpoint, consumer, endpointConfiguration);644 when(endpoint.createConsumer()).thenReturn(consumer);645 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);646 when(endpointConfiguration.getTimeout()).thenReturn(5000L);647 648 Message message = new DefaultMessage("<root>"649 + "<element attributeA='attribute-value' attributeB='attribute-value' >"650 + "<sub-elementA attribute='A'>text-value</sub-elementA>"651 + "<sub-elementB attribute='B'>text-value</sub-elementB>"652 + "<sub-elementC attribute='C'>text-value</sub-elementC>"653 + "</element>"654 + "</root>");655 656 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);657 when(endpoint.getActor()).thenReturn(null);658 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();659 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();660 receiveMessageBean.setMessageBuilder(controlMessageBuilder);661 controlMessageBuilder.setPayloadData("<root>"662 + "<element attributeA='attribute-value' attributeB='attribute-value' >"663 + "<sub-elementA attribute='A'>text-value</sub-elementA>"664 + "<sub-elementB attribute='B'>text-value</sub-elementB>"665 + "<sub-elementC attribute='C'>text-value</sub-elementC>"666 + "</element>" 667 + "</root>");668 669 HashMap<String, String> extractMessageElements = new HashMap<String, String>();670 extractMessageElements.put("root.element.sub-elementA.attribute", "${valueA}");671 extractMessageElements.put("root.element.sub-elementB.attribute", "${valueB}");672 673 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();674 variableExtractor.setXpathExpressions(extractMessageElements);675 676 receiveMessageBean.addVariableExtractors(variableExtractor);677 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();678 validationContexts.add(validationContext);679 receiveMessageBean.setValidationContexts(validationContexts);680 receiveMessageBean.execute(context);681 682 Assert.assertTrue(context.getVariables().containsKey("valueA"));683 Assert.assertEquals(context.getVariables().get("valueA"), "A");684 Assert.assertTrue(context.getVariables().containsKey("valueB"));685 Assert.assertEquals(context.getVariables().get("valueB"), "B");686 }687 688 @Test(expectedExceptions = {CitrusRuntimeException.class})689 @SuppressWarnings({ "unchecked", "rawtypes" })690 public void testExtractMessageElementsForWrongElement() {691 reset(endpoint, consumer, endpointConfiguration);692 when(endpoint.createConsumer()).thenReturn(consumer);693 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);694 when(endpointConfiguration.getTimeout()).thenReturn(5000L);695 696 Message message = new DefaultMessage("<root>"697 + "<element attributeA='attribute-value' attributeB='attribute-value' >"698 + "<sub-elementA attribute='A'>text-value</sub-elementA>"699 + "<sub-elementB attribute='B'>text-value</sub-elementB>"700 + "<sub-elementC attribute='C'>text-value</sub-elementC>"701 + "</element>"702 + "</root>");703 704 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);705 when(endpoint.getActor()).thenReturn(null);706 707 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();708 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();709 receiveMessageBean.setMessageBuilder(controlMessageBuilder);710 controlMessageBuilder.setPayloadData("<root>"711 + "<element attributeA='attribute-value' attributeB='attribute-value' >"712 + "<sub-elementA attribute='A'>text-value</sub-elementA>"713 + "<sub-elementB attribute='B'>text-value</sub-elementB>"714 + "<sub-elementC attribute='C'>text-value</sub-elementC>"715 + "</element>" 716 + "</root>");717 718 HashMap<String, String> extractMessageElements = new HashMap<String, String>();719 extractMessageElements.put("root.element.sub-element-wrong", "${valueA}");720 extractMessageElements.put("element.sub-element-wrong", "${valueB}");721 722 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();723 variableExtractor.setXpathExpressions(extractMessageElements);724 725 receiveMessageBean.addVariableExtractors(variableExtractor);726 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();727 validationContexts.add(validationContext);728 receiveMessageBean.setValidationContexts(validationContexts);729 receiveMessageBean.execute(context);730 731 Assert.assertFalse(context.getVariables().containsKey("valueA"));732 Assert.assertFalse(context.getVariables().containsKey("valueB"));733 }734 735 @Test(expectedExceptions = {CitrusRuntimeException.class})736 @SuppressWarnings({ "unchecked", "rawtypes" })737 public void testExtractMessageElementsForWrongAtribute() {738 reset(endpoint, consumer, endpointConfiguration);739 when(endpoint.createConsumer()).thenReturn(consumer);740 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);741 when(endpointConfiguration.getTimeout()).thenReturn(5000L);742 743 Message message = new DefaultMessage("<root>"744 + "<element attributeA='attribute-value' attributeB='attribute-value' >"745 + "<sub-elementA attribute='A'>text-value</sub-elementA>"746 + "<sub-elementB attribute='B'>text-value</sub-elementB>"747 + "<sub-elementC attribute='C'>text-value</sub-elementC>"748 + "</element>"749 + "</root>");750 751 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);752 when(endpoint.getActor()).thenReturn(null);753 754 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();755 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();756 receiveMessageBean.setMessageBuilder(controlMessageBuilder);757 controlMessageBuilder.setPayloadData("<root>"758 + "<element attributeA='attribute-value' attributeB='attribute-value' >"759 + "<sub-elementA attribute='A'>text-value</sub-elementA>"760 + "<sub-elementB attribute='B'>text-value</sub-elementB>"761 + "<sub-elementC attribute='C'>text-value</sub-elementC>"762 + "</element>" 763 + "</root>");764 765 HashMap<String, String> extractMessageElements = new HashMap<String, String>();766 extractMessageElements.put("root.element.sub-elementA.attribute-wrong", "${attributeA}");767 768 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();769 variableExtractor.setXpathExpressions(extractMessageElements);770 771 receiveMessageBean.addVariableExtractors(variableExtractor);772 773 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();774 validationContexts.add(validationContext);775 receiveMessageBean.setValidationContexts(validationContexts);776 receiveMessageBean.execute(context);777 778 Assert.assertFalse(context.getVariables().containsKey("attributeA"));779 }780}...

Full Screen

Full Screen

Source:DefaultPayloadVariableExtractor.java Github

copy

Full Screen

...63 jsonPathVariableExtractor.setJsonPathExpressions(jsonPathExpressions);64 jsonPathVariableExtractor.extractVariables(message, context);65 }66 if (!xpathExpressions.isEmpty()) {67 xpathPayloadVariableExtractor.setXpathExpressions(xpathExpressions);68 xpathPayloadVariableExtractor.extractVariables(message, context);69 }70 }71 /**72 * Sets the JSONPath / XPath expressions.73 * @param pathExpressions74 */75 public void setPathExpressions(Map<String, String> pathExpressions) {76 this.pathExpressions = pathExpressions;77 }78 /**79 * Gets the JSONPath / XPath expressions.80 * @return81 */...

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import org.testng.annotations.Test;3import com.consol.citrus.context.TestContext;4import com.consol.citrus.exceptions.ValidationException;5import com.consol.citrus.testng.AbstractTestNGUnitTest;6import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;7public class XpathPayloadVariableExtractorTest extends AbstractTestNGUnitTest {8 private XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();9 public void testExtractVariables() {10 TestContext context = new TestContext();11 variableExtractor.extractVariables("<Order><OrderID>12345</OrderID></Order>", context);12 Assert.assertEquals(context.getVariable("OrderID"), "12345");13 }14 public void testExtractVariablesMultiple() {15 TestContext context = new TestContext();16 variableExtractor.extractVariables("<Order><OrderID>12345</OrderID><OrderNumber>12345</OrderNumber></Order>", context);17 Assert.assertEquals(context.getVariable("OrderID"), "12345");18 Assert.assertEquals(context.getVariable("OrderNumber"), "12345");19 }20 @Test(expectedExceptions = ValidationException.class)21 public void testExtractVariablesNotFound() {22 TestContext context = new TestContext();23 variableExtractor.extractVariables("<Order><OrderId>12345</OrderId></Order>", context);24 }25 @Test(expectedExceptions = ValidationException.class)26 public void testExtractVariablesNotFoundMultiple() {27 TestContext context = new TestContext();28 variableExtractor.extractVariables("<Order><OrderId>12345</OrderId><OrderNumber>12345</OrderNumber></Order>", context);29 }30}31package com.consol.citrus;32import org.testng.annotations.Test;33import com.consol.citrus.context.TestContext;34import com.consol.citrus.exceptions.Validation

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import java.io.File;3import java.io.IOException;4import java.util.HashMap;5import java.util.Map;6import org.springframework.context.ApplicationContext;7import org.springframework.context.support.ClassPathXmlApplicationContext;8import org.testng.annotations.Test;9import com.consol.citrus.context.TestContext;10import com.consol.citrus.exceptions.CitrusRuntimeException;11import com.consol.citrus.message.DefaultMessage;12import com.consol.citrus.message.Message;13import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;14public class Test4 {15public void test() throws IOException {16ApplicationContext ctx = new ClassPathXmlApplicationContext(17"applicationContext.xml");18TestContext context = ctx.getBean(TestContext.class);19File file = new File("src/test/resources/test.xml");20String xml = FileUtils.readToString(file);21Message message = new DefaultMessage(xml);22XpathPayloadVariableExtractor extractor = new XpathPayloadVariableExtractor();23Map<String, String> xpaths = new HashMap<String, String>();24extractor.setXpathExpressions(xpaths);25extractor.extractVariables(message, context);26}27}28package com.consol.citrus;29import java.io.File;30import java.io.IOException;31import java.util.HashMap;32import java.util.Map;33import org.springframework.context.ApplicationContext;34import org.springframework.context.support.ClassPathXmlApplicationContext;35import org.testng.annotations.Test;36import com.consol.citrus.context.TestContext;37import com.consol.citrus.exceptions.CitrusRuntimeException;38import com.consol.citrus.message.DefaultMessage;39import com.consol.citrus.message.Message;40import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;41public class Test5 {42public void test() throws IOException {43ApplicationContext ctx = new ClassPathXmlApplicationContext(44"applicationContext.xml");45TestContext context = ctx.getBean(TestContext.class);46File file = new File("src/test/resources/test.xml");47String xml = FileUtils.readToString(file);48Message message = new DefaultMessage(xml);49XpathPayloadVariableExtractor extractor = new XpathPayloadVariableExtractor();50Map<String, String> xpaths = new HashMap<String, String>();51extractor.setXpathExpressions(xpaths);52extractor.extractVariables(message, context);53}54}

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1public class XpathPayloadVariableExtractor_setXpathExpressions {2 public static void main(String[] args) {3 XpathPayloadVariableExtractor objXpathPayloadVariableExtractor = new XpathPayloadVariableExtractor();4 List<String> list = new ArrayList<String>();5 list.add("xpath1");6 list.add("xpath2");7 objXpathPayloadVariableExtractor.setXpathExpressions(list);8 }9}10public class XpathPayloadVariableExtractor_setXpathNamespaceContext {11 public static void main(String[] args) {12 XpathPayloadVariableExtractor objXpathPayloadVariableExtractor = new XpathPayloadVariableExtractor();13 NamespaceContext namespaceContext = new NamespaceContext() {14 public String getNamespaceURI(String prefix) {15 return null;16 }17 public String getPrefix(String namespaceURI) {18 return null;19 }20 public Iterator getPrefixes(String namespaceURI) {21 return null;22 }23 };24 objXpathPayloadVariableExtractor.setXpathNamespaceContext(namespaceContext);25 }26}27public class XpathPayloadVariableExtractor_setXpathValidationUtils {28 public static void main(String[] args) {29 XpathPayloadVariableExtractor objXpathPayloadVariableExtractor = new XpathPayloadVariableExtractor();30 XpathValidationUtils xpathValidationUtils = new XpathValidationUtils();31 objXpathPayloadVariableExtractor.setXpathValidationUtils(xpathValidationUtils);32 }33}34public class XpathPayloadVariableExtractor_setXpathVariableExtractors {35 public static void main(String[] args) {36 XpathPayloadVariableExtractor objXpathPayloadVariableExtractor = new XpathPayloadVariableExtractor();37 List<XPathVariableExtractor> list = new ArrayList<XPathVariableExtractor>();38 list.add(new XPathVariableExtractor() {39 public String extract(String name, String value) {40 return null;41 }42 });43 objXpathPayloadVariableExtractor.setXpathVariableExtractors(list);44 }45}

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.annotations.CitrusXmlTest;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import com.consol.citrus.testng.CitrusParameters;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.Resource;8import org.testng.annotations.Test;9public class SetXpathExpressionsJavaITest extends TestNGCitrusTestDesigner {10 private Resource success;11 public void setXpathExpressions() {12 variable("variable1", "citrus:randomNumber(5)");13 variable("variable2", "citrus:randomNumber(5)");14 variable("variable3", "citrus:randomNumber(5)");15 variable("variable4", "citrus:randomNumber(5)");16 variable("variable5", "citrus:randomNumber(5)");17 parallel().actions(18 http().client("httpClient")19 .send()20 .post("/services/rest/api")21 .contentType("text/xml")22 "<orderNumber>${variable1}</orderNumber>" +23 "<orderDate>${variable2}</orderDate>" +24 "<orderAmount>${variable3}</orderAmount>" +25 "<orderCurrency>${variable4}</orderCurrency>" +26 "<orderType>${variable5}</orderType>" +27 http().client("httpClient")28 .receive()29 .response(HttpStatus.OK)30 .payload(success)31 .extractFromPayload("/ns0:orderResponse/ns0:order/orderNumber", "orderNumber")32 .extractFromPayload("/ns0:orderResponse/ns0:order/orderDate", "orderDate")33 .extractFromPayload("/ns0:orderResponse/ns0:order/orderAmount", "orderAmount")34 .extractFromPayload("/ns0:orderResponse/ns0:order/orderCurrency", "orderCurrency")35 .extractFromPayload("/ns0:orderResponse/ns0:order/orderType", "orderType")36 );37 echo("orderNumber: ${orderNumber}");

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;4import org.testng.annotations.Test;5import java.util.HashMap;6import java.util.Map;7public class MyTest extends TestNGCitrusTestDesigner {8 public void myTest() {9 variable("xpathExpressions", new XpathPayloadVariableExtractor()10 .setXpathExpressions(Map.of("/testRequest/text()", "text",11 "/testRequest/number", "number")));12 echo("Text is: ${text}");13 echo("Number is: ${number}");14 }15}16package com.consol.citrus.samples;17import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;18import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;19import org.testng.annotations.Test;20import java.util.HashMap;21import java.util.Map;22public class MyTest extends TestNGCitrusTestDesigner {23 public void myTest() {24 variable("xpathExpressions", new XpathPayloadVariableExtractor()25 echo("Text is: ${text}");26 echo("Number is: ${number}");27 }28}29package com.consol.citrus.samples;30import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;31import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;32import org.testng.annotations.Test;33import java.util.HashMap;34import java.util.Map;35public class MyTest extends TestNGCitrusTestDesigner {36 public void myTest() {37 variable("xpathExpressions", new XpathPayloadVariableExtractor()38 echo("Text is: ${text}");39 echo("

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 XpathPayloadVariableExtractor extractor = new XpathPayloadVariableExtractor();4 extractor.setXpathExpressions(Arrays.asList("/Envelope/Body/Response/Result/text()", "/Envelope/Body/Response/Result/@id"));5 extractor.setNames(Arrays.asList("result", "id"));6 extractor.setPrefixes(Arrays.asList("tns"));7 extractor.setExtractPath(true);8 extractor.setExtractNamespaces(true);9 extractor.setExtractPrefixes(true);10 extractor.setExtractNames(true);11 extractor.setExtractValues(true);12 extractor.setExtractAttributes(true);13 extractor.setExtractTexts(true);14 extractor.setExtractValues(true);15 extractor.setExtractNamespaces(true);16 extractor.setExtractPrefixes(true);17 extractor.setExtractNames(true);18 extractor.setExtractValues(true);19 extractor.setExtractAttributes(true);20 extractor.setExtractTexts(true);21 extractor.setExtractNamespaces(true);22 extractor.setExtractPrefixes(true);23 extractor.setExtractNames(true);24 extractor.setExtractValues(true);25 extractor.setExtractAttributes(true);26 extractor.setExtractTexts(true);27 extractor.setExtractNamespaces(true);28 extractor.setExtractPrefixes(true);29 extractor.setExtractNames(true);30 extractor.setExtractValues(true);31 extractor.setExtractAttributes(true);32 extractor.setExtractTexts(true);33 extractor.setExtractNamespaces(true);34 extractor.setExtractPrefixes(true);35 extractor.setExtractNames(true);36 extractor.setExtractValues(true);37 extractor.setExtractAttributes(true);38 extractor.setExtractTexts(true);39 extractor.setExtractNamespaces(true);40 extractor.setExtractPrefixes(true);41 extractor.setExtractNames(true);42 extractor.setExtractValues(true);43 extractor.setExtractAttributes(true);44 extractor.setExtractTexts(true);45 extractor.setExtractNamespaces(true);46 extractor.setExtractPrefixes(true);47 extractor.setExtractNames(true);48 extractor.setExtractValues(true);49 extractor.setExtractAttributes(true);50 extractor.setExtractTexts(true);51 extractor.setExtractNamespaces(true);52 extractor.setExtractPrefixes(true);53 extractor.setExtractNames(true);54 extractor.setExtractValues(true);55 extractor.setExtractAttributes(true);56 extractor.setExtractTexts(true);57 extractor.setExtractNamespaces(true);58 extractor.setExtractPrefixes(true);

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1public class 4 extends org.springframework.context.support.ClassPathXmlApplicationContext {2 public static void main(String[] args) {3 4 app = new 4();4 app.start();5 }6 public void start() {7 com.consol.citrus.validation.xml.XpathPayloadVariableExtractor xpathPayloadVariableExtractor = (com.consol.citrus.validation.xml.XpathPayloadVariableExtractor) getBean("xpathPayloadVariableExtractor");8 xpathPayloadVariableExtractor.setXpathExpressions(new java.util.HashMap());9 }10}

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestCase {2 public void 4() {3 variable("message", "Hello World!");4 variable("name", "John Doe");5 send("sender")6 .payload("<HelloRequestMessage>" +7 "<Message>${message}</Message>" +8 "<Name>${name}</Name>" +9 .header("operation", "sayHello");10 receive("receiver")11 .payload("<HelloResponseMessage>" +12 "<Message>Hello ${name}!</Message>" +13 .header("operation", "sayHello")14 echo("${response}");15 }16}17public class 5 extends TestCase {18 public void 5() {19 variable("message", "Hello World!");20 variable("name", "John Doe");21 send("sender")22 .payload("<HelloRequestMessage>" +23 "<Message>${message}</Message>" +24 "<Name>${name}</Name>" +25 .header("operation", "sayHello");26 receive("receiver")27 .payload("<HelloResponseMessage>" +28 "<Message>Hello ${name}!</Message>" +29 .header("operation", "sayHello")30 echo("${response}");31 }32}33public class 6 extends TestCase {34 public void 6() {35 variable("message", "Hello World!");36 variable("name", "John Doe");37 send("sender")38 .payload("<HelloRequestMessage>" +39 "<Message>${message}</Message>" +40 "<Name>${name}</Name>" +41 .header("operation", "sayHello");42 receive("receiver")43 .payload("<HelloResponseMessage>" +44 "<Message>Hello ${name}!</Message>" +45 .header("operation", "sayHello")

Full Screen

Full Screen

setXpathExpressions

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestCase {2 public void 4() {3 echo("xPath: " + variable("xPath"));4 echo("xPath: " + variable("xPath"));5 echo("xPath: " + variable("xPath"));6 }7}8public class 5 extends TestCase {9 public void 5() {10 echo("xPath: " + variable("xPath"));11 echo("xPath: " + variable("xPath"));12 echo("xPath: " + variable("xPath"));13 }14}15public class 6 extends TestCase {16 public void 6() {17 echo("xPath: " + variable("xPath"));18 echo("xPath: " + variable("xPath"));19 echo("xPath: " + variable("xPath"));20 }21}22public class 7 extends TestCase {23 public void 7() {24 echo("xPath: " + variable("xPath"));25 echo("xPath: " + variable("xPath"));26 echo("xPath: " + variable("xPath"));27 }28}

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.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in XpathPayloadVariableExtractor

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful