How to use setControlNamespaces method of com.consol.citrus.validation.xml.XmlMessageValidationContext class

Best Citrus code snippet using com.consol.citrus.validation.xml.XmlMessageValidationContext.setControlNamespaces

Source:NamespaceTest.java Github

copy

Full Screen

...385 386 Map<String, String> expectedNamespaces = new HashMap<String, String>();387 expectedNamespaces.put("", "http://citrus");388 389 validationContext.setControlNamespaces(expectedNamespaces);390 391 validationContext.setSchemaValidation(false);392 393 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();394 validationContexts.add(validationContext);395 receiveMessageBean.setValidationContexts(validationContexts);396 receiveMessageBean.execute(context);397 }398 399 @Test400 @SuppressWarnings({ "unchecked", "rawtypes" })401 public void testExpectNamespace() {402 reset(endpoint, consumer, endpointConfiguration);403 when(endpoint.createConsumer()).thenReturn(consumer);404 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);405 when(endpointConfiguration.getTimeout()).thenReturn(5000L);406 407 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus/ns1'>"408 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"409 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"410 + "</ns1:element>" 411 + "</ns1:root>");412 413 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);414 when(endpoint.getActor()).thenReturn(null);415 416 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();417 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();418 receiveMessageBean.setMessageBuilder(controlMessageBuilder);419 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus/ns1'>"420 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"421 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"422 + "</ns1:element>" 423 + "</ns1:root>");424 425 Map<String, String> expectedNamespaces = new HashMap<String, String>();426 expectedNamespaces.put("ns1", "http://citrus/ns1");427 428 validationContext.setControlNamespaces(expectedNamespaces);429 430 validationContext.setSchemaValidation(false);431 432 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();433 validationContexts.add(validationContext);434 receiveMessageBean.setValidationContexts(validationContexts);435 receiveMessageBean.execute(context);436 }437 438 @Test439 @SuppressWarnings({ "unchecked", "rawtypes" })440 public void testExpectMixedNamespaces() {441 reset(endpoint, consumer, endpointConfiguration);442 when(endpoint.createConsumer()).thenReturn(consumer);443 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);444 when(endpointConfiguration.getTimeout()).thenReturn(5000L);445 446 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1'>"447 + "<element attributeA='attribute-value' attributeB='attribute-value'>"448 + "<sub-element attribute='A'>text-value</sub-element>"449 + "</element>" 450 + "</root>");451 452 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);453 when(endpoint.getActor()).thenReturn(null);454 455 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();456 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();457 receiveMessageBean.setMessageBuilder(controlMessageBuilder);458 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1'>"459 + "<element attributeA='attribute-value' attributeB='attribute-value'>"460 + "<sub-element attribute='A'>text-value</sub-element>"461 + "</element>" 462 + "</root>");463 464 Map<String, String> expectedNamespaces = new HashMap<String, String>();465 expectedNamespaces.put("", "http://citrus/default");466 expectedNamespaces.put("ns1", "http://citrus/ns1");467 468 validationContext.setControlNamespaces(expectedNamespaces);469 470 validationContext.setSchemaValidation(false);471 472 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();473 validationContexts.add(validationContext);474 receiveMessageBean.setValidationContexts(validationContexts);475 receiveMessageBean.execute(context);476 }477 478 @Test479 @SuppressWarnings({ "unchecked", "rawtypes" })480 public void testExpectMultipleNamespaces() {481 reset(endpoint, consumer, endpointConfiguration);482 when(endpoint.createConsumer()).thenReturn(consumer);483 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);484 when(endpointConfiguration.getTimeout()).thenReturn(5000L);485 486 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"487 + "<element attributeA='attribute-value' attributeB='attribute-value'>"488 + "<sub-element attribute='A'>text-value</sub-element>"489 + "</element>" 490 + "</root>");491 492 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);493 when(endpoint.getActor()).thenReturn(null);494 495 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();496 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();497 receiveMessageBean.setMessageBuilder(controlMessageBuilder);498 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"499 + "<element attributeA='attribute-value' attributeB='attribute-value'>"500 + "<sub-element attribute='A'>text-value</sub-element>"501 + "</element>" 502 + "</root>");503 504 Map<String, String> expectedNamespaces = new HashMap<String, String>();505 expectedNamespaces.put("", "http://citrus/default");506 expectedNamespaces.put("ns1", "http://citrus/ns1");507 expectedNamespaces.put("ns2", "http://citrus/ns2");508 509 validationContext.setControlNamespaces(expectedNamespaces);510 511 validationContext.setSchemaValidation(false);512 513 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();514 validationContexts.add(validationContext);515 receiveMessageBean.setValidationContexts(validationContexts);516 receiveMessageBean.execute(context);517 }518 519 @Test(expectedExceptions = {ValidationException.class})520 @SuppressWarnings({ "unchecked", "rawtypes" })521 public void testExpectDefaultNamespaceError() {522 reset(endpoint, consumer, endpointConfiguration);523 when(endpoint.createConsumer()).thenReturn(consumer);524 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);525 when(endpointConfiguration.getTimeout()).thenReturn(5000L);526 527 Message message = new DefaultMessage("<root xmlns='http://citrus'>"528 + "<element attributeA='attribute-value' attributeB='attribute-value'>"529 + "<sub-element attribute='A'>text-value</sub-element>"530 + "</element>" 531 + "</root>");532 533 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);534 when(endpoint.getActor()).thenReturn(null);535 536 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();537 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();538 receiveMessageBean.setMessageBuilder(controlMessageBuilder);539 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus'>"540 + "<element attributeA='attribute-value' attributeB='attribute-value'>"541 + "<sub-element attribute='A'>text-value</sub-element>"542 + "</element>" 543 + "</root>");544 545 Map<String, String> expectedNamespaces = new HashMap<String, String>();546 expectedNamespaces.put("", "http://citrus/wrong");547 548 validationContext.setControlNamespaces(expectedNamespaces);549 550 validationContext.setSchemaValidation(false);551 552 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();553 validationContexts.add(validationContext);554 receiveMessageBean.setValidationContexts(validationContexts);555 receiveMessageBean.execute(context);556 }557 558 @Test(expectedExceptions = {ValidationException.class})559 @SuppressWarnings({ "unchecked", "rawtypes" })560 public void testExpectNamespaceError() {561 reset(endpoint, consumer, endpointConfiguration);562 when(endpoint.createConsumer()).thenReturn(consumer);563 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);564 when(endpointConfiguration.getTimeout()).thenReturn(5000L);565 566 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus/ns1'>"567 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"568 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"569 + "</ns1:element>" 570 + "</ns1:root>");571 572 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);573 when(endpoint.getActor()).thenReturn(null);574 575 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();576 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();577 receiveMessageBean.setMessageBuilder(controlMessageBuilder);578 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus/ns1'>"579 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"580 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"581 + "</ns1:element>" 582 + "</ns1:root>");583 584 Map<String, String> expectedNamespaces = new HashMap<String, String>();585 expectedNamespaces.put("ns1", "http://citrus/ns1/wrong");586 587 validationContext.setControlNamespaces(expectedNamespaces);588 589 validationContext.setSchemaValidation(false);590 591 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();592 validationContexts.add(validationContext);593 receiveMessageBean.setValidationContexts(validationContexts);594 receiveMessageBean.execute(context);595 }596 597 @Test(expectedExceptions = {ValidationException.class})598 @SuppressWarnings({ "unchecked", "rawtypes" })599 public void testExpectMixedNamespacesError() {600 reset(endpoint, consumer, endpointConfiguration);601 when(endpoint.createConsumer()).thenReturn(consumer);602 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);603 when(endpointConfiguration.getTimeout()).thenReturn(5000L);604 605 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1'>"606 + "<element attributeA='attribute-value' attributeB='attribute-value'>"607 + "<sub-element attribute='A'>text-value</sub-element>"608 + "</element>" 609 + "</root>");610 611 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);612 when(endpoint.getActor()).thenReturn(null);613 614 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();615 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();616 receiveMessageBean.setMessageBuilder(controlMessageBuilder);617 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1'>"618 + "<element attributeA='attribute-value' attributeB='attribute-value'>"619 + "<sub-element attribute='A'>text-value</sub-element>"620 + "</element>" 621 + "</root>");622 623 Map<String, String> expectedNamespaces = new HashMap<String, String>();624 expectedNamespaces.put("", "http://citrus/default/wrong");625 expectedNamespaces.put("ns1", "http://citrus/ns1");626 627 validationContext.setControlNamespaces(expectedNamespaces);628 629 validationContext.setSchemaValidation(false);630 631 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();632 validationContexts.add(validationContext);633 receiveMessageBean.setValidationContexts(validationContexts);634 receiveMessageBean.execute(context);635 }636 637 @Test(expectedExceptions = {ValidationException.class})638 @SuppressWarnings({ "unchecked", "rawtypes" })639 public void testExpectMultipleNamespacesError() {640 reset(endpoint, consumer, endpointConfiguration);641 when(endpoint.createConsumer()).thenReturn(consumer);642 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);643 when(endpointConfiguration.getTimeout()).thenReturn(5000L);644 645 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"646 + "<element attributeA='attribute-value' attributeB='attribute-value'>"647 + "<sub-element attribute='A'>text-value</sub-element>"648 + "</element>" 649 + "</root>");650 651 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);652 when(endpoint.getActor()).thenReturn(null);653 654 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();655 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();656 receiveMessageBean.setMessageBuilder(controlMessageBuilder);657 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"658 + "<element attributeA='attribute-value' attributeB='attribute-value'>"659 + "<sub-element attribute='A'>text-value</sub-element>"660 + "</element>" 661 + "</root>");662 663 Map<String, String> expectedNamespaces = new HashMap<String, String>();664 expectedNamespaces.put("", "http://citrus/default");665 expectedNamespaces.put("ns1", "http://citrus/ns1/wrong");666 expectedNamespaces.put("ns2", "http://citrus/ns2");667 668 validationContext.setControlNamespaces(expectedNamespaces);669 670 validationContext.setSchemaValidation(false);671 672 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();673 validationContexts.add(validationContext);674 receiveMessageBean.setValidationContexts(validationContexts);675 receiveMessageBean.execute(context);676 }677 678 @Test(expectedExceptions = {ValidationException.class})679 @SuppressWarnings({ "unchecked", "rawtypes" })680 public void testExpectWrongNamespacePrefix() {681 reset(endpoint, consumer, endpointConfiguration);682 when(endpoint.createConsumer()).thenReturn(consumer);683 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);684 when(endpointConfiguration.getTimeout()).thenReturn(5000L);685 686 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"687 + "<element attributeA='attribute-value' attributeB='attribute-value'>"688 + "<sub-element attribute='A'>text-value</sub-element>"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 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"699 + "<element attributeA='attribute-value' attributeB='attribute-value'>"700 + "<sub-element attribute='A'>text-value</sub-element>"701 + "</element>" 702 + "</root>");703 704 Map<String, String> expectedNamespaces = new HashMap<String, String>();705 expectedNamespaces.put("", "http://citrus/default");706 expectedNamespaces.put("nswrong", "http://citrus/ns1");707 expectedNamespaces.put("ns2", "http://citrus/ns2");708 709 validationContext.setControlNamespaces(expectedNamespaces);710 711 validationContext.setSchemaValidation(false);712 713 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();714 validationContexts.add(validationContext);715 receiveMessageBean.setValidationContexts(validationContexts);716 receiveMessageBean.execute(context);717 }718 719 @Test(expectedExceptions = {ValidationException.class})720 @SuppressWarnings({ "unchecked", "rawtypes" })721 public void testExpectDefaultNamespaceButNamespace() {722 reset(endpoint, consumer, endpointConfiguration);723 when(endpoint.createConsumer()).thenReturn(consumer);724 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);725 when(endpointConfiguration.getTimeout()).thenReturn(5000L);726 727 Message message = new DefaultMessage("<ns0:root xmlns:ns0='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"728 + "<ns0:element attributeA='attribute-value' attributeB='attribute-value'>"729 + "<ns0:sub-element attribute='A'>text-value</ns0:sub-element>"730 + "</ns0:element>" 731 + "</ns0:root>");732 733 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);734 when(endpoint.getActor()).thenReturn(null);735 736 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();737 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();738 receiveMessageBean.setMessageBuilder(controlMessageBuilder);739 controlMessageBuilder.setPayloadData("<ns0:root xmlns:ns0='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"740 + "<ns0:element attributeA='attribute-value' attributeB='attribute-value'>"741 + "<ns0:sub-element attribute='A'>text-value</ns0:sub-element>"742 + "</ns0:element>" 743 + "</ns0:root>");744 745 Map<String, String> expectedNamespaces = new HashMap<String, String>();746 expectedNamespaces.put("", "http://citrus/default");747 expectedNamespaces.put("ns1", "http://citrus/ns1");748 expectedNamespaces.put("ns2", "http://citrus/ns2");749 750 validationContext.setControlNamespaces(expectedNamespaces);751 752 validationContext.setSchemaValidation(false);753 754 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();755 validationContexts.add(validationContext);756 receiveMessageBean.setValidationContexts(validationContexts);757 receiveMessageBean.execute(context);758 }759 760 @Test(expectedExceptions = {ValidationException.class})761 @SuppressWarnings({ "unchecked", "rawtypes" })762 public void testExpectNamespaceButDefaultNamespace() {763 reset(endpoint, consumer, endpointConfiguration);764 when(endpoint.createConsumer()).thenReturn(consumer);765 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);766 when(endpointConfiguration.getTimeout()).thenReturn(5000L);767 768 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"769 + "<element attributeA='attribute-value' attributeB='attribute-value'>"770 + "<sub-element attribute='A'>text-value</sub-element>"771 + "</element>" 772 + "</root>");773 774 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);775 when(endpoint.getActor()).thenReturn(null);776 777 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();778 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();779 receiveMessageBean.setMessageBuilder(controlMessageBuilder);780 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"781 + "<element attributeA='attribute-value' attributeB='attribute-value'>"782 + "<sub-element attribute='A'>text-value</sub-element>"783 + "</element>" 784 + "</root>");785 786 Map<String, String> expectedNamespaces = new HashMap<String, String>();787 expectedNamespaces.put("ns0", "http://citrus/default");788 expectedNamespaces.put("ns1", "http://citrus/ns1");789 expectedNamespaces.put("ns2", "http://citrus/ns2");790 791 validationContext.setControlNamespaces(expectedNamespaces);792 793 validationContext.setSchemaValidation(false);794 795 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();796 validationContexts.add(validationContext);797 receiveMessageBean.setValidationContexts(validationContexts);798 receiveMessageBean.execute(context);799 }800 801 @Test(expectedExceptions = {ValidationException.class})802 @SuppressWarnings({ "unchecked", "rawtypes" })803 public void testExpectAdditionalNamespace() {804 reset(endpoint, consumer, endpointConfiguration);805 when(endpoint.createConsumer()).thenReturn(consumer);806 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);807 when(endpointConfiguration.getTimeout()).thenReturn(5000L);808 809 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"810 + "<element attributeA='attribute-value' attributeB='attribute-value'>"811 + "<sub-element attribute='A'>text-value</sub-element>"812 + "</element>" 813 + "</root>");814 815 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);816 when(endpoint.getActor()).thenReturn(null);817 818 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();819 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();820 receiveMessageBean.setMessageBuilder(controlMessageBuilder);821 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"822 + "<element attributeA='attribute-value' attributeB='attribute-value'>"823 + "<sub-element attribute='A'>text-value</sub-element>"824 + "</element>" 825 + "</root>");826 827 Map<String, String> expectedNamespaces = new HashMap<String, String>();828 expectedNamespaces.put("", "http://citrus/default");829 expectedNamespaces.put("ns1", "http://citrus/ns1");830 expectedNamespaces.put("ns2", "http://citrus/ns2");831 expectedNamespaces.put("ns4", "http://citrus/ns4");832 833 validationContext.setControlNamespaces(expectedNamespaces);834 835 validationContext.setSchemaValidation(false);836 837 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();838 validationContexts.add(validationContext);839 receiveMessageBean.setValidationContexts(validationContexts);840 receiveMessageBean.execute(context);841 }842 843 @Test(expectedExceptions = {ValidationException.class})844 @SuppressWarnings({ "unchecked", "rawtypes" })845 public void testExpectNamespaceButNamespaceMissing() {846 reset(endpoint, consumer, endpointConfiguration);847 when(endpoint.createConsumer()).thenReturn(consumer);848 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);849 when(endpointConfiguration.getTimeout()).thenReturn(5000L);850 851 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2' xmlns:ns4='http://citrus/ns4'>"852 + "<element attributeA='attribute-value' attributeB='attribute-value'>"853 + "<sub-element attribute='A'>text-value</sub-element>"854 + "</element>" 855 + "</root>");856 857 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);858 when(endpoint.getActor()).thenReturn(null);859 860 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();861 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();862 receiveMessageBean.setMessageBuilder(controlMessageBuilder);863 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2' xmlns:ns4='http://citrus/ns4'>"864 + "<element attributeA='attribute-value' attributeB='attribute-value'>"865 + "<sub-element attribute='A'>text-value</sub-element>"866 + "</element>" 867 + "</root>");868 869 Map<String, String> expectedNamespaces = new HashMap<String, String>();870 expectedNamespaces.put("", "http://citrus/default");871 expectedNamespaces.put("ns1", "http://citrus/ns1");872 expectedNamespaces.put("ns2", "http://citrus/ns2");873 874 validationContext.setControlNamespaces(expectedNamespaces);875 876 validationContext.setSchemaValidation(false);877 878 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();879 validationContexts.add(validationContext);880 receiveMessageBean.setValidationContexts(validationContexts);881 receiveMessageBean.execute(context);882 }883 884 @Test885 @SuppressWarnings({ "unchecked", "rawtypes" })886 public void testValidateMessageElementsWithAdditionalNamespacePrefix() {887 reset(endpoint, consumer, endpointConfiguration);888 when(endpoint.createConsumer()).thenReturn(consumer);...

Full Screen

Full Screen

Source:ReceiveMessageActionParser.java Github

copy

Full Screen

...239 private XpathMessageValidationContext getXPathMessageValidationContext(Element messageElement, XmlMessageValidationContext parentContext) {240 XpathMessageValidationContext context = new XpathMessageValidationContext();241 242 parseXPathValidationElements(messageElement, context);243 context.setControlNamespaces(parentContext.getControlNamespaces());244 context.setNamespaces(parentContext.getNamespaces());245 context.setIgnoreExpressions(parentContext.getIgnoreExpressions());246 context.setSchema(parentContext.getSchema());247 context.setSchemaRepository(parentContext.getSchemaRepository());248 context.setSchemaValidation(parentContext.isSchemaValidationEnabled());249 context.setDTDResource(parentContext.getDTDResource());250 return context;251 }252 /**253 * Construct the JSONPath message validation context.254 * @param messageElement255 * @return256 */257 private JsonPathMessageValidationContext getJsonPathMessageValidationContext(Element messageElement) {258 JsonPathMessageValidationContext context = new JsonPathMessageValidationContext();259 //check for validate elements, these elements can either have script, jsonPath or namespace validation information260 //for now we only handle jsonPath validation261 Map<String, Object> validateJsonPathExpressions = new HashMap<>();262 List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");263 if (validateElements.size() > 0) {264 for (Iterator<?> iter = validateElements.iterator(); iter.hasNext();) {265 Element validateElement = (Element) iter.next();266 extractJsonPathValidateExpressions(validateElement, validateJsonPathExpressions);267 }268 context.setJsonPathExpressions(validateJsonPathExpressions);269 }270 return context;271 }272 /**273 * Construct the message validation context.274 * @param messageElement275 * @return276 */277 private ScriptValidationContext getScriptValidationContext(Element messageElement, String messageType) {278 ScriptValidationContext context = null;279 boolean done = false;280 List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");281 if (validateElements.size() > 0) {282 for (Iterator<?> iter = validateElements.iterator(); iter.hasNext();) {283 Element validateElement = (Element) iter.next();284 Element scriptElement = DomUtils.getChildElementByTagName(validateElement, "script");285 // check for nested validate script child node286 if (scriptElement != null) {287 if (!done) {288 done = true;289 } else {290 throw new BeanCreationException("Found multiple validation script definitions - " +291 "only supporting a single validation script for message validation");292 }293 context = new ScriptValidationContext(messageType);294 String type = scriptElement.getAttribute("type");295 context.setScriptType(type);296 String filePath = scriptElement.getAttribute("file");297 if (StringUtils.hasText(filePath)) {298 context.setValidationScriptResourcePath(filePath);299 if (scriptElement.hasAttribute("charset")) {300 context.setValidationScriptResourceCharset(scriptElement.getAttribute("charset"));301 }302 } else {303 context.setValidationScript(DomUtils.getTextValue(scriptElement));304 }305 }306 }307 }308 return context;309 }310 311 /**312 * Parses validation elements and adds information to the message validation context.313 * 314 * @param messageElement the message DOM element.315 * @param context the message validation context.316 */317 private void parseNamespaceValidationElements(Element messageElement, XmlMessageValidationContext context) {318 //check for validate elements, these elements can either have script, xpath or namespace validation information319 //for now we only handle namespace validation320 Map<String, String> validateNamespaces = new HashMap<String, String>();321 List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");322 if (validateElements.size() > 0) {323 for (Iterator<?> iter = validateElements.iterator(); iter.hasNext();) {324 Element validateElement = (Element) iter.next();325 //check for namespace validation elements326 List<?> validateNamespaceElements = DomUtils.getChildElementsByTagName(validateElement, "namespace");327 if (validateNamespaceElements.size() > 0) {328 for (Iterator<?> namespaceIterator = validateNamespaceElements.iterator(); namespaceIterator.hasNext();) {329 Element namespaceElement = (Element) namespaceIterator.next();330 validateNamespaces.put(namespaceElement.getAttribute("prefix"), namespaceElement.getAttribute("value"));331 }332 }333 }334 context.setControlNamespaces(validateNamespaces);335 }336 }337 /**338 * Parses validation elements and adds information to the message validation context.339 *340 * @param messageElement the message DOM element.341 * @param context the message validation context.342 */343 private void parseXPathValidationElements(Element messageElement, XpathMessageValidationContext context) {344 //check for validate elements, these elements can either have script, xpath or namespace validation information345 //for now we only handle xpath validation346 Map<String, Object> validateXpathExpressions = new HashMap<>();347 List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");348 if (validateElements.size() > 0) {...

Full Screen

Full Screen

Source:XmlMessageValidationContext.java Github

copy

Full Screen

...96 /**97 * Set the control namespace elements.98 * @param controlNamespaces the controlNamespaces to set99 */100 public void setControlNamespaces(Map<String, String> controlNamespaces) {101 this.controlNamespaces = controlNamespaces;102 }103 /**104 * {@inheritDoc}105 */106 @Override107 public boolean isSchemaValidationEnabled() {108 return schemaValidation;109 }110 /**111 * {@inheritDoc}112 */113 @Override114 public void setSchemaValidation(boolean schemaValidation) {...

Full Screen

Full Screen

setControlNamespaces

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.validation.xml;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.exceptions.CitrusRuntimeException;4import com.consol.citrus.message.Message;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.message.MessageValidationContext;7import com.consol.citrus.message.MessageValidationContextFactory;8import com.consol.citrus.validation.xml.XmlMessageValidationContext;9import org.springframework.util.CollectionUtils;10import java.util.HashMap;11import java.util.Map;12import java.util.Optional;13public class XmlMessageValidationContextFactory implements MessageValidationContextFactory {14 public XmlMessageValidationContextFactory() {15 namespaceMap = new HashMap<>();16 }17 public MessageValidationContext createValidationContext(MessageType messageType, Message message, TestContext context) {18 if (messageType == MessageType.XML) {19 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();20 validationContext.setMessage(message);21 validationContext.setNamespaces(namespaceMap);22 validationContext.setSchemaRepository(schemaRepository);23 validationContext.setXsdSchemaCollection(xsdSchemaCollection);24 validationContext.setSchemaValidationEnabled(schemaValidationEnabled);25 validationContext.setDtdValidationEnabled(dtdValidationEnabled);26 validationContext.setIgnoreWhitespace(ignoreWhitespace);27 validationContext.setIgnoreNamespaces(ignoreNamespaces);28 validationContext.setIgnoreComments(ignoreComments);29 validationContext.setIgnoreDiffBetweenTextAndCDATA(ignoreDiffBetweenTextAndCDATA);30 validationContext.setIgnoreXmlDeclaration(ignoreXmlDeclaration);31 validationContext.setIgnoreEmptyElements(ignoreEmptyElements);32 validationContext.setIgnoreAttributeOrder(ignoreAttributeOrder);33 validationContext.setIgnoreXPathNamespacePrefix(ignoreXPathNamespacePrefix);34 validationContext.setIgnoreDTD(ignoreDTD);35 validationContext.setIgnoreSchemaLocation(ignoreSchemaLocation);

Full Screen

Full Screen

setControlNamespaces

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.annotations.CitrusTest;6import com.consol.citrus.testng.CitrusParameters;7import com.consol.citrus.validation.xml.XmlMessageValidationContext;8import com.consol.citrus.xml.namespace.NamespaceContextBuilder;9import com.consol.citrus.xml.namespace.SimpleNamespaceContextBuilder;10public class XmlMessageValidationContextTest {11 @CitrusParameters("controlNamespaces")12 public void testSetControlNamespaces() {13 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();14 Map<String, String> controlNamespaces = new HashMap<String, String>();15 xmlMessageValidationContext.setControlNamespaces(controlNamespaces);16 }17 @CitrusParameters("namespaceContextBuilder")18 public void testSetNamespaceContextBuilder() {19 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();20 NamespaceContextBuilder namespaceContextBuilder = new SimpleNamespaceContextBuilder();21 xmlMessageValidationContext.setNamespaceContextBuilder(namespaceContextBuilder);22 }23}24[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ citrus-core ---

Full Screen

Full Screen

setControlNamespaces

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import java.util.Arrays;3import java.util.List;4import org.testng.annotations.Test;5import com.consol.citrus.annotations.CitrusTest;6import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;7import com.consol.citrus.message.MessageType;8import com.consol.citrus.validation.xml.XmlMessageValidationContext;9public class Sample4 extends TestNGCitrusTestRunner {10 public void sample4() {11 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();12 xmlMessageValidationContext.setControlNamespaces(controlNamespaces);13 variable("xmlMessageValidationContext", xmlMessageValidationContext);14 echo("Using XmlMessageValidationContext: ${xmlMessageValidationContext}");15 http().client("httpClient")16 .send()17 .post()18 "</ns0:sayHelloRequest>");19 http().client("httpClient")20 .receive()21 .response(HttpStatus.OK)22 .messageType(MessageType.XML)23 .validate(xmlMessageValidationContext)24 }25}26package com.consol.citrus.samples;27import org.testng.annotations.Test;28import com.consol.citrus.annotations.CitrusTest;29import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;30import com.consol.citrus.message.MessageType;31import com.consol.citrus.validation.xml.XmlMessageValidationContext;32public class Sample5 extends TestNGCitrusTestRunner {33 public void sample5() {34 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();35 xmlMessageValidationContext.setSchemaRepository("classpath:com/consol/c

Full Screen

Full Screen

setControlNamespaces

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.builder;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.dsl.builder.AbstractTestContainerBuilder;4import com.consol.citrus.dsl.builder.DelegatingTestBuilder;5import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;6import com.consol.citrus.dsl.builder.SendMessageBuilder;7import com.consol.citrus.message.Message;8import com.consol.citrus.validation.xml.XmlMessageValidationContext;9import com.consol.citrus.validation.xml.XmlMessageValidationContext.Builder;10import com.consol.citrus.validation.xml.XmlMessageValidationErrorHandler;11import com.consol.citrus.validation.xml.XmlMessageValidationProcessor;12import com.consol.citrus.validation.xml.XmlMessageValidationUtils;13import com.consol.citrus.validation.xml.XmlSchemaValidationErrorHandler;14import com.consol.citrus.validation.xml.XsdSchemaRepository;15import com.consol.citrus.xml.XsdSchemaRepositoryFactoryBean;16import org.springframework.core.io.ClassPathResource;17import org.springframework.util.CollectionUtils;18import org.springframework.xml.xsd.SimpleXsdSchema;19import org.springframework.xml.xsd.XsdSchema;20import org.springframework.xml.xsd.XsdSchemaCollection;21import org.springframework.xml.xsd.XsdSchemaCollectionFactoryBean;22import javax.xml.transform.Source;23import javax.xml.transform.stream.StreamSource;24import java.util.ArrayList;25import java.util.Arrays;26import java.util.List;27public class SoapClientActionBuilder extends DelegatingTestBuilder<AbstractTestContainerBuilder<?, ?>> {28 private final SoapClient soapClient;29 private final SoapClientBuilder soapClientBuilder;30 private final List<SendMessageBuilder> sendMessageBuilders = new ArrayList<>();31 private final List<ReceiveMessageBuilder> receiveMessageBuilders = new ArrayList<>();32 private final List<ReceiveMessageBuilder> receiveFaultBuilders = new ArrayList<>();33 public SoapClientActionBuilder(AbstractTestContainerBuilder

Full Screen

Full Screen

setControlNamespaces

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;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.XmlMessageValidationContext;6import org.springframework.core.io.ClassPathResource;7import org.testng.annotations.Test;8public class 4 extends TestNGCitrusTestRunner {9 public void 4() {10 variable("var1", "value1");11 variable("var2", "value2");12 variable("var3", "value3");13 variable("var4", "value4");14 variable("var5", "value5");15 variable("var6", "value6");16 variable("var7", "value7");17 variable("var8", "value8");18 variable("var9", "value9");19 variable("var10", "value10");20 variable("var11", "value11");21 variable("var12", "value12");22 variable("var13", "value13");23 variable("var14", "value14");24 variable("var15", "value15");25 variable("var16", "value16");26 variable("var17", "value17");27 variable("var18", "value18");28 variable("var19", "value19");29 variable("var20", "value20");30 variable("var21", "value21");31 variable("var22", "value22");32 variable("var23", "value23");33 variable("var24", "value24");34 variable("var25", "value25");35 variable("var26", "value26");36 variable("var27", "value27");37 variable("var28", "value28");38 variable("var29", "value29");39 variable("var30", "value30");40 variable("var31", "value31");41 variable("var32", "value32");42 variable("var33", "value33");43 variable("var34", "value34");44 variable("var35", "value35");45 variable("var36", "value36");46 variable("var37", "value37");47 variable("var38", "value38");48 variable("var39", "value

Full Screen

Full Screen

setControlNamespaces

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2import org.testng.annotations.Test;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.dsl.builder.SendSoapMessageBuilder;5import com.consol.citrus.testng.TestNGCitrusSupport;6public class SoapTest extends TestNGCitrusSupport {7public void soapTest() {8.send()9.soap()10.endpoint(soapEndpoint)11.message()12+ "</soapenv:Envelope>");13sendSoapMessageBuilder.getEndpointConfiguration().setValidationContext(new XmlMessageValidationContext());14sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreNamespaces(true);15sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreWhitespace(true);16sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreComments(true);17sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreDiffContent(true);18sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreXmlDeclaration(true);19sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreDtd(true);20sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreSchemaLocation(true);21sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreUnknownElements(true);22sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreXPath("/soapenv:Envelope/soapenv:Body/web:GetLastTradePriceResponse/web:Price", "10.0");23sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreXPath("/soapenv:Envelope/soapenv:Header", "10.0");24sendSoapMessageBuilder.getEndpointConfiguration().getValidationContext().setIgnoreXPath("/soapenv:Envelope/soapenv:Body/web:Get

Full Screen

Full Screen

setControlNamespaces

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.BuilderSupport;2import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;3import com.consol.citrus.dsl.builder.SendBuilder;4import com.consol.citrus.dsl.junit.JUnit4CitrusTest;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.validation.xml.XmlMessageValidationContext;7import org.testng.annotations.Test;8import java.util.HashMap;9import java.util.Map;10public class 4 extends JUnit4CitrusTest {11 public void 4() {12 description("4");13 variable("name", "John");14 variable("name", "Jane");15 variable("name", "Joe");16 parallel().actions(17 sequential().actions(18 send("client")19 .messageType(MessageType.XML)20 .header("operation", "sayHello")21 .header("citrus_jms_messageId", "1234567890")22 .header("citrus_jms_correlationId", "0987654321")23 .header("citrus_jms_timestamp", "1234567890")24 .header("citrus_jms_type", "MyType")25 .header("citrus_jms_replyTo", "replyQueue")26 .header("citrus_jms_priority", "2")27 .header("citrus_jms_expiration", "1234567890")28 .header("citrus_jms_redelivered", "true")29 .header("citrus_jms_deliveryMode", "persistent")30 .header("citrus_jms_groupId", "citrus:concat('group', citrus:randomNumber(3))")31 .header("citrus_jms_groupSequence", "1")32 .extractFromHeader("citrus_jms_messageId", "correlation_id")33 .extractFromHeader("citrus_jms_correlationId", "correlation_id")34 sequential().actions(35 receive("client")

Full Screen

Full Screen

setControlNamespaces

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.validation.xml.XmlMessageValidationContext;5import org.springframework.core.io.ClassPathResource;6import org.testng.annotations.Test;7import java.util.HashMap;8import java.util.Map;9public class 4 extends TestNGCitrusTestDesigner {10public void 4() {11Map<String, String> namespaces = new HashMap<>();12XmlMessageValidationContext validationContext = new XmlMessageValidationContext();13validationContext.setControlNamespaces(namespaces);14send("sender")15.messageType(MessageType.XML)16.payload(new ClassPathResource("request4.xml"));17receive("receiver")18.messageType(MessageType.XML)19.validationContext(validationContext)20.payload(new ClassPathResource("response4.xml"));21}22}23package com.consol.citrus.samples;24import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;25import com.consol.citrus.message.MessageType;26import com.consol.citrus.validation.xml.XmlMessageValidationContext;27import org.springframework.core.io.ClassPathResource;28import org.testng.annotations.Test;29public class 5 extends TestNGCitrusTestDesigner {30public void 5() {31XmlMessageValidationContext validationContext = new XmlMessageValidationContext();32validationContext.setSchemaValidation(true);33send("sender")34.messageType(MessageType.XML)35.payload(new ClassPathResource("request5.xml"));36receive("receiver")37.messageType(MessageType.XML)38.validationContext(validationContext)39.payload(new ClassPathResource("response5.xml"));40}41}42package com.consol.citrus.samples;43import com.consol.citrus.dsl.testng.TestNG

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful