Best Citrus code snippet using com.consol.citrus.validation.xml.DomXmlMessageValidator.validateMessage
Source:DomXmlMessageValidatorTest.java
...552 + "</element>"553 + "</root>");554 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();555 DomXmlMessageValidator validator = new DomXmlMessageValidator();556 validator.validateMessage(message, controlMessage, context, validationContext);557 }558 559 @Test560 public void testValidateMessagePayloadWithIgnoresSuccess() {561 Message message = new DefaultMessage("<root>"562 + "<element attributeA='attribute-value' attributeB='attribute-value'>"563 + "<sub-element1 attribute='A'>THIS_IS_IGNORED_BY_XPATH</sub-element1>"564 + "<sub-element2 attribute='A'>THIS IS IGNORED BY IGNORE-EXPR</sub-element2>"565 + "<sub-element3 attribute='A'>a text</sub-element3>"566 + "</element>"567 + "</root>");568 Message controlMessage = new DefaultMessage("<root>"569 + "<element attributeA='attribute-value' attributeB='attribute-value'>"570 + "<sub-element1 attribute='A'>text-value</sub-element1>"571 + "<sub-element2 attribute='A'>@ignore@</sub-element2>"572 + "<sub-element3 attribute='A'>a text</sub-element3>"573 + "</element>"574 + "</root>");575 Set<String> ignoreExpressions = new HashSet<String>();576 ignoreExpressions.add("//root/element/sub-element1");577 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();578 validationContext.setIgnoreExpressions(ignoreExpressions);579 DomXmlMessageValidator validator = new DomXmlMessageValidator();580 validator.validateMessage(message, controlMessage, context, validationContext);581 }582 583 @Test(expectedExceptions = {ValidationException.class})584 public void testValidateMessagePayloadWithValidationMatchersFailsBecauseOfAttribute() {585 Message message = new DefaultMessage("<root>"586 + "<element attributeA='attribute-value' attributeB='attribute-value'>"587 + "<sub-element attribute='text-attribute'>text-element</sub-element>"588 + "</element>"589 + "</root>");590 Message controlMessage = new DefaultMessage("<root>"591 + "<element attributeA='attribute-value' attributeB='attribute-value'>"592 + "<sub-element attribute='@startsWith(FAIL)@'>@startsWith(text)@</sub-element>"593 + "</element>"594 + "</root>");595 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();596 DomXmlMessageValidator validator = new DomXmlMessageValidator();597 validator.validateMessage(message, controlMessage, context, validationContext);598 }599 600 @Test(expectedExceptions = {ValidationException.class})601 public void testValidateMessagePayloadWithValidationMatcherOnElementFails() {602 Message message = new DefaultMessage("<root>"603 + "<element attributeA='attribute-value' attributeB='attribute-value'>"604 + "<sub-element attribute='text-attribute'>text-element</sub-element>"605 + "</element>"606 + "</root>");607 Message controlMessage = new DefaultMessage("<root>"608 + "<element attributeA='attribute-value' attributeB='attribute-value'>"609 + "<sub-element attribute='text-attribute'>@startsWith(FAIL)@</sub-element>"610 + "</element>"611 + "</root>");612 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();613 DomXmlMessageValidator validator = new DomXmlMessageValidator();614 validator.validateMessage(message, controlMessage, context, validationContext);615 }616 617 @Test(expectedExceptions = {ValidationException.class})618 public void testValidateMessagePayloadWithValidationMatcherOnAttributeFails() {619 Message message = new DefaultMessage("<root>"620 + "<element attributeA='attribute-value' attributeB='attribute-value'>"621 + "<sub-element attribute='text-attribute'>text-element</sub-element>"622 + "</element>"623 + "</root>");624 Message controlMessage = new DefaultMessage("<root>"625 + "<element attributeA='attribute-value' attributeB='attribute-value'>"626 + "<sub-element attribute='@startsWith(FAIL)@'>text-element</sub-element>"627 + "</element>"628 + "</root>");629 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();630 DomXmlMessageValidator validator = new DomXmlMessageValidator();631 validator.validateMessage(message, controlMessage, context, validationContext);632 }633 @Test634 public void testNamespaceQualifiedAttributeValue() {635 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"636 + "<element xsi:type='ns1:attribute-value' attributeB='attribute-value'>"637 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"638 + "</element>"639 + "</root>");640 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"641 + "<element xsi:type='ns1:attribute-value' attributeB='attribute-value'>"642 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"643 + "</element>"644 + "</root>");645 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();646 DomXmlMessageValidator validator = new DomXmlMessageValidator();647 validator.validateMessage(message, controlMessage, context, validationContext);648 }649 @Test650 public void testNamespaceQualifiedAttributeValueParentDeclaration() {651 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"652 + "<element xmlns:ns1='http://citrusframework.org/ns1' xsi:type='ns1:attribute-value' attributeB='attribute-value'>"653 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"654 + "</element>"655 + "</root>");656 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"657 + "<element xsi:type='ns1:attribute-value' attributeB='attribute-value'>"658 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"659 + "</element>"660 + "</root>");661 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();662 DomXmlMessageValidator validator = new DomXmlMessageValidator();663 validator.validateMessage(message, controlMessage, context, validationContext);664 }665 @Test666 public void testNamespaceQualifiedAttributeValueParentDeclarationInSource() {667 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"668 + "<element xmlns:ns1='http://citrusframework.org/ns1' xsi:type='ns1:attribute-value' attributeB='attribute-value'>"669 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"670 + "</element>"671 + "</root>");672 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"673 + "<element xmlns:ns1='http://citrusframework.org/ns1' xsi:type='ns1:attribute-value' attributeB='attribute-value'>"674 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"675 + "</element>"676 + "</root>");677 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();678 DomXmlMessageValidator validator = new DomXmlMessageValidator();679 validator.validateMessage(message, controlMessage, context, validationContext);680 }681 @Test682 public void testNamespaceQualifiedAttributeValueDifferentPrefix() {683 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"684 + "<element xsi:type='ns1:attribute-value' attributeB='attribute-value'>"685 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"686 + "</element>"687 + "</root>");688 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:cit='http://citrusframework.org/ns1' xmlns:cit2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"689 + "<element xsi:type='cit:attribute-value' attributeB='attribute-value'>"690 + "<sub-element xsi:type='cit2:AType'>text-value</sub-element>"691 + "</element>"692 + "</root>");693 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();694 DomXmlMessageValidator validator = new DomXmlMessageValidator();695 validator.validateMessage(message, controlMessage, context, validationContext);696 }697 @Test698 public void testNamespaceQualifiedLikeAttributeValues() {699 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"700 + "<element credentials='username:password' attributeB='attribute-value'>"701 + "<sub-element>text-value</sub-element>"702 + "</element>"703 + "</root>");704 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"705 + "<element credentials='username:password' attributeB='attribute-value'>"706 + "<sub-element>text-value</sub-element>"707 + "</element>"708 + "</root>");709 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();710 DomXmlMessageValidator validator = new DomXmlMessageValidator();711 validator.validateMessage(message, controlMessage, context, validationContext);712 }713 @Test714 public void testCommentBeforeRootElement() {715 Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"716 + "<!-- some comment -->"717 + "<root>"718 + "<element>test</element>"719 + "</root>");720 Message controlMessage = new DefaultMessage("<root>"721 + "<element>test</element>"722 + "</root>");723 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();724 DomXmlMessageValidator validator = new DomXmlMessageValidator();725 validator.validateMessage(message, controlMessage, context, validationContext);726 }727 @Test728 public void testComment() {729 Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"730 + "<root>"731 + "<!-- some comment -->"732 + "<element>test</element>"733 + "</root>");734 Message controlMessage = new DefaultMessage("<root>"735 + "<element>test</element>"736 + "</root>");737 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();738 DomXmlMessageValidator validator = new DomXmlMessageValidator();739 validator.validateMessage(message, controlMessage, context, validationContext);740 }741 @Test(expectedExceptions = {ValidationException.class})742 public void testNamespaceQualifiedAttributeValueFails() {743 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"744 + "<element xsi:type='ns1:attribute-value' attributeB='attribute-value'>"745 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"746 + "</element>"747 + "</root>");748 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"749 + "<element xsi:type='ns1:wrong-value' attributeB='attribute-value'>"750 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"751 + "</element>"752 + "</root>");753 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();754 DomXmlMessageValidator validator = new DomXmlMessageValidator();755 validator.validateMessage(message, controlMessage, context, validationContext);756 }757 @Test(expectedExceptions = {ValidationException.class})758 public void testNamespaceQualifiedAttributeValueUriMismatch() {759 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"760 + "<element xsi:type='ns1:attribute-value' attributeB='attribute-value'>"761 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"762 + "</element>"763 + "</root>");764 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:cit='http://citrusframework.org/cit' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"765 + "<element xsi:type='cit:attribute-value' attributeB='attribute-value'>"766 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"767 + "</element>"768 + "</root>");769 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();770 DomXmlMessageValidator validator = new DomXmlMessageValidator();771 validator.validateMessage(message, controlMessage, context, validationContext);772 }773 @Test(expectedExceptions = {ValidationException.class})774 public void testNamespaceQualifiedAttributeMissingPrefix() {775 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"776 + "<element xsi:type='attribute-value' attributeB='attribute-value'>"777 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"778 + "</element>"779 + "</root>");780 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/cit' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"781 + "<element xsi:type='ns1:attribute-value' attributeB='attribute-value'>"782 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"783 + "</element>"784 + "</root>");785 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();786 DomXmlMessageValidator validator = new DomXmlMessageValidator();787 validator.validateMessage(message, controlMessage, context, validationContext);788 }789 @Test(expectedExceptions = {ValidationException.class})790 public void testNamespaceQualifiedAttributeValueMissingDeclaration() {791 Message message = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns1='http://citrusframework.org/ns1' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"792 + "<element xsi:type='ns1:attribute-value' attributeB='attribute-value'>"793 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"794 + "</element>"795 + "</root>");796 Message controlMessage = new DefaultMessage("<root xmlns='http://citrusframework.org/default' xmlns:ns2='http://citrusframework.org/ns2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"797 + "<element xsi:type='cit:attribute-value' attributeB='attribute-value'>"798 + "<sub-element xsi:type='ns2:AType'>text-value</sub-element>"799 + "</element>"800 + "</root>");801 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();802 DomXmlMessageValidator validator = new DomXmlMessageValidator();803 validator.validateMessage(message, controlMessage, context, validationContext);804 }805}...
Source:SendMessageActionTest.java
...69 @Override70 public Object answer(InvocationOnMock invocation) throws Throwable {71 DomXmlMessageValidator validator = new DomXmlMessageValidator();72 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();73 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);74 return null;75 }76 }).when(producer).send(any(Message.class), any(TestContext.class));77 when(endpoint.getActor()).thenReturn(null);78 79 sendAction.execute(context);80 }81 82 @Test83 @SuppressWarnings("rawtypes")84 public void testSendMessageWithMessagePayloadResource() {85 SendMessageAction sendAction = new SendMessageAction();86 sendAction.setEndpoint(endpoint);87 88 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();89 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload.xml");90 91 sendAction.setMessageBuilder(messageBuilder);92 93 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");94 reset(endpoint, producer, endpointConfiguration);95 when(endpoint.createProducer()).thenReturn(producer);96 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);97 doAnswer(new Answer() {98 @Override99 public Object answer(InvocationOnMock invocation) throws Throwable {100 DomXmlMessageValidator validator = new DomXmlMessageValidator();101 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();102 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);103 return null;104 }105 }).when(producer).send(any(Message.class), any(TestContext.class));106 when(endpoint.getActor()).thenReturn(null);107 108 sendAction.execute(context);109 }110 111 @Test112 @SuppressWarnings("rawtypes")113 public void testSendMessageWithMessageBuilderScriptData() {114 SendMessageAction sendAction = new SendMessageAction();115 sendAction.setEndpoint(endpoint);116 StringBuilder sb = new StringBuilder();117 sb.append("markupBuilder.TestRequest(){\n");118 sb.append("Message('Hello World!')\n");119 sb.append("}");120 121 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();122 scriptMessageBuidler.setScriptData(sb.toString());123 124 sendAction.setMessageBuilder(scriptMessageBuidler);125 126 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");127 reset(endpoint, producer, endpointConfiguration);128 when(endpoint.createProducer()).thenReturn(producer);129 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);130 doAnswer(new Answer() {131 @Override132 public Object answer(InvocationOnMock invocation) throws Throwable {133 DomXmlMessageValidator validator = new DomXmlMessageValidator();134 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();135 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);136 return null;137 }138 }).when(producer).send(any(Message.class), any(TestContext.class));139 when(endpoint.getActor()).thenReturn(null);140 141 sendAction.execute(context);142 }143 144 @Test145 @SuppressWarnings("rawtypes")146 public void testSendMessageWithMessageBuilderScriptDataVariableSupport() {147 context.setVariable("text", "Hello World!");148 149 SendMessageAction sendAction = new SendMessageAction();150 sendAction.setEndpoint(endpoint);151 StringBuilder sb = new StringBuilder();152 sb.append("markupBuilder.TestRequest(){\n");153 sb.append("Message('${text}')\n");154 sb.append("}");155 156 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();157 scriptMessageBuidler.setScriptData(sb.toString());158 159 sendAction.setMessageBuilder(scriptMessageBuidler);160 161 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");162 reset(endpoint, producer, endpointConfiguration);163 when(endpoint.createProducer()).thenReturn(producer);164 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);165 doAnswer(new Answer() {166 @Override167 public Object answer(InvocationOnMock invocation) throws Throwable {168 DomXmlMessageValidator validator = new DomXmlMessageValidator();169 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();170 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);171 return null;172 }173 }).when(producer).send(any(Message.class), any(TestContext.class));174 when(endpoint.getActor()).thenReturn(null);175 176 sendAction.execute(context);177 }178 179 @Test180 @SuppressWarnings("rawtypes")181 public void testSendMessageWithMessageBuilderScriptResource() {182 SendMessageAction sendAction = new SendMessageAction();183 sendAction.setEndpoint(endpoint);184 185 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();186 scriptMessageBuidler.setScriptResourcePath("classpath:com/consol/citrus/actions/test-request-payload.groovy");187 188 sendAction.setMessageBuilder(scriptMessageBuidler);189 190 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");191 reset(endpoint, producer, endpointConfiguration);192 when(endpoint.createProducer()).thenReturn(producer);193 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);194 doAnswer(new Answer() {195 @Override196 public Object answer(InvocationOnMock invocation) throws Throwable {197 DomXmlMessageValidator validator = new DomXmlMessageValidator();198 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();199 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);200 return null;201 }202 }).when(producer).send(any(Message.class), any(TestContext.class));203 when(endpoint.getActor()).thenReturn(null);204 205 sendAction.execute(context);206 }207 208 @Test209 @SuppressWarnings("rawtypes")210 public void testSendMessageWithMessagePayloadDataVariablesSupport() {211 SendMessageAction sendAction = new SendMessageAction();212 sendAction.setEndpoint(endpoint);213 214 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();215 messageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");216 217 sendAction.setMessageBuilder(messageBuilder);218 219 context.setVariable("myText", "Hello World!");220 221 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");222 reset(endpoint, producer, endpointConfiguration);223 when(endpoint.createProducer()).thenReturn(producer);224 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);225 doAnswer(new Answer() {226 @Override227 public Object answer(InvocationOnMock invocation) throws Throwable {228 DomXmlMessageValidator validator = new DomXmlMessageValidator();229 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();230 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);231 return null;232 }233 }).when(producer).send(any(Message.class), any(TestContext.class));234 when(endpoint.getActor()).thenReturn(null);235 236 sendAction.execute(context);237 }238 239 @Test240 @SuppressWarnings("rawtypes")241 public void testSendMessageWithMessagePayloadResourceVariablesSupport() {242 SendMessageAction sendAction = new SendMessageAction();243 sendAction.setEndpoint(endpoint);244 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();245 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload-with-variables.xml");246 247 sendAction.setMessageBuilder(messageBuilder);248 249 context.setVariable("myText", "Hello World!");250 251 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");252 reset(endpoint, producer, endpointConfiguration);253 when(endpoint.createProducer()).thenReturn(producer);254 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);255 doAnswer(new Answer() {256 @Override257 public Object answer(InvocationOnMock invocation) throws Throwable {258 DomXmlMessageValidator validator = new DomXmlMessageValidator();259 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();260 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);261 return null;262 }263 }).when(producer).send(any(Message.class), any(TestContext.class));264 when(endpoint.getActor()).thenReturn(null);265 266 sendAction.execute(context);267 }268 269 @Test270 @SuppressWarnings("rawtypes")271 public void testSendMessageWithMessagePayloadResourceFunctionsSupport() {272 SendMessageAction sendAction = new SendMessageAction();273 sendAction.setEndpoint(endpoint);274 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();275 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload-with-functions.xml");276 277 sendAction.setMessageBuilder(messageBuilder);278 279 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");280 reset(endpoint, producer, endpointConfiguration);281 when(endpoint.createProducer()).thenReturn(producer);282 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);283 doAnswer(new Answer() {284 @Override285 public Object answer(InvocationOnMock invocation) throws Throwable {286 DomXmlMessageValidator validator = new DomXmlMessageValidator();287 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();288 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);289 return null;290 }291 }).when(producer).send(any(Message.class), any(TestContext.class));292 when(endpoint.getActor()).thenReturn(null);293 294 sendAction.execute(context);295 }296 297 @Test298 @SuppressWarnings("rawtypes")299 public void testSendMessageOverwriteMessageElementsXPath() {300 SendMessageAction sendAction = new SendMessageAction();301 sendAction.setEndpoint(endpoint);302 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();303 messageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>");304 305 Map<String, String> overwriteElements = new HashMap<String, String>();306 overwriteElements.put("/TestRequest/Message", "Hello World!");307 308 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);309 messageBuilder.add(interceptor);310 311 sendAction.setMessageBuilder(messageBuilder);312 313 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");314 reset(endpoint, producer, endpointConfiguration);315 when(endpoint.createProducer()).thenReturn(producer);316 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);317 doAnswer(new Answer() {318 @Override319 public Object answer(InvocationOnMock invocation) throws Throwable {320 DomXmlMessageValidator validator = new DomXmlMessageValidator();321 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();322 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);323 return null;324 }325 }).when(producer).send(any(Message.class), any(TestContext.class));326 when(endpoint.getActor()).thenReturn(null);327 328 sendAction.execute(context);329 }330 @Test331 @SuppressWarnings("rawtypes")332 public void testSendMessageOverwriteMessageElementsJsonPath() {333 SendMessageAction sendAction = new SendMessageAction();334 sendAction.setMessageType(MessageType.JSON.toString());335 sendAction.setEndpoint(endpoint);336 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();337 messageBuilder.setPayloadData("{ \"TestRequest\": { \"Message\": \"?\" }}");338 Map<String, String> overwriteElements = new HashMap<String, String>();339 overwriteElements.put("$.TestRequest.Message", "Hello World!");340 JsonPathMessageConstructionInterceptor interceptor = new JsonPathMessageConstructionInterceptor(overwriteElements);341 messageBuilder.add(interceptor);342 sendAction.setMessageBuilder(messageBuilder);343 final Message controlMessage = new DefaultMessage("{ \"TestRequest\": { \"Message\": \"Hello World!\" }}");344 reset(endpoint, producer, endpointConfiguration);345 when(endpoint.createProducer()).thenReturn(producer);346 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);347 doAnswer(new Answer() {348 @Override349 public Object answer(InvocationOnMock invocation) throws Throwable {350 JsonTextMessageValidator validator = new JsonTextMessageValidator();351 JsonMessageValidationContext validationContext = new JsonMessageValidationContext();352 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);353 return null;354 }355 }).when(producer).send(any(Message.class), any(TestContext.class));356 when(endpoint.getActor()).thenReturn(null);357 sendAction.execute(context);358 }359 360 @Test361 @SuppressWarnings("rawtypes")362 public void testSendMessageOverwriteMessageElementsDotNotation() {363 SendMessageAction sendAction = new SendMessageAction();364 sendAction.setEndpoint(endpoint);365 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();366 messageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>");367 368 Map<String, String> overwriteElements = new HashMap<String, String>();369 overwriteElements.put("TestRequest.Message", "Hello World!");370 371 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);372 messageBuilder.add(interceptor);373 374 sendAction.setMessageBuilder(messageBuilder);375 376 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");377 reset(endpoint, producer, endpointConfiguration);378 when(endpoint.createProducer()).thenReturn(producer);379 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);380 doAnswer(new Answer() {381 @Override382 public Object answer(InvocationOnMock invocation) throws Throwable {383 DomXmlMessageValidator validator = new DomXmlMessageValidator();384 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();385 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);386 return null;387 }388 }).when(producer).send(any(Message.class), any(TestContext.class));389 when(endpoint.getActor()).thenReturn(null);390 391 sendAction.execute(context);392 }393 394 @Test395 @SuppressWarnings("rawtypes")396 public void testSendMessageOverwriteMessageElementsXPathWithNamespace() {397 SendMessageAction sendAction = new SendMessageAction();398 sendAction.setEndpoint(endpoint);399 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();400 messageBuilder.setPayloadData("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +401 "<ns0:Message>?</ns0:Message></ns0:TestRequest>");402 403 Map<String, String> overwriteElements = new HashMap<String, String>();404 overwriteElements.put("/ns0:TestRequest/ns0:Message", "Hello World!");405 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);406 messageBuilder.add(interceptor);407 408 sendAction.setMessageBuilder(messageBuilder);409 410 final Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\"><ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");411 reset(endpoint, producer, endpointConfiguration);412 when(endpoint.createProducer()).thenReturn(producer);413 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);414 doAnswer(new Answer() {415 @Override416 public Object answer(InvocationOnMock invocation) throws Throwable {417 DomXmlMessageValidator validator = new DomXmlMessageValidator();418 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();419 validationContext.setSchemaValidation(false);420 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);421 return null;422 }423 }).when(producer).send(any(Message.class), any(TestContext.class));424 when(endpoint.getActor()).thenReturn(null);425 426 sendAction.execute(context);427 }428 429 @Test430 @SuppressWarnings("rawtypes")431 public void testSendMessageOverwriteMessageElementsXPathWithDefaultNamespace() {432 SendMessageAction sendAction = new SendMessageAction();433 sendAction.setEndpoint(endpoint);434 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();435 messageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +436 "<Message>?</Message></TestRequest>");437 438 Map<String, String> overwriteElements = new HashMap<String, String>();439 overwriteElements.put("/:TestRequest/:Message", "Hello World!");440 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);441 messageBuilder.add(interceptor);442 443 sendAction.setMessageBuilder(messageBuilder);444 445 final Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\"><Message>Hello World!</Message></TestRequest>");446 reset(endpoint, producer, endpointConfiguration);447 when(endpoint.createProducer()).thenReturn(producer);448 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);449 doAnswer(new Answer() {450 @Override451 public Object answer(InvocationOnMock invocation) throws Throwable {452 DomXmlMessageValidator validator = new DomXmlMessageValidator();453 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();454 validationContext.setSchemaValidation(false);455 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);456 return null;457 }458 }).when(producer).send(any(Message.class), any(TestContext.class));459 when(endpoint.getActor()).thenReturn(null);460 461 sendAction.execute(context);462 }463 464 @Test465 @SuppressWarnings("rawtypes")466 public void testSendMessageWithMessageHeaders() {467 SendMessageAction sendAction = new SendMessageAction();468 sendAction.setEndpoint(endpoint);469 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();470 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");471 472 final Map<String, Object> controlHeaders = new HashMap<String, Object>();473 controlHeaders.put("Operation", "sayHello");474 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);475 final Map<String, Object> headers = new HashMap<String, Object>();476 headers.put("Operation", "sayHello");477 messageBuilder.setMessageHeaders(headers);478 479 sendAction.setMessageBuilder(messageBuilder);480 reset(endpoint, producer, endpointConfiguration);481 when(endpoint.createProducer()).thenReturn(producer);482 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);483 doAnswer(new Answer() {484 @Override485 public Object answer(InvocationOnMock invocation) throws Throwable {486 DomXmlMessageValidator validator = new DomXmlMessageValidator();487 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();488 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);489 return null;490 }491 }).when(producer).send(any(Message.class), any(TestContext.class));492 when(endpoint.getActor()).thenReturn(null);493 494 sendAction.execute(context);495 }496 497 @Test498 @SuppressWarnings("rawtypes")499 public void testSendMessageWithHeaderValuesVariableSupport() {500 SendMessageAction sendAction = new SendMessageAction();501 sendAction.setEndpoint(endpoint);502 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();503 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");504 505 context.setVariable("myOperation", "sayHello");506 507 final Map<String, Object> controlHeaders = new HashMap<String, Object>();508 controlHeaders.put("Operation", "sayHello");509 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);510 final Map<String, Object> headers = new HashMap<String, Object>();511 headers.put("Operation", "${myOperation}");512 messageBuilder.setMessageHeaders(headers);513 514 sendAction.setMessageBuilder(messageBuilder);515 reset(endpoint, producer, endpointConfiguration);516 when(endpoint.createProducer()).thenReturn(producer);517 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);518 doAnswer(new Answer() {519 @Override520 public Object answer(InvocationOnMock invocation) throws Throwable {521 DomXmlMessageValidator validator = new DomXmlMessageValidator();522 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();523 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);524 return null;525 }526 }).when(producer).send(any(Message.class), any(TestContext.class));527 when(endpoint.getActor()).thenReturn(null);528 529 sendAction.execute(context);530 }531 532 @Test533 public void testSendMessageWithUnknwonVariableInMessagePayload() {534 SendMessageAction sendAction = new SendMessageAction();535 sendAction.setEndpoint(endpoint);536 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();537 messageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");538 539 sendAction.setMessageBuilder(messageBuilder);540 reset(endpoint, producer, endpointConfiguration);541 when(endpoint.createProducer()).thenReturn(producer);542 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);543 when(endpoint.getActor()).thenReturn(null);544 545 try {546 sendAction.execute(context);547 } catch(CitrusRuntimeException e) {548 Assert.assertEquals(e.getMessage(), "Unknown variable 'myText'");549 return;550 }551 552 Assert.fail("Missing " + CitrusRuntimeException.class + " with unknown variable error message");553 }554 555 @Test556 public void testSendMessageWithUnknwonVariableInHeaders() {557 SendMessageAction sendAction = new SendMessageAction();558 sendAction.setEndpoint(endpoint);559 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();560 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");561 562 final Map<String, Object> headers = new HashMap<String, Object>();563 headers.put("Operation", "${myOperation}");564 messageBuilder.setMessageHeaders(headers);565 566 sendAction.setMessageBuilder(messageBuilder);567 reset(endpoint, producer, endpointConfiguration);568 when(endpoint.createProducer()).thenReturn(producer);569 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);570 when(endpoint.getActor()).thenReturn(null);571 572 try {573 sendAction.execute(context);574 } catch(CitrusRuntimeException e) {575 Assert.assertEquals(e.getMessage(), "Unknown variable 'myOperation'");576 return;577 }578 579 Assert.fail("Missing " + CitrusRuntimeException.class + " with unknown variable error message");580 }581 582 @Test583 @SuppressWarnings("rawtypes")584 public void testSendMessageWithExtractHeaderValues() {585 SendMessageAction sendAction = new SendMessageAction();586 sendAction.setEndpoint(endpoint);587 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();588 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");589 590 final Map<String, Object> controlHeaders = new HashMap<String, Object>();591 controlHeaders.put("Operation", "sayHello");592 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);593 final Map<String, Object> headers = new HashMap<String, Object>();594 headers.put("Operation", "sayHello");595 messageBuilder.setMessageHeaders(headers);596 597 sendAction.setMessageBuilder(messageBuilder);598 599 Map<String, String> extractVars = new HashMap<String, String>();600 extractVars.put("Operation", "myOperation");601 extractVars.put(MessageHeaders.ID, "correlationId");602 603 List<VariableExtractor> variableExtractors = new ArrayList<VariableExtractor>();604 MessageHeaderVariableExtractor variableExtractor = new MessageHeaderVariableExtractor();605 variableExtractor.setHeaderMappings(extractVars);606 607 variableExtractors.add(variableExtractor);608 sendAction.setVariableExtractors(variableExtractors);609 reset(endpoint, producer, endpointConfiguration);610 when(endpoint.createProducer()).thenReturn(producer);611 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);612 doAnswer(new Answer() {613 @Override614 public Object answer(InvocationOnMock invocation) throws Throwable {615 DomXmlMessageValidator validator = new DomXmlMessageValidator();616 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();617 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);618 return null;619 }620 }).when(producer).send(any(Message.class), any(TestContext.class));621 when(endpoint.getActor()).thenReturn(null);622 623 sendAction.execute(context);624 625 Assert.assertNotNull(context.getVariable("myOperation"));626 Assert.assertNotNull(context.getVariable("correlationId"));627 }628 629 @Test630 @SuppressWarnings("rawtypes")631 public void testMissingMessagePayload() {632 SendMessageAction sendAction = new SendMessageAction();633 sendAction.setEndpoint(endpoint);634 reset(endpoint, producer, endpointConfiguration);635 when(endpoint.createProducer()).thenReturn(producer);636 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);637 doAnswer(new Answer() {638 @Override639 public Object answer(InvocationOnMock invocation) throws Throwable {640 DomXmlMessageValidator validator = new DomXmlMessageValidator();641 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();642 validator.validateMessage(((Message)invocation.getArguments()[0]), new DefaultMessage(""), context, validationContext);643 return null;644 }645 }).when(producer).send(any(Message.class), any(TestContext.class));646 when(endpoint.getActor()).thenReturn(null);647 648 sendAction.execute(context);649 }650 651 @Test652 @SuppressWarnings("rawtypes")653 public void testSendMessageWithXmlDeclaration() {654 SendMessageAction sendAction = new SendMessageAction();655 sendAction.setEndpoint(endpoint);656 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();657 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");658 659 sendAction.setMessageBuilder(messageBuilder);660 661 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");662 reset(endpoint, producer, endpointConfiguration);663 when(endpoint.createProducer()).thenReturn(producer);664 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);665 doAnswer(new Answer() {666 @Override667 public Object answer(InvocationOnMock invocation) throws Throwable {668 DomXmlMessageValidator validator = new DomXmlMessageValidator();669 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();670 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);671 return null;672 }673 }).when(producer).send(any(Message.class), any(TestContext.class));674 when(endpoint.getActor()).thenReturn(null);675 676 sendAction.execute(context);677 }678 679 @Test680 @SuppressWarnings("rawtypes")681 public void testSendMessageWithUTF16Encoding() {682 SendMessageAction sendAction = new SendMessageAction();683 sendAction.setEndpoint(endpoint);684 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();685 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"UTF-16\"?><TestRequest><Message>Hello World!</Message></TestRequest>");686 687 sendAction.setMessageBuilder(messageBuilder);688 689 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-16\"?><TestRequest><Message>Hello World!</Message></TestRequest>");690 reset(endpoint, producer, endpointConfiguration);691 when(endpoint.createProducer()).thenReturn(producer);692 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);693 doAnswer(new Answer() {694 @Override695 public Object answer(InvocationOnMock invocation) throws Throwable {696 DomXmlMessageValidator validator = new DomXmlMessageValidator();697 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();698 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);699 return null;700 }701 }).when(producer).send(any(Message.class), any(TestContext.class));702 when(endpoint.getActor()).thenReturn(null);703 704 sendAction.execute(context);705 }706 707 @Test708 @SuppressWarnings("rawtypes")709 public void testSendMessageWithISOEncoding() {710 SendMessageAction sendAction = new SendMessageAction();711 sendAction.setEndpoint(endpoint);712 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();713 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");714 715 sendAction.setMessageBuilder(messageBuilder);716 717 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");718 reset(endpoint, producer, endpointConfiguration);719 when(endpoint.createProducer()).thenReturn(producer);720 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);721 doAnswer(new Answer() {722 @Override723 public Object answer(InvocationOnMock invocation) throws Throwable {724 DomXmlMessageValidator validator = new DomXmlMessageValidator();725 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();726 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);727 return null;728 }729 }).when(producer).send(any(Message.class), any(TestContext.class));730 when(endpoint.getActor()).thenReturn(null);731 732 sendAction.execute(context);733 }734 735 @Test736 @SuppressWarnings("rawtypes")737 public void testSendMessageWithUnsupportedEncoding() {738 SendMessageAction sendAction = new SendMessageAction();739 sendAction.setEndpoint(endpoint);740 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();741 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"MyUnsupportedEncoding\"?><TestRequest><Message>Hello World!</Message></TestRequest>");742 743 sendAction.setMessageBuilder(messageBuilder);744 reset(endpoint, producer, endpointConfiguration);745 when(endpoint.createProducer()).thenReturn(producer);746 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);747 when(endpoint.getActor()).thenReturn(null);748 try {749 sendAction.execute(context);750 } catch (CitrusRuntimeException e) {751 Assert.assertTrue(e.getCause() instanceof UnsupportedEncodingException);752 }753 verify(producer).send(any(Message.class), any(TestContext.class));754 }755 @Test756 @SuppressWarnings("rawtypes")757 public void testSendMessageWithMessagePayloadResourceISOEncoding() {758 SendMessageAction sendAction = new SendMessageAction();759 sendAction.setEndpoint(endpoint);760 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();761 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-iso-encoding.xml");762 763 sendAction.setMessageBuilder(messageBuilder);764 765 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");766 reset(endpoint, producer, endpointConfiguration);767 when(endpoint.createProducer()).thenReturn(producer);768 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);769 doAnswer(new Answer() {770 @Override771 public Object answer(InvocationOnMock invocation) throws Throwable {772 DomXmlMessageValidator validator = new DomXmlMessageValidator();773 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();774 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);775 return null;776 }777 }).when(producer).send(any(Message.class), any(TestContext.class));778 when(endpoint.getActor()).thenReturn(null);779 780 sendAction.execute(context);781 }782 783 @Test784 public void testDisabledSendMessage() {785 TestCase testCase = new TestCase();786 SendMessageAction sendAction = new SendMessageAction();787 sendAction.setEndpoint(endpoint);788 ...
Source:XhtmlMessageValidator.java
...29public class XhtmlMessageValidator extends DomXmlMessageValidator implements InitializingBean {30 /** Message converter for XHTML content */31 private XhtmlMessageConverter messageConverter = new XhtmlMessageConverter();32 @Override33 public void validateMessage(Message receivedMessage, Message controlMessage,34 TestContext context, XmlMessageValidationContext validationContext)35 throws ValidationException {36 37 String messagePayload = receivedMessage.getPayload(String.class);38 super.validateMessage(new DefaultMessage(messageConverter.convert(messagePayload), receivedMessage.getHeaders()),39 controlMessage, context, validationContext);40 }41 42 @Override43 public boolean supportsMessageType(String messageType, Message message) {44 return super.supportsMessageType(MessageType.XML.name(), message)45 && messageType.equalsIgnoreCase(MessageType.XHTML.name());46 }47 @Override48 public void afterPropertiesSet() throws Exception {49 messageConverter.initialize();50 }51 /**52 * Sets the messageConverter property....
validateMessage
Using AI Code Generation
1package com.consol.citrus.validation.xml;2import com.consol.citrus.exceptions.CitrusRuntimeException;3import com.consol.citrus.message.Message;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.MessageValidator;6import com.consol.citrus.validation.MessageValidatorContext;7import com.consol.citrus.validation.context.ValidationContext;8import com.consol.citrus.validation.xml.XmlMessageValidationContext;9import com.consol.citrus.xml.namespace.NamespaceContextBuilder;10import com.consol.citrus.xml.schema.XsdSchemaRepository;11import org.springframework.util.xml.SimpleNamespaceContext;12import org.springframework.xml.validation.XmlValidator;13import org.springframework.xml.xsd.SimpleXsdSchema;14import org.springframework.xml.xsd.XsdSchema;15import org.springframework.xml.xsd.XsdSchemaCollection;16import org.springframework.xml.xsd.XsdSchemaCollectionFactoryBean;17import org.springframework.xml.xsd.XsdSchemaFactoryBean;18import org.springframework.xml.xsd.XsdSchemaLocator;19import org.springframework.xml.xsd.XsdSchemaResolver;20import org.springframework.xml.xsd.XsdSchemaValidationUtils;21import org.springframework.xml.xsd.XsdSchemaValidationUtils.ValidationType;22import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;23import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionFactoryBean;24import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader;25import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader.SchemaReader;26import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader.SchemaReaderCallback;27import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader.SchemaReaderCallbackFactory;28import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader.SchemaReaderCallbackFactoryBean;29import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader.SchemaReaderCallbackFactoryBean.SchemaReaderCallbackType;30import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader.SchemaReaderFactory;31import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader.SchemaReaderFactoryBean;32import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollectionReader.SchemaReaderType;33import org.springframework.xml.xsd.commons.CommonsXsdSchemaFactoryBean;34import org.springframework.xml.xsd.commons.CommonsXsdSchemaLocator;35import org.springframework.xml.xsd.commons.CommonsXsdSchemaResolver;36import org.springframework.xml.xsd.commons.CommonsXsdSchemaResolver.SchemaResolver
validateMessage
Using AI Code Generation
1package com.consol.citrus.validation.xml;2import org.springframework.util.xml.DomUtils;3import org.w3c.dom.Document;4import org.w3c.dom.Node;5import org.w3c.dom.NodeList;6import org.xml.sax.SAXException;7import javax.xml.parsers.DocumentBuilder;8import javax.xml.parsers.DocumentBuilderFactory;9import javax.xml.parsers.ParserConfigurationException;10import java.io.IOException;11import java.util.ArrayList;12import java.util.List;13public class DomXmlMessageValidator {14 public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {15 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();16 factory.setNamespaceAware(true);17 DocumentBuilder builder = factory.newDocumentBuilder();18 Document document = builder.parse("C:\\Users\\surya\\Desktop\\soap.xml");19 NodeList nodes = document.getElementsByTagName("ns2:Body");20 Node node = nodes.item(0);21 List<XmlValidationMessage> list = new ArrayList<XmlValidationMessage>();22 list.add(new XmlValidationMessage("ns2:Body", "ns2:Body"));23 list.add(new XmlValidationMessage("ns2:Body/ns2:Fault", "ns2:Body/ns2:Fault"));24 list.add(new XmlValidationMessage("ns2:Body/ns2:Fault/faultcode", "ns2:Body/ns2:Fault/faultcode"));25 list.add(new XmlValidationMessage("ns2:Body/ns2:Fault/faultstring", "ns2:Body/ns2:Fault/faultstring"));26 list.add(new XmlValidationMessage("ns2:Body/ns2:Fault/detail", "ns2:Body/ns2:Fault/detail"));27 list.add(new XmlValidationMessage("ns2:Body/ns2:Fault/detail/ns2:Error", "ns2:Body/ns2:Fault/detail/ns2:Error"));28 list.add(new XmlValidationMessage("ns2:Body/ns2:Fault/detail/ns2:Error/ns2:Code", "ns2:Body/ns2:Fault/detail/ns2:Error/ns2:Code"));29 list.add(new XmlValidationMessage("ns2:Body/ns2:Fault/detail/ns2:Error/ns2:Message", "ns2:Body/ns2:Fault/detail/ns2:Error/ns2:Message"));30 list.add(new XmlValidationMessage("ns2:Body/ns2:Fault/detail/ns2:Error/ns2:Message", "ns2:Body/ns2:Fault
validateMessage
Using AI Code Generation
1public class 4 {2 public static void main(String[] args) {3 DomXmlMessageValidator validator = new DomXmlMessageValidator();4 validator.validateMessage(new StringMessage(xml), new StringMessage(controlXml), new MessageValidationContext());5 }6}7public class 5 {8 public static void main(String[] args) {9 DomXmlMessageValidator validator = new DomXmlMessageValidator();10 validator.validateMessage(new StringMessage(xml), new StringMessage(controlXml), new MessageValidationContext());11 }12}13public class 6 {14 public static void main(String[] args) {15 DomXmlMessageValidator validator = new DomXmlMessageValidator();16 validator.validateMessage(new StringMessage(xml), new StringMessage(controlXml), new MessageValidationContext());17 }18}
validateMessage
Using AI Code Generation
1public class 4 {2 public static void main(String[] args) {3 DomXmlMessageValidator validator = new DomXmlMessageValidator();4 validator.validateMessage(new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"), new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"));5 }6}7public class 5 {8 public static void main(String[] args) {9 DomXmlMessageValidator validator = new DomXmlMessageValidator();10 validator.validateMessage(new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"), new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"));11 }12}13public class 6 {14 public static void main(String[] args) {15 DomXmlMessageValidator validator = new DomXmlMessageValidator();16 validator.validateMessage(new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"), new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"));17 }18}19public class 7 {20 public static void main(String[] args) {21 DomXmlMessageValidator validator = new DomXmlMessageValidator();22 validator.validateMessage(new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"), new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"));23 }24}25public class 8 {26 public static void main(String[] args) {27 DomXmlMessageValidator validator = new DomXmlMessageValidator();28 validator.validateMessage(new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"), new StringSource("<testMessage><text>Hello Citrus!</text></testMessage>"));29 }30}
validateMessage
Using AI Code Generation
1package com.consol.citrus.samples;2import java.io.File;3import org.springframework.context.support.ClassPathXmlApplicationContext;4import org.springframework.core.io.ClassPathResource;5import org.testng.annotations.Test;6import com.consol.citrus.context.TestContext;7import com.consol.citrus.context.TestContextFactory;8import com.consol.citrus.exceptions.ValidationException;9import com.consol.citrus.message.Message;10import com.consol.citrus.message.MessageType;11import com.consol.citrus.validation.xml.DomXmlMessageValidator;12import com.consol.citrus.xml.XsdSchemaRepository;13public class Test4 {14 public void test4() {15 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");16 TestContextFactory testContextFactory = context.getBean(TestContextFactory.class);17 TestContext testContext = testContextFactory.getObject();18 DomXmlMessageValidator validator = new DomXmlMessageValidator();19 validator.setSchemaRepository(new XsdSchemaRepository(new ClassPathResource("person.xsd")));20 validator.validateMessage(message, new ClassPathResource("person.xsd"), testContext);21 }22}
validateMessage
Using AI Code Generation
1package com.consol.citrus.samples;2import java.io.IOException;3import java.util.HashMap;4import java.util.Map;5import org.springframework.context.ApplicationContext;6import org.springframework.context.support.ClassPathXmlApplicationContext;7import org.springframework.core.io.ClassPathResource;8import org.springframework.xml.xsd.SimpleXsdSchema;9import org.springframework.xml.xsd.XsdSchema;10import org.testng.annotations.Test;11import com.consol.citrus.context.TestContext;12import com.consol.citrus.context.TestContextFactory;13import com.consol.citrus.dsl.builder.BuilderSupport;14import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;15import com.consol.citrus.dsl.builder.SendMessageActionBuilder;16import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;17import com.consol.citrus.message.MessageType;18import com.consol.citrus.testng.CitrusParameters;19import com.consol.citrus.validation.xml.DomXmlMessageValidator;20import com.consol.citrus.validation.xml.XmlMessageValidationContext;21public class ValidateMessage extends TestNGCitrusTestRunner {22 @CitrusParameters({"requestMessage", "responseMessage"})23 public void validateMessage(String requestMessage, String responseMessage) {24 TestContextFactory contextFactory = new TestContextFactory();25 TestContext context = contextFactory.getObject();26 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();27 XsdSchema schema = new SimpleXsdSchema(new ClassPathResource("schema.xsd"));28 validationContext.setSchema(schema);29 DomXmlMessageValidator validator = new DomXmlMessageValidator();30 validator.setValidationContext(validationContext);31 Map<String, BuilderSupport<ReceiveMessageActionBuilder.ReceiveMessageAction>> receiveMessageBuilder = new HashMap<String, BuilderSupport<ReceiveMessageActionBuilder.ReceiveMessageAction>>();32 receiveMessageBuilder.put(requestMessage, receive(builder -> builder.validator(validator)));
validateMessage
Using AI Code Generation
1import org.springframework.context.support.ClassPathXmlApplicationContext;2import org.springframework.context.ApplicationContext;3import org.consol.citrus.context.TestContext;4import org.consol.citrus.context.TestContextFactory;5import org.consol.citrus.message.Message;6import org.consol.citrus.message.MessageType;7import org.consol.citrus.message.DefaultMessage;8import org.consol.citrus.message.MessageBuilder;9import org.consol.citrus.validation.xml.DomXmlMessageValidator;10import org.consol.citrus.validation.xml.XmlMessageValidationContext;11import org.consol.citrus.exceptions.ValidationException;12import org.consol.citrus.context.TestContext;13import org.consol.citrus.context.TestContextFactory;14import org.consol.citrus.message.Message;15import org.consol.citrus.message.MessageType;16import org.consol.citrus.message.DefaultMessage;17import org.consol.citrus.message.MessageBuilder;18import org.consol.citrus.validation.xml.DomXmlMessageValidator;19import org.consol.citrus.exceptions.ValidationException;20import org.consol.citrus.context.TestContext;21import org.consol.citrus.context.TestContextFactory;22import org.consol.citrus.message.Message;23import org.consol.citrus.message.MessageType;24import org.consol.citrus.message.DefaultMessage;25import org.consol.citrus.message.MessageBuilder;26import org.consol.citrus.validation.xml.DomXmlMessageValidator;27import org.consol.citrus.exceptions.ValidationException;28import org.consol.citrus.context.TestContext;29import org.consol.citrus.context.TestContextFactory;30import org.consol.citrus.message.Message;31import org.consol.citrus.message.MessageType;32import org.consol.citrus.message.DefaultMessage;33import org.consol.citrus.message.MessageBuilder;34import org.consol.citrus.validation.xml.DomXmlMessageValidator;35import org.consol.citrus.exceptions.ValidationException;36import org.consol.citrus.context.TestContext;37import org.consol.citrus.context.TestContextFactory;38import org.consol.citrus.message.Message;39import org.consol.citrus.message.MessageType;40import org.consol.citrus.message.DefaultMessage;41import org.consol.citrus.message.MessageBuilder;42import org.consol.citrus.validation.xml.DomXmlMessageValidator;43import org.con
validateMessage
Using AI Code Generation
1 @CitrusParameters({"requestMessage", "responseMessage"})2 public void validateMessage(String requestMessage, String responseMessage) {3 TestContextFactory contextFactory = new TestContextFactory();4 TestContext context = contextFactory.getObject();5 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();6 XsdSchema schema = new SimpleXsdSchema(new ClassPathResource("schema.xsd"));7 validationContext.setSchema(schema);8 DomXmlMessageValidator validator = new DomXmlMessageValidator();9 validator.setValidationContext(validationContext);10 Map<String, BuilderSupport<ReceiveMessageActionBuilder.ReceiveMessageAction>> receiveMessageBuilder = new HashMap<String, BuilderSupport<ReceiveMessageActionBuilder.ReceiveMessageAction>>();11 receiveMessageBuilder.put(requestMessage, receive(builder -> builder.validator(validator)));
validateMessage
Using AI Code Generation
1package com.consol.citrus.samples;2import java.io.File;3import org.springframework.context.support.ClassPathXmlApplicationContext;4import org.springframework.core.io.ClassPathResource;5import org.testng.annotations.Test;6import com.consol.citrus.context.TestContext;7import com.consol.citrus.context.TestContextFactory;8import com.consol.citrus.exceptions.ValidationException;9import com.consol.citrus.message.Message;10import com.consol.citrus.message.MessageType;11import com.consol.citrus.validation.xml.DomXmlMessageValidator;12import com.consol.citrus.xml.XsdSchemaRepository;13public class Test4 {14 public void test4() {15 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");16 TestContextFactory testContextFactory = context.getBean(TestContextFactory.class);17 TestContext testContext = testContextFactory.getObject();18 DomXmlMessageValidator validator = new DomXmlMessageValidator();19 validator.setSchemaRepository(new XsdSchemaRepository(new ClassPathResource("person.xsd")));20 validator.validateMessage(message, new ClassPathResource("person.xsd"), testContext);21 }22}
validateMessage
Using AI Code Generation
1package com.consol.citrus.samples;2import java.io.IOException;3import java.util.HashMap;4import java.util.Map;5import org.springframework.context.ApplicationContext;6import org.springframework.context.support.ClassPathXmlApplicationContext;7import org.springframework.core.io.ClassPathResource;8import org.springframework.xml.xsd.SimpleXsdSchema;9import org.springframework.xml.xsd.XsdSchema;10import org.testng.annotations.Test;11import com.consol.citrus.context.TestContext;12import com.consol.citrus.context.TestContextFactory;13import com.consol.citrus.dsl.builder.BuilderSupport;14import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;15import com.consol.citrus.dsl.builder.SendMessageActionBuilder;16import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;17import com.consol.citrus.message.MessageType;18import com.consol.citrus.testng.CitrusParameters;19import com.consol.citrus.validation.xml.DomXmlMessageValidator;20import com.consol.citrus.validation.xml.XmlMessageValidationContext;21public class ValidateMessage extends TestNGCitrusTestRunner {22 @CitrusParameters({"requestMessage", "responseMessage"})23 public void validateMessage(String requestMessage, String responseMessage) {24 TestContextFactory contextFactory = new TestContextFactory();25 TestContext context = contextFactory.getObject();26 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();27 XsdSchema schema = new SimpleXsdSchema(new ClassPathResource("schema.xsd"));28 validationContext.setSchema(schema);29 DomXmlMessageValidator validator = new DomXmlMessageValidator();30 validator.setValidationContext(validationContext);31 Map<String, BuilderSupport<ReceiveMessageActionBuilder.ReceiveMessageAction>> receiveMessageBuilder = new HashMap<String, BuilderSupport<ReceiveMessageActionBuilder.ReceiveMessageAction>>();32 receiveMessageBuilder.put(requestMessage, receive(builder -> builder.validator(validator)));
validateMessage
Using AI Code Generation
1import org.springframework.context.support.ClassPathXmlApplicationContext;2import org.springframework.context.ApplicationContext;3import org.consol.citrus.context.TestContext;4import org.consol.citrus.context.TestContextFactory;5import org.consol.citrus.message.Message;6import org.consol.citrus.message.MessageType;7import org.consol.citrus.message.DefaultMessage;8import org.consol.citrus.message.MessageBuilder;9import org.consol.citrus.validation.xml.DomXmlMessageValidator;10import org.consol.citrus.validation.xml.XmlMessageValidationContext;11import org.consol.citrus.exceptions.ValidationException;12import org.consol.citrus.context.TestContext;13import org.consol.citrus.context.TestContextFactory;14import org.consol.citrus.message.Message;15import org.consol.citrus.message.MessageType;16import org.consol.citrus.message.DefaultMessage;17import org.consol.citrus.message.MessageBuilder;18import org.consol.citrus.validation.xml.DomXmlMessageValidator;19import org.consol.citrus.exceptions.ValidationException;20import org.consol.citrus.context.TestContext;21import org.consol.citrus.context.TestContextFactory;22import org.consol.citrus.message.Message;23import org.consol.citrus.message.MessageType;24import org.consol.citrus.message.DefaultMessage;25import org.consol.citrus.message.MessageBuilder;26import org.consol.citrus.validation.xml.DomXmlMessageValidator;27import org.consol.citrus.exceptions.ValidationException;28import org.consol.citrus.context.TestContext;29import org.consol.citrus.context.TestContextFactory;30import org.consol.citrus.message.Message;31import org.consol.citrus.message.MessageType;32import org.consol.citrus.message.DefaultMessage;33import org.consol.citrus.message.MessageBuilder;34import org.consol.citrus.validation.xml.DomXmlMessageValidator;35import org.consol.citrus.exceptions.ValidationException;36import org.consol.citrus.context.TestContext;37import org.consol.citrus.context.TestContextFactory;38import org.consol.citrus.message.Message;39import org.consol.citrus.message.MessageType;40import org.consol.citrus.message.DefaultMessage;41import org.consol.citrus.message.MessageBuilder;42import org.consol.citrus.validation.xml.DomXmlMessageValidator;43import org.con
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!