How to use setXPathExpressions method of com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor class

Best Citrus code snippet using com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor.setXPathExpressions

Source:MessageElementsTest.java Github

copy

Full Screen

1/*2 * Copyright 2006-2010 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus;17import com.consol.citrus.actions.ReceiveMessageAction;18import com.consol.citrus.context.TestContext;19import com.consol.citrus.endpoint.Endpoint;20import com.consol.citrus.endpoint.EndpointConfiguration;21import com.consol.citrus.exceptions.CitrusRuntimeException;22import com.consol.citrus.exceptions.ValidationException;23import com.consol.citrus.message.DefaultMessage;24import com.consol.citrus.message.Message;25import com.consol.citrus.messaging.Consumer;26import com.consol.citrus.testng.AbstractTestNGUnitTest;27import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;28import com.consol.citrus.validation.context.ValidationContext;29import com.consol.citrus.validation.xml.*;30import org.mockito.Mockito;31import org.testng.Assert;32import org.testng.annotations.BeforeMethod;33import org.testng.annotations.Test;34import java.util.*;35import static org.mockito.Mockito.*;36/**37 * @author Christoph Deppisch38 */39public class MessageElementsTest extends AbstractTestNGUnitTest {40 private Endpoint endpoint = Mockito.mock(Endpoint.class);41 private Consumer consumer = Mockito.mock(Consumer.class);42 private EndpointConfiguration endpointConfiguration = Mockito.mock(EndpointConfiguration.class);43 44 private ReceiveMessageAction receiveMessageBean;45 46 @Override47 @BeforeMethod48 public void prepareTest() {49 super.prepareTest();50 51 receiveMessageBean = new ReceiveMessageAction();52 receiveMessageBean.setEndpoint(endpoint);53 }54 55 @Test56 @SuppressWarnings({ "unchecked", "rawtypes" })57 public void testValidateMessageElements() {58 reset(endpoint, consumer, endpointConfiguration);59 when(endpoint.createConsumer()).thenReturn(consumer);60 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);61 when(endpointConfiguration.getTimeout()).thenReturn(5000L);62 63 Message message = new DefaultMessage("<root>"64 + "<element attributeA='attribute-value' attributeB='attribute-value' >"65 + "<sub-elementA attribute='A'>text-value</sub-elementA>"66 + "<sub-elementB attribute='B'>text-value</sub-elementB>"67 + "<sub-elementC attribute='C'>text-value</sub-elementC>"68 + "</element>" 69 + "</root>");70 71 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);72 when(endpoint.getActor()).thenReturn(null);73 HashMap<String, Object> validateMessageElements = new HashMap<>();74 validateMessageElements.put("//root/element/sub-elementA", "text-value");75 validateMessageElements.put("//sub-elementB", "text-value");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

1/*2 * Copyright 2006-2010 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus;17import com.consol.citrus.actions.ReceiveMessageAction;18import com.consol.citrus.context.TestContext;19import com.consol.citrus.endpoint.Endpoint;20import com.consol.citrus.endpoint.EndpointConfiguration;21import com.consol.citrus.exceptions.CitrusRuntimeException;22import com.consol.citrus.exceptions.ValidationException;23import com.consol.citrus.message.DefaultMessage;24import com.consol.citrus.message.Message;25import com.consol.citrus.messaging.Consumer;26import com.consol.citrus.testng.AbstractTestNGUnitTest;27import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;28import com.consol.citrus.validation.context.ValidationContext;29import com.consol.citrus.validation.xml.*;30import org.mockito.Mockito;31import org.testng.Assert;32import org.testng.annotations.BeforeMethod;33import org.testng.annotations.Test;34import java.util.*;35import static org.mockito.Mockito.*;36/**37 * @author Christoph Deppisch38 */39public class MessageElementsLegacyTest extends AbstractTestNGUnitTest {40 private Endpoint endpoint = Mockito.mock(Endpoint.class);41 private Consumer consumer = Mockito.mock(Consumer.class);42 private EndpointConfiguration endpointConfiguration = Mockito.mock(EndpointConfiguration.class);43 44 private ReceiveMessageAction receiveMessageBean;45 46 @Override47 @BeforeMethod48 public void prepareTest() {49 super.prepareTest();50 51 receiveMessageBean = new ReceiveMessageAction();52 receiveMessageBean.setEndpoint(endpoint);53 }54 55 @Test56 @SuppressWarnings({ "unchecked", "rawtypes" })57 public void testValidateMessageElements() {58 reset(endpoint, consumer, endpointConfiguration);59 when(endpoint.createConsumer()).thenReturn(consumer);60 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);61 when(endpointConfiguration.getTimeout()).thenReturn(5000L);62 63 Message message = new DefaultMessage("<root>"64 + "<element attributeA='attribute-value' attributeB='attribute-value' >"65 + "<sub-elementA attribute='A'>text-value</sub-elementA>"66 + "<sub-elementB attribute='B'>text-value</sub-elementB>"67 + "<sub-elementC attribute='C'>text-value</sub-elementC>"68 + "</element>" 69 + "</root>");70 71 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);72 when(endpoint.getActor()).thenReturn(null);73 HashMap<String, Object> validateMessageElements = new HashMap<>();74 validateMessageElements.put("root.element.sub-elementA", "text-value");75 validateMessageElements.put("sub-elementB", "text-value");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:XpathMessageConstructionInterceptor.java Github

copy

Full Screen

...109 }110 /**111 * @param xPathExpressions the xPathExpressions to set112 */113 public void setXPathExpressions(final Map<String, String> xPathExpressions) {114 this.xPathExpressions = xPathExpressions;115 }116 /**117 * Gets the xPathExpressions.118 * @return the xPathExpressions119 */120 public Map<String, String> getXPathExpressions() {121 return xPathExpressions;122 }123}...

Full Screen

Full Screen

setXPathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.validation.xml;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.message.Message;4import com.consol.citrus.message.MessageBuilder;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.testng.AbstractTestNGUnitTest;7import org.testng.Assert;8import org.testng.annotations.Test;9import org.springframework.xml.xpath.XPathExpression;10import org.springframework.xml.xpath.XPathExpressionFactory;11import java.util.HashMap;12import java.util.Map;13import static org.mockito.Mockito.*;14public class SetXPathExpressionsTest extends AbstractTestNGUnitTest {15 private XPathMessageConstructionInterceptor messageConstructionInterceptor = new XPathMessageConstructionInterceptor();16 private final Map<String, XPathExpression> xPathExpressions = new HashMap<String, XPathExpression>();17 public void testSetXPathExpressions() {18 messageConstructionInterceptor.setXPathExpressions(xPathExpressions);19 Assert.assertEquals(messageConstructionInterceptor.getXPathExpressions(), xPathExpressions);20 }21 public void testSetXPathExpressionsWithString() {22 messageConstructionInterceptor.setXPathExpressions(xPathExpressions);23 Assert.assertEquals(messageConstructionInterceptor.getXPathExpressions(), xPathExpressions);24 }25 public void testHandleMessageConstruction() {26 final String xmlMessage = "<root><test1>test1</test1><test2>test2</test2></root>";27 final Map<String, Object> headers = new HashMap<String, Object>();28 headers.put("Header1", "Value1");29 headers.put("Header2", "Value2");30 messageConstructionInterceptor.setXPathExpressions(xPathExpressions);31 Message message = MessageBuilder.withPayload(xmlMessage).setHeader("Header1", "Value1").setHeader("Header2", "Value2").build();32 messageConstructionInterceptor.handleMessageConstruction(message, MessageType.XML.name(), context);33 Assert.assertEquals(message.getPayload

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.annotations.CitrusTest;4import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;5import com.consol.citrus.xml.XpathMessageConstructionInterceptor;6public class 4 extends TestNGCitrusTestRunner {7public void test4() {8XpathMessageConstructionInterceptor x = new XpathMessageConstructionInterceptor();9send("sftp:localhost:2222/input?username=admin&password=admin&knownHosts=classpath:known_hosts&privateKeyPath=classpath:private_key&privateKeyPassphrase=passphrase&autoCreateLocalDirectory=true&autoCreateRemoteDirectory=true", "<root><name>citrus</name><name>citrus</name></root>");10}11}12package com.consol.citrus;13import org.testng.annotations.Test;14import com.consol.citrus.annotations.CitrusTest;15import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;16import com.consol.citrus.xml.XpathMessageConstructionInterceptor;17public class 5 extends TestNGCitrusTestRunner {18public void test5() {19XpathMessageConstructionInterceptor x = new XpathMessageConstructionInterceptor();20send("sftp:localhost:2222/input?username=admin&password=admin&knownHosts=classpath:known_hosts&privateKeyPath=classpath:private_key&privateKeyPassphrase=passphrase&autoCreateLocalDirectory=true&autoCreateRemoteDirectory=true", "<root><name>citrus</name><name>citrus</name></root>");21}22}23package com.consol.citrus;24import org.testng.annotations.Test;25import com.consol.citrus.annotations.CitrusTest;26import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;27import com.consol.citrus.xml.XpathMessageConstructionInterceptor;28public class 6 extends TestNGCitrusTestRunner {

Full Screen

Full Screen

setXPathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.validation.xml;2import java.util.HashMap;3import java.util.Map;4import org.springframework.context.ApplicationContext;5import org.springframework.context.support.ClassPathXmlApplicationContext;6import org.testng.Assert;7import org.testng.annotations.Test;8import com.consol.citrus.context.TestContext;9import com.consol.citrus.context.TestContextFactory;10import com.consol.citrus.exceptions.CitrusRuntimeException;11import com.consol.citrus.testng.AbstractTestNGUnitTest;12import com.consol.citrus.validation.context.ValidationContext;13public class SetXPathExpressionsTest extends AbstractTestNGUnitTest {14 private ApplicationContext applicationContext = new ClassPathXmlApplicationContext("com/consol/citrus/validation/xml/SetXPathExpressionsTest-context.xml");15 private TestContextFactory testContextFactory = new TestContextFactory(applicationContext);16 public void testSetXPathExpressions() {17 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor();18 Map<String, String> xPathExpressions = new HashMap<String, String>();19 interceptor.setXPathExpressions(xPathExpressions);20 TestContext context = testContextFactory.getObject();21 ValidationContext validationContext = new ValidationContext();22 }23 public void testSetInvalidXPathExpressions() {24 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor();25 Map<String, String> xPathExpressions = new HashMap<String, String>();26 interceptor.setXPathExpressions(xPathExpressions);27 TestContext context = testContextFactory.getObject();28 ValidationContext validationContext = new ValidationContext();29 try {30 Assert.fail("Missing exception due to invalid XPath expression");31 } catch (CitrusRuntimeException e) {32 Assert.assertTrue(e.getMessage().contains("Invalid XPath expression"));33 }34 }35}

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.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;5public class 4 extends TestNGCitrusTestDesigner {6public void 4() {7variable("testName", "4");8echo("Executing test case: ${testName}");9http()10.client("httpClient")11.send()12.get("/api/users?page=2")13.header("Accept", "application/xml");14http()15.client("httpClient")16.receive()17.response(HttpStatus.OK)18.messageType(MessageType.XML)19.validateScript("classpath:com/consol/citrus/scripts/4.groovy")

Full Screen

Full Screen

setXPathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.validation.xml;2import java.util.HashMap;3import java.util.Map;4import org.testng.annotations.Test;5import com.consol.citrus.testng.AbstractTestNGUnitTest;6import com.consol.citrus.validation.builder.DefaultMessageBuilder;7import com.consol.citrus.validation.builder.StaticMessageContentBuilder;8import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;9public class XpathMessageConstructionInterceptorTest extends AbstractTestNGUnitTest {10 public void testXpathMessageConstructionInterceptor() {11 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor();12 Map<String, String> xpathExpressions = new HashMap<>();13 xpathExpressions.put("/ns0:TestRequest/ns0:Message", "Hello World");14 interceptor.setXpathExpressions(xpathExpressions);15 DefaultMessageBuilder messageBuilder = new DefaultMessageBuilder();16 messageBuilder.setMessageContent(new StaticMessageContentBuilder("<TestRequest><Message>Hello World</Message></TestRequest>"));17 messageBuilder.addMessageConstructionInterceptor(interceptor);18 assertMessageBuilder(messageBuilder);19 }20}21package com.consol.citrus.validation.xml;22import java.util.HashMap;23import java.util.Map;24import org.testng.annotations.Test;25import com.consol.citrus.testng.AbstractTestNGUnitTest;26import com.consol.citrus.validation.builder.DefaultMessageBuilder;27import com.consol.citrus.validation.builder.StaticMessageContentBuilder;28import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;29public class XpathMessageConstructionInterceptorTest extends AbstractTestNGUnitTest {30 public void testXpathMessageConstructionInterceptor() {31 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor();32 Map<String, String> xpathNamespaces = new HashMap<>();33 interceptor.setXpathNamespaces(xpathNamespaces);34 DefaultMessageBuilder messageBuilder = new DefaultMessageBuilder();35 messageBuilder.setMessageContent(new StaticMessageContentBuilder("<TestRequest><Message>Hello World</Message></TestRequest>"));36 messageBuilder.addMessageConstructionInterceptor(interceptor);37 assertMessageBuilder(messageBuilder);38 }39}

Full Screen

Full Screen

setXPathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.builder;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;4import org.springframework.util.StringUtils;5import java.util.HashMap;6import java.util.Map;7public class XpathMessageConstructionInterceptorBuilder extends AbstractMessageConstructionInterceptorBuilder<XpathMessageConstructionInterceptor> {8 private final Map<String, String> xPathExpressions = new HashMap<>();9 public XpathMessageConstructionInterceptorBuilder() {10 this.interceptor = new XpathMessageConstructionInterceptor();11 }12 public XpathMessageConstructionInterceptorBuilder setXPathExpressions(Map<String, String> xPathExpressions) {13 this.xPathExpressions.putAll(xPathExpressions);14 return this;15 }16 public XpathMessageConstructionInterceptorBuilder setXPathExpressions(String xPathExpressions) {17 if (StringUtils.hasText(xPathExpressions)) {18 for (String xPathExpression : xPathExpressions.split(",")) {19 String[] parts = xPathExpression.split("=");20 this.xPathExpressions.put(parts[0], parts[1]);21 }22 }23 return this;24 }25 public XpathMessageConstructionInterceptor getObject() {26 interceptor.setXPathExpressions(xPathExpressions);27 return interceptor;28 }29}30package com.consol.citrus.dsl.builder;31import com.consol.citrus.context.TestContext;32import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;33import org.springframework.util.StringUtils;34import java.util.HashMap;35import java.util.Map;36public class XpathMessageConstructionInterceptorBuilder extends AbstractMessageConstructionInterceptorBuilder<XpathMessageConstructionInterceptor> {37 private final Map<String, String> xPathExpressions = new HashMap<>();38 public XpathMessageConstructionInterceptorBuilder() {39 this.interceptor = new XpathMessageConstructionInterceptor();40 }41 public XpathMessageConstructionInterceptorBuilder setXPathExpressions(Map<String, String

Full Screen

Full Screen

setXPathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.builder;2import org.springframework.util.StringUtils;3import org.w3c.dom.Document;4import org.w3c.dom.Node;5import org.w3c.dom.NodeList;6import org.xml.sax.InputSource;7import javax.xml.parsers.DocumentBuilder;8import javax.xml.parsers.DocumentBuilderFactory;9import javax.xml.xpath.XPath;10import javax.xml.xpath.XPathConstants;11import javax.xml.xpath.XPathFactory;12import java.io.StringReader;13import java.util.HashMap;14import java.util.Map;15import java.util.Map.Entry;16import java.util.Set;17import java.util.regex.Matcher;18import java.util.regex.Pattern;19public class XPathMessageConstructionInterceptor extends MessageConstructionInterceptor {20 private static final String XPATH_EXPRESSION_PREFIX = "xpath:";21 private static final String XPATH_EXPRESSION_REGEX = "xpath:\\w+";22 private static final String XPATH_EXPRESSION_SEPARATOR = ",";23 private Map<String, String> xPathExpressions = new HashMap<String, String>();24 public XPathMessageConstructionInterceptor() {25 super();26 }27 public XPathMessageConstructionInterceptor(Map<String, String> xPathExpressions) {28 this.xPathExpressions = xPathExpressions;29 }30 public void interceptMessagePayload(String messageType, String messageName, Object payload, Map<String, Object> headers) {31 if (payload instanceof String) {32 String payloadString = (String) payload;33 Set<Entry<String, String>> xpathExpressions = xPathExpressions.entrySet();34 for (Entry<String, String> xpathExpression : xpathExpressions) {35 String key = xpathExpression.getKey();36 String value = xpathExpression.getValue();37 String xpathResult = evaluateXPathExpression(payloadString, value);38 if (StringUtils.hasText(xpathResult)) {39 headers.put(key, xpathResult);40 }41 }42 }43 }44 private String evaluateXPathExpression(String payload, String xpathExpression) {45 try {46 DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();47 Document document = documentBuilder.parse(new InputSource(new StringReader(payload)));48 XPath xPath = XPathFactory.newInstance().newXPath();49 NodeList nodeList = (NodeList) xPath.evaluate(xpathExpression, document, XPathConstants

Full Screen

Full Screen

setXPathExpressions

Using AI Code Generation

copy

Full Screen

1public void testSetXPathExpressions() {2 XpathMessageConstructionInterceptor xpathMessageConstructionInterceptor = new XpathMessageConstructionInterceptor();3 List<String> xPathExpressions = xpathMessageConstructionInterceptor.getXPathExpressions();4 Assert.assertEquals(xPathExpressions.size(), 2);5}6Source Project: spring-integration Source File: XpathMessageTransformationTests.java License: Apache License 2.0 5 votes /** * Test the XPath message transformation with a {@link MessageTransformationException} * thrown because the XPath expression is invalid. */ @Test public void testInvalidXPathExpression() { Message<?> message = MessageBuilder.withPayload("<test>test</test>") .build(); MessageTransformationException exception = Assertions.assertThrows(MessageTransformationException.class, () -> this.transformer.transform(message)); assertThat(exception.getMessage()).startsWith("Failed to evaluate XPath expression"); }7Source Project: spring-integration Source File: XpathMessageTransformationTests.java License: Apache License 2.0 5 votes /** * Test the XPath message transformation with a {@link MessageTransformationException} * thrown because the XPath expression is invalid. */ @Test public void testInvalidXPathExpression() { Message<?> message = MessageBuilder.withPayload("<test>test</test>") .build(); MessageTransformationException exception = Assertions.assertThrows(MessageTransformationException.class, () -> this.transformer.transform(message)); assertThat(exception.getMessage()).startsWith("Failed to evaluate XPath expression"); }8Source Project: spring-integration Source File: XpathMessageTransformationTests.java License: Apache License 2.0 5 votes /** * Test the XPath message transformation with a {@link MessageTransformationException} * thrown because the XPath expression is invalid. */ @Test public void testInvalidXPathExpression() { Message<?> message = MessageBuilder.withPayload("<test>test</test>") .build(); MessageTransformationException exception = Assertions.assertThrows(MessageTransformationException.class, () -> this.transformer.transform(message)); assertThat(exception.getMessage()).startsWith("Failed to evaluate XPath expression"); }9Source Project: spring-integration Source File: XpathMessageTransformationTests.java License: Apache License 2.0 5 votes /** * Test the XPath message transformation with a {@link MessageTransformationException}

Full Screen

Full Screen

setXPathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import org.springframework.context.annotation.Bean;3import org.springframework.context.annotation.Configuration;4import org.springframework.context.annotation.Import;5import com.consol.citrus.dsl.builder.Builder;6import com.consol.citrus.dsl.runner.TestRunner;7import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;8import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;9import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;10import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;11import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;12import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;13import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;14import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;15import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;16import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;17import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;18import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;19import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;20import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;21import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;22import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;23import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;24import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;25import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;26import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;27import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;28import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;29import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;30import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;31import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;32import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;33import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;34import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;35import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;

Full Screen

Full Screen

setXPathExpressions

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.ClassPathResource;8import org.testng.annotations.Test;9import java.util.HashMap;10import java.util.Map;11public class CitrusSetXPathExpressionsTest extends TestNGCitrusTestRunner {12 private XpathMessageConstructionInterceptor xPathMessageConstructionInterceptor;13 public void setXPathExpressions() {14 xPathMessageConstructionInterceptor.setMessageType(MessageType.XML);15 xPathMessageConstructionInterceptor.setNamespaces(getNamespaces());16 variable("title", "XML Developer's Guide");17 variable("author", "Christian Nagel");18 send("sendMessageEndpoint")19 .payload(new ClassPathResource("com/consol/citrus/samples/4.xml"))20 .messageType(MessageType.XML)21 .messageConstructionInterceptor(xPathMessageConstructionInterceptor);22 receive("receiveMessageEndpoint")23 .payload(new ClassPathResource("com/consol/citrus/samples/4.xml"))24 .messageType(MessageType.XML)25 .messageConstructionInterceptor(xPathMessageConstructionInterceptor);26 }27 private Map<String, String> getNamespaces() {28 Map<String, String> namespaces = new HashMap<>();29 return namespaces;30 }31}32package com.consol.citrus.samples;33import com.consol.citrus.annotations.CitrusTest;34import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;35import com.consol.citrus.message.MessageType;36import com.consol.citrus.validation.xml.X

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful