Best Citrus code snippet using com.consol.citrus.validation.xml.XmlMessageValidationContext.setSchemaValidation
Source:ReceiveMessageActionTest.java
...414 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);415 when(endpointConfiguration.getTimeout()).thenReturn(5000L);416 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);417 when(endpoint.getActor()).thenReturn(null);418 validationContext.setSchemaValidation(false);419 420 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 421 validationContexts.add(validationContext);422 receiveAction.setValidationContexts(validationContexts);423 receiveAction.execute(context);424 }425 426 @Test427 @SuppressWarnings({ "unchecked", "rawtypes" })428 public void testReceiveMessageOverwriteMessageElementsXPathWithNestedNamespaces() {429 ReceiveMessageAction receiveAction = new ReceiveMessageAction();430 receiveAction.setEndpoint(endpoint);431 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();432 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();433 receiveAction.setMessageBuilder(controlMessageBuilder);434 controlMessageBuilder.setPayloadData("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +435 "<ns1:Message xmlns:ns1=\"http://citrusframework.org/unittest/message\">?</ns1:Message></ns0:TestRequest>");436 437 Map<String, String> overwriteElements = new HashMap<String, String>();438 overwriteElements.put("/ns0:TestRequest/ns1:Message", "Hello World!");439 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);440 controlMessageBuilder.add(interceptor);441 442 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +443 "<ns1:Message xmlns:ns1=\"http://citrusframework.org/unittest/message\">Hello World!</ns1:Message></ns0:TestRequest>");444 reset(endpoint, consumer, endpointConfiguration);445 when(endpoint.createConsumer()).thenReturn(consumer);446 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);447 when(endpointConfiguration.getTimeout()).thenReturn(5000L);448 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);449 when(endpoint.getActor()).thenReturn(null);450 validationContext.setSchemaValidation(false);451 452 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 453 validationContexts.add(validationContext);454 receiveAction.setValidationContexts(validationContexts);455 receiveAction.execute(context);456 }457 458 @Test459 @SuppressWarnings({ "unchecked", "rawtypes" })460 public void testReceiveMessageOverwriteMessageElementsXPathWithDefaultNamespaces() {461 ReceiveMessageAction receiveAction = new ReceiveMessageAction();462 receiveAction.setEndpoint(endpoint);463 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();464 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();465 receiveAction.setMessageBuilder(controlMessageBuilder);466 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +467 "<Message>?</Message></TestRequest>");468 469 Map<String, String> overwriteElements = new HashMap<String, String>();470 overwriteElements.put("/:TestRequest/:Message", "Hello World!");471 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);472 controlMessageBuilder.add(interceptor);473 474 Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\"><Message>Hello World!</Message></TestRequest>");475 reset(endpoint, consumer, endpointConfiguration);476 when(endpoint.createConsumer()).thenReturn(consumer);477 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);478 when(endpointConfiguration.getTimeout()).thenReturn(5000L);479 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);480 when(endpoint.getActor()).thenReturn(null);481 validationContext.setSchemaValidation(false);482 483 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 484 validationContexts.add(validationContext);485 receiveAction.setValidationContexts(validationContexts);486 receiveAction.execute(context);487 }488 489 @Test490 @SuppressWarnings({ "unchecked", "rawtypes" })491 public void testReceiveMessageWithMessageHeaders() {492 ReceiveMessageAction receiveAction = new ReceiveMessageAction();493 receiveAction.setEndpoint(endpoint);494 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();495 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();496 receiveAction.setMessageBuilder(controlMessageBuilder);497 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");498 Map<String, Object> headers = new HashMap<String, Object>();499 headers.put("Operation", "sayHello");500 controlMessageBuilder.setMessageHeaders(headers);501 Map<String, Object> controlHeaders = new HashMap<String, Object>();502 controlHeaders.put("Operation", "sayHello");503 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);504 reset(endpoint, consumer, endpointConfiguration);505 when(endpoint.createConsumer()).thenReturn(consumer);506 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);507 when(endpointConfiguration.getTimeout()).thenReturn(5000L);508 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);509 when(endpoint.getActor()).thenReturn(null);510 511 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 512 validationContexts.add(validationContext);513 receiveAction.setValidationContexts(validationContexts);514 receiveAction.execute(context);515 }516 517 @Test518 @SuppressWarnings({ "unchecked", "rawtypes" })519 public void testReceiveMessageWithMessageHeadersVariablesSupport() {520 ReceiveMessageAction receiveAction = new ReceiveMessageAction();521 receiveAction.setEndpoint(endpoint);522 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();523 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();524 receiveAction.setMessageBuilder(controlMessageBuilder);525 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");526 context.setVariable("myOperation", "sayHello");527 528 Map<String, Object> headers = new HashMap<String, Object>();529 headers.put("Operation", "${myOperation}");530 controlMessageBuilder.setMessageHeaders(headers);531 532 Map<String, Object> controlHeaders = new HashMap<String, Object>();533 controlHeaders.put("Operation", "sayHello");534 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);535 reset(endpoint, consumer, endpointConfiguration);536 when(endpoint.createConsumer()).thenReturn(consumer);537 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);538 when(endpointConfiguration.getTimeout()).thenReturn(5000L);539 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);540 when(endpoint.getActor()).thenReturn(null);541 542 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 543 validationContexts.add(validationContext);544 receiveAction.setValidationContexts(validationContexts);545 receiveAction.execute(context);546 }547 548 @Test549 @SuppressWarnings({ "unchecked", "rawtypes" })550 public void testReceiveMessageWithUnknownVariablesInMessageHeaders() {551 ReceiveMessageAction receiveAction = new ReceiveMessageAction();552 receiveAction.setEndpoint(endpoint);553 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();554 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();555 receiveAction.setMessageBuilder(controlMessageBuilder);556 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");557 Map<String, Object> headers = new HashMap<String, Object>();558 headers.put("Operation", "${myOperation}");559 controlMessageBuilder.setMessageHeaders(headers);560 561 Map<String, Object> controlHeaders = new HashMap<String, Object>();562 controlHeaders.put("Operation", "sayHello");563 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);564 reset(endpoint, consumer, endpointConfiguration);565 when(endpoint.createConsumer()).thenReturn(consumer);566 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);567 when(endpointConfiguration.getTimeout()).thenReturn(5000L);568 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);569 when(endpoint.getActor()).thenReturn(null);570 571 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 572 validationContexts.add(validationContext);573 receiveAction.setValidationContexts(validationContexts);574 try {575 receiveAction.execute(context);576 } catch(CitrusRuntimeException e) {577 Assert.assertEquals(e.getMessage(), "Unknown variable 'myOperation'");578 return;579 }580 }581 582 @Test583 @SuppressWarnings({ "unchecked", "rawtypes" })584 public void testReceiveMessageWithUnknownVariableInMessagePayload() {585 ReceiveMessageAction receiveAction = new ReceiveMessageAction();586 receiveAction.setEndpoint(endpoint);587 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();588 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();589 receiveAction.setMessageBuilder(controlMessageBuilder);590 controlMessageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");591 592 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");593 reset(endpoint, consumer, endpointConfiguration);594 when(endpoint.createConsumer()).thenReturn(consumer);595 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);596 when(endpointConfiguration.getTimeout()).thenReturn(5000L);597 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);598 when(endpoint.getActor()).thenReturn(null);599 600 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 601 validationContexts.add(validationContext);602 receiveAction.setValidationContexts(validationContexts);603 try {604 receiveAction.execute(context);605 } catch(CitrusRuntimeException e) {606 Assert.assertEquals(e.getMessage(), "Unknown variable 'myText'");607 return;608 }609 }610 611 @Test612 @SuppressWarnings({ "unchecked", "rawtypes" })613 public void testReceiveMessageWithExtractVariablesFromHeaders() {614 ReceiveMessageAction receiveAction = new ReceiveMessageAction();615 receiveAction.setEndpoint(endpoint);616 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();617 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();618 receiveAction.setMessageBuilder(controlMessageBuilder);619 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");620 Map<String, String> headers = new HashMap<String, String>();621 headers.put("Operation", "myOperation");622 623 MessageHeaderVariableExtractor headerVariableExtractor = new MessageHeaderVariableExtractor();624 headerVariableExtractor.setHeaderMappings(headers);625 List<VariableExtractor> variableExtractors = new ArrayList<VariableExtractor>();626 variableExtractors.add(headerVariableExtractor);627 receiveAction.addVariableExtractors(headerVariableExtractor);628 629 Map<String, Object> controlHeaders = new HashMap<String, Object>();630 controlHeaders.put("Operation", "sayHello");631 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);632 reset(endpoint, consumer, endpointConfiguration);633 when(endpoint.createConsumer()).thenReturn(consumer);634 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);635 when(endpointConfiguration.getTimeout()).thenReturn(5000L);636 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);637 when(endpoint.getActor()).thenReturn(null);638 639 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 640 validationContexts.add(validationContext);641 receiveAction.setValidationContexts(validationContexts);642 receiveAction.execute(context);643 644 Assert.assertNotNull(context.getVariable("myOperation"));645 Assert.assertEquals(context.getVariable("myOperation"), "sayHello");646 }647 648 @Test649 @SuppressWarnings({ "unchecked", "rawtypes" })650 public void testReceiveMessageWithValidateMessageElementsFromMessageXPath() {651 ReceiveMessageAction receiveAction = new ReceiveMessageAction();652 receiveAction.setEndpoint(endpoint);653 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();654 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();655 receiveAction.setMessageBuilder(controlMessageBuilder);656 Map<String, Object> messageElements = new HashMap<>();657 messageElements.put("/TestRequest/Message", "Hello World!");658 validationContext.setXpathExpressions(messageElements);659 660 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");661 reset(endpoint, consumer, endpointConfiguration);662 when(endpoint.createConsumer()).thenReturn(consumer);663 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);664 when(endpointConfiguration.getTimeout()).thenReturn(5000L);665 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);666 when(endpoint.getActor()).thenReturn(null);667 668 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 669 validationContexts.add(validationContext);670 receiveAction.setValidationContexts(validationContexts);671 receiveAction.execute(context);672 }673 674 @Test675 @SuppressWarnings({ "unchecked", "rawtypes" })676 public void testReceiveMessageWithValidateMessageElementsXPathDefaultNamespaceSupport() {677 ReceiveMessageAction receiveAction = new ReceiveMessageAction();678 receiveAction.setEndpoint(endpoint);679 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();680 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();681 receiveAction.setMessageBuilder(controlMessageBuilder);682 Map<String, Object> messageElements = new HashMap<>();683 messageElements.put("/:TestRequest/:Message", "Hello World!");684 validationContext.setXpathExpressions(messageElements);685 686 Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +687 "<Message>Hello World!</Message></TestRequest>");688 reset(endpoint, consumer, endpointConfiguration);689 when(endpoint.createConsumer()).thenReturn(consumer);690 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);691 when(endpointConfiguration.getTimeout()).thenReturn(5000L);692 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);693 when(endpoint.getActor()).thenReturn(null);694 validationContext.setSchemaValidation(false);695 696 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 697 validationContexts.add(validationContext);698 receiveAction.setValidationContexts(validationContexts);699 receiveAction.execute(context);700 }701 702 @Test703 @SuppressWarnings({ "unchecked", "rawtypes" })704 public void testReceiveMessageWithValidateMessageElementsXPathNamespaceSupport() {705 ReceiveMessageAction receiveAction = new ReceiveMessageAction();706 receiveAction.setEndpoint(endpoint);707 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();708 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();709 receiveAction.setMessageBuilder(controlMessageBuilder);710 Map<String, Object> messageElements = new HashMap<>();711 messageElements.put("/ns0:TestRequest/ns0:Message", "Hello World!");712 validationContext.setXpathExpressions(messageElements);713 714 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +715 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");716 reset(endpoint, consumer, endpointConfiguration);717 when(endpoint.createConsumer()).thenReturn(consumer);718 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);719 when(endpointConfiguration.getTimeout()).thenReturn(5000L);720 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);721 when(endpoint.getActor()).thenReturn(null);722 validationContext.setSchemaValidation(false);723 724 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 725 validationContexts.add(validationContext);726 receiveAction.setValidationContexts(validationContexts);727 receiveAction.execute(context);728 }729 730 @Test731 @SuppressWarnings({ "unchecked", "rawtypes" })732 public void testReceiveMessageWithValidateMessageElementsXPathNestedNamespaceSupport() {733 ReceiveMessageAction receiveAction = new ReceiveMessageAction();734 receiveAction.setEndpoint(endpoint);735 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();736 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();737 receiveAction.setMessageBuilder(controlMessageBuilder);738 Map<String, Object> messageElements = new HashMap<>();739 messageElements.put("/ns0:TestRequest/ns1:Message", "Hello World!");740 validationContext.setXpathExpressions(messageElements);741 742 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +743 "<ns1:Message xmlns:ns1=\"http://citrusframework.org/unittest/message\">Hello World!</ns1:Message></ns0:TestRequest>");744 reset(endpoint, consumer, endpointConfiguration);745 when(endpoint.createConsumer()).thenReturn(consumer);746 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);747 when(endpointConfiguration.getTimeout()).thenReturn(5000L);748 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);749 when(endpoint.getActor()).thenReturn(null);750 validationContext.setSchemaValidation(false);751 752 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 753 validationContexts.add(validationContext);754 receiveAction.setValidationContexts(validationContexts);755 receiveAction.execute(context);756 }757 758 @Test759 @SuppressWarnings({ "unchecked", "rawtypes" })760 public void testReceiveMessageWithValidateMessageElementsXPathNamespaceBindings() {761 ReceiveMessageAction receiveAction = new ReceiveMessageAction();762 receiveAction.setEndpoint(endpoint);763 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();764 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();765 receiveAction.setMessageBuilder(controlMessageBuilder);766 Map<String, Object> messageElements = new HashMap<>();767 messageElements.put("/pfx:TestRequest/pfx:Message", "Hello World!");768 validationContext.setXpathExpressions(messageElements);769 770 Map<String, String> namespaces = new HashMap<String, String>();771 namespaces.put("pfx", "http://citrusframework.org/unittest");772 validationContext.setNamespaces(namespaces);773 774 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +775 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");776 reset(endpoint, consumer, endpointConfiguration);777 when(endpoint.createConsumer()).thenReturn(consumer);778 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);779 when(endpointConfiguration.getTimeout()).thenReturn(5000L);780 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);781 when(endpoint.getActor()).thenReturn(null);782 validationContext.setSchemaValidation(false);783 784 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 785 validationContexts.add(validationContext);786 receiveAction.setValidationContexts(validationContexts);787 receiveAction.execute(context);788 }789 @Test790 @SuppressWarnings({ "unchecked", "rawtypes" })791 public void testReceiveMessageWithExtractVariablesFromMessageJsonPath() {792 ReceiveMessageAction receiveAction = new ReceiveMessageAction();793 receiveAction.setEndpoint(endpoint);794 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();795 JsonMessageValidationContext validationContext = new JsonMessageValidationContext();796 receiveAction.setMessageBuilder(controlMessageBuilder);797 controlMessageBuilder.setPayloadData("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");798 Map<String, String> extractMessageElements = new HashMap<String, String>();799 extractMessageElements.put("$.text", "messageVar");800 extractMessageElements.put("$.person", "person");801 JsonPathVariableExtractor variableExtractor = new JsonPathVariableExtractor();802 variableExtractor.setJsonPathExpressions(extractMessageElements);803 receiveAction.addVariableExtractors(variableExtractor);804 Message controlMessage = new DefaultMessage("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");805 reset(endpoint, consumer, endpointConfiguration);806 when(endpoint.createConsumer()).thenReturn(consumer);807 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);808 when(endpointConfiguration.getTimeout()).thenReturn(5000L);809 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);810 when(endpoint.getActor()).thenReturn(null);811 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();812 validationContexts.add(validationContext);813 receiveAction.setValidationContexts(validationContexts);814 receiveAction.execute(context);815 Assert.assertNotNull(context.getVariable("messageVar"));816 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");817 Assert.assertNotNull(context.getVariable("person"));818 Assert.assertTrue(context.getVariable("person").contains("\"John\""));819 }820 821 @Test822 @SuppressWarnings({ "unchecked", "rawtypes" })823 public void testReceiveMessageWithExtractVariablesFromMessageXPath() {824 ReceiveMessageAction receiveAction = new ReceiveMessageAction();825 receiveAction.setEndpoint(endpoint);826 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();827 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();828 receiveAction.setMessageBuilder(controlMessageBuilder);829 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");830 Map<String, String> extractMessageElements = new HashMap<String, String>();831 extractMessageElements.put("/TestRequest/Message", "messageVar");832 833 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();834 variableExtractor.setXpathExpressions(extractMessageElements);835 receiveAction.addVariableExtractors(variableExtractor);836 837 Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");838 reset(endpoint, consumer, endpointConfiguration);839 when(endpoint.createConsumer()).thenReturn(consumer);840 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);841 when(endpointConfiguration.getTimeout()).thenReturn(5000L);842 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);843 when(endpoint.getActor()).thenReturn(null);844 845 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 846 validationContexts.add(validationContext);847 receiveAction.setValidationContexts(validationContexts);848 receiveAction.execute(context);849 850 Assert.assertNotNull(context.getVariable("messageVar"));851 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");852 }853 @Test854 @SuppressWarnings({ "unchecked", "rawtypes" })855 public void testReceiveMessageWithExtractVariablesFromMessageXPathNodeList() {856 ReceiveMessageAction receiveAction = new ReceiveMessageAction();857 receiveAction.setEndpoint(endpoint);858 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();859 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();860 receiveAction.setMessageBuilder(controlMessageBuilder);861 controlMessageBuilder.setPayloadData("<TestRequest>" +862 "<Message>Hello</Message>" +863 "<Message>ByeBye</Message>" +864 "</TestRequest>");865 Map<String, String> extractMessageElements = new HashMap<String, String>();866 extractMessageElements.put("node-set://TestRequest/Message", "messageVar");867 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();868 variableExtractor.setXpathExpressions(extractMessageElements);869 receiveAction.addVariableExtractors(variableExtractor);870 Message controlMessage = new DefaultMessage("<TestRequest>" +871 "<Message>Hello</Message>" +872 "<Message>ByeBye</Message>" +873 "</TestRequest>");874 reset(endpoint, consumer, endpointConfiguration);875 when(endpoint.createConsumer()).thenReturn(consumer);876 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);877 when(endpointConfiguration.getTimeout()).thenReturn(5000L);878 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);879 when(endpoint.getActor()).thenReturn(null);880 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();881 validationContexts.add(validationContext);882 receiveAction.setValidationContexts(validationContexts);883 receiveAction.execute(context);884 Assert.assertNotNull(context.getVariable("messageVar"));885 Assert.assertEquals(context.getVariable("messageVar"), "Hello,ByeBye");886 }887 @Test888 @SuppressWarnings({ "unchecked", "rawtypes" })889 public void testReceiveMessageWithExtractVariablesFromMessageXPathDefaultNamespaceSupport() {890 ReceiveMessageAction receiveAction = new ReceiveMessageAction();891 receiveAction.setEndpoint(endpoint);892 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();893 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();894 receiveAction.setMessageBuilder(controlMessageBuilder);895 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +896 "<Message>Hello World!</Message></TestRequest>");897 Map<String, String> extractMessageElements = new HashMap<String, String>();898 extractMessageElements.put("/:TestRequest/:Message", "messageVar");899 900 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();901 variableExtractor.setXpathExpressions(extractMessageElements);902 receiveAction.addVariableExtractors(variableExtractor);903 904 Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +905 "<Message>Hello World!</Message></TestRequest>");906 reset(endpoint, consumer, endpointConfiguration);907 when(endpoint.createConsumer()).thenReturn(consumer);908 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);909 when(endpointConfiguration.getTimeout()).thenReturn(5000L);910 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);911 when(endpoint.getActor()).thenReturn(null);912 913 validationContext.setSchemaValidation(false);914 915 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 916 validationContexts.add(validationContext);917 receiveAction.setValidationContexts(validationContexts);918 receiveAction.execute(context);919 920 Assert.assertNotNull(context.getVariable("messageVar"));921 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");922 }923 924 @Test925 @SuppressWarnings({ "unchecked", "rawtypes" })926 public void testReceiveMessageWithExtractVariablesFromMessageXPathNamespaceSupport() {927 ReceiveMessageAction receiveAction = new ReceiveMessageAction();928 receiveAction.setEndpoint(endpoint);929 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();930 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();931 receiveAction.setMessageBuilder(controlMessageBuilder);932 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +933 "<Message>Hello World!</Message></TestRequest>");934 935 Map<String, String> extractMessageElements = new HashMap<String, String>();936 extractMessageElements.put("/ns0:TestRequest/ns0:Message", "messageVar");937 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();938 variableExtractor.setXpathExpressions(extractMessageElements);939 receiveAction.addVariableExtractors(variableExtractor);940 941 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +942 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");943 reset(endpoint, consumer, endpointConfiguration);944 when(endpoint.createConsumer()).thenReturn(consumer);945 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);946 when(endpointConfiguration.getTimeout()).thenReturn(5000L);947 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);948 when(endpoint.getActor()).thenReturn(null);949 950 validationContext.setSchemaValidation(false);951 952 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 953 validationContexts.add(validationContext);954 receiveAction.setValidationContexts(validationContexts);955 receiveAction.execute(context);956 957 Assert.assertNotNull(context.getVariable("messageVar"));958 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");959 }960 961 @Test962 @SuppressWarnings({ "unchecked", "rawtypes" })963 public void testReceiveMessageWithExtractVariablesFromMessageXPathNestedNamespaceSupport() {964 ReceiveMessageAction receiveAction = new ReceiveMessageAction();965 receiveAction.setEndpoint(endpoint);966 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();967 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();968 receiveAction.setMessageBuilder(controlMessageBuilder);969 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\" xmlns:ns1=\"http://citrusframework.org/unittest/message\">" +970 "<ns1:Message>Hello World!</ns1:Message></TestRequest>");971 Map<String, String> extractMessageElements = new HashMap<String, String>();972 extractMessageElements.put("/ns0:TestRequest/ns1:Message", "messageVar");973 974 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();975 variableExtractor.setXpathExpressions(extractMessageElements);976 receiveAction.addVariableExtractors(variableExtractor);977 978 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +979 "<ns1:Message xmlns:ns1=\"http://citrusframework.org/unittest/message\">Hello World!</ns1:Message></ns0:TestRequest>");980 reset(endpoint, consumer, endpointConfiguration);981 when(endpoint.createConsumer()).thenReturn(consumer);982 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);983 when(endpointConfiguration.getTimeout()).thenReturn(5000L);984 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);985 when(endpoint.getActor()).thenReturn(null);986 987 validationContext.setSchemaValidation(false);988 989 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 990 validationContexts.add(validationContext);991 receiveAction.setValidationContexts(validationContexts);992 receiveAction.execute(context);993 994 Assert.assertNotNull(context.getVariable("messageVar"));995 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");996 }997 998 @Test999 @SuppressWarnings({ "unchecked", "rawtypes" })1000 public void testReceiveMessageWithExtractVariablesFromMessageXPathNamespaceBindings() {1001 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1002 receiveAction.setEndpoint(endpoint);1003 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();1004 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();1005 receiveAction.setMessageBuilder(controlMessageBuilder);1006 controlMessageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +1007 "<Message>Hello World!</Message></TestRequest>");1008 Map<String, String> extractMessageElements = new HashMap<String, String>();1009 extractMessageElements.put("/pfx:TestRequest/pfx:Message", "messageVar");1010 1011 XpathPayloadVariableExtractor variableExtractor = new XpathPayloadVariableExtractor();1012 variableExtractor.setXpathExpressions(extractMessageElements);1013 receiveAction.addVariableExtractors(variableExtractor);1014 1015 Map<String, String> namespaces = new HashMap<String, String>();1016 namespaces.put("pfx", "http://citrusframework.org/unittest");1017 variableExtractor.setNamespaces(namespaces);1018 1019 Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +1020 "<ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");1021 reset(endpoint, consumer, endpointConfiguration);1022 when(endpoint.createConsumer()).thenReturn(consumer);1023 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);1024 when(endpointConfiguration.getTimeout()).thenReturn(5000L);1025 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);1026 when(endpoint.getActor()).thenReturn(null);1027 1028 validationContext.setSchemaValidation(false);1029 1030 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>(); 1031 validationContexts.add(validationContext);1032 receiveAction.setValidationContexts(validationContexts);1033 receiveAction.execute(context);1034 1035 Assert.assertNotNull(context.getVariable("messageVar"));1036 Assert.assertEquals(context.getVariable("messageVar"), "Hello World!");1037 }1038 @Test1039 public void testReceiveMessageWithJsonPathValidation() {1040 ReceiveMessageAction receiveAction = new ReceiveMessageAction();1041 receiveAction.setEndpoint(endpoint);1042 receiveAction.setMessageType(MessageType.JSON.toString());...
Source:NamespaceTest.java
...77 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"78 + "</ns1:element>" 79 + "</ns1:root>");80 81 validationContext.setSchemaValidation(false);82 83 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();84 validationContexts.add(validationContext);85 receiveMessageBean.setValidationContexts(validationContexts);86 receiveMessageBean.execute(context);87 }88 89 @Test90 @SuppressWarnings({ "unchecked", "rawtypes" })91 public void testDifferentNamespacePrefix() {92 reset(endpoint, consumer, endpointConfiguration);93 when(endpoint.createConsumer()).thenReturn(consumer);94 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);95 when(endpointConfiguration.getTimeout()).thenReturn(5000L);96 97 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus'>"98 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"99 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"100 + "</ns1:element>" 101 + "</ns1:root>");102 103 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);104 when(endpoint.getActor()).thenReturn(null);105 106 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();107 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();108 receiveMessageBean.setMessageBuilder(controlMessageBuilder);109 controlMessageBuilder.setPayloadData("<ns2:root xmlns:ns2='http://citrus'>"110 + "<ns2:element attributeA='attribute-value' attributeB='attribute-value'>"111 + "<ns2:sub-element attribute='A'>text-value</ns2:sub-element>"112 + "</ns2:element>" 113 + "</ns2:root>");114 115 validationContext.setSchemaValidation(false);116 117 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();118 validationContexts.add(validationContext);119 receiveMessageBean.setValidationContexts(validationContexts);120 receiveMessageBean.execute(context);121 }122 123 @Test124 @SuppressWarnings({ "unchecked", "rawtypes" })125 public void testAdditionalNamespace() {126 reset(endpoint, consumer, endpointConfiguration);127 when(endpoint.createConsumer()).thenReturn(consumer);128 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);129 when(endpointConfiguration.getTimeout()).thenReturn(5000L);130 131 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus'>"132 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"133 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"134 + "</ns1:element>" 135 + "</ns1:root>");136 137 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);138 when(endpoint.getActor()).thenReturn(null);139 140 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();141 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();142 receiveMessageBean.setMessageBuilder(controlMessageBuilder);143 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus' xmlns:ns2='http://citrus/default'>"144 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"145 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"146 + "</ns1:element>" 147 + "</ns1:root>");148 149 validationContext.setSchemaValidation(false);150 151 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();152 validationContexts.add(validationContext);153 receiveMessageBean.setValidationContexts(validationContexts);154 receiveMessageBean.execute(context);155 }156 157 @Test158 @SuppressWarnings({ "unchecked", "rawtypes" })159 public void testMissingNamespaceDeclaration() {160 reset(endpoint, consumer, endpointConfiguration);161 when(endpoint.createConsumer()).thenReturn(consumer);162 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);163 when(endpointConfiguration.getTimeout()).thenReturn(5000L);164 165 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus' xmlns:ns2='http://citrus/default'>"166 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"167 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"168 + "</ns1:element>" 169 + "</ns1:root>");170 171 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);172 when(endpoint.getActor()).thenReturn(null);173 174 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();175 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();176 receiveMessageBean.setMessageBuilder(controlMessageBuilder);177 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus'>"178 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"179 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"180 + "</ns1:element>" 181 + "</ns1:root>");182 183 validationContext.setSchemaValidation(false);184 185 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();186 validationContexts.add(validationContext);187 receiveMessageBean.setValidationContexts(validationContexts);188 receiveMessageBean.execute(context);189 }190 191 @Test192 @SuppressWarnings({ "unchecked", "rawtypes" })193 public void testDefaultNamespaces() {194 reset(endpoint, consumer, endpointConfiguration);195 when(endpoint.createConsumer()).thenReturn(consumer);196 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);197 when(endpointConfiguration.getTimeout()).thenReturn(5000L);198 199 Message message = new DefaultMessage("<root xmlns='http://citrus'>"200 + "<element attributeA='attribute-value' attributeB='attribute-value'>"201 + "<sub-element attribute='A'>text-value</sub-element>"202 + "</element>" 203 + "</root>");204 205 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);206 when(endpoint.getActor()).thenReturn(null);207 208 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();209 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();210 receiveMessageBean.setMessageBuilder(controlMessageBuilder);211 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus'>"212 + "<element attributeA='attribute-value' attributeB='attribute-value'>"213 + "<sub-element attribute='A'>text-value</sub-element>"214 + "</element>" 215 + "</root>");216 217 validationContext.setSchemaValidation(false);218 219 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();220 validationContexts.add(validationContext);221 receiveMessageBean.setValidationContexts(validationContexts);222 receiveMessageBean.execute(context);223 }224 @Test225 @SuppressWarnings({ "unchecked", "rawtypes" })226 public void testDefaultNamespacesInExpectedMessage() {227 reset(endpoint, consumer, endpointConfiguration);228 when(endpoint.createConsumer()).thenReturn(consumer);229 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);230 when(endpointConfiguration.getTimeout()).thenReturn(5000L);231 232 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus'>"233 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"234 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"235 + "</ns1:element>" 236 + "</ns1:root>");237 238 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);239 when(endpoint.getActor()).thenReturn(null);240 241 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();242 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();243 receiveMessageBean.setMessageBuilder(controlMessageBuilder);244 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus'>"245 + "<element attributeA='attribute-value' attributeB='attribute-value'>"246 + "<sub-element attribute='A'>text-value</sub-element>"247 + "</element>" 248 + "</root>");249 250 validationContext.setSchemaValidation(false);251 252 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();253 validationContexts.add(validationContext);254 receiveMessageBean.setValidationContexts(validationContexts);255 receiveMessageBean.execute(context);256 }257 258 @Test259 @SuppressWarnings({ "unchecked", "rawtypes" })260 public void testDefaultNamespacesInSourceMessage() {261 reset(endpoint, consumer, endpointConfiguration);262 when(endpoint.createConsumer()).thenReturn(consumer);263 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);264 when(endpointConfiguration.getTimeout()).thenReturn(5000L);265 266 Message message = new DefaultMessage("<root xmlns='http://citrus'>"267 + "<element attributeA='attribute-value' attributeB='attribute-value'>"268 + "<sub-element attribute='A'>text-value</sub-element>"269 + "</element>" 270 + "</root>");271 272 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);273 when(endpoint.getActor()).thenReturn(null);274 275 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();276 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();277 receiveMessageBean.setMessageBuilder(controlMessageBuilder);278 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus'>"279 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"280 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"281 + "</ns1:element>" 282 + "</ns1:root>");283 284 validationContext.setSchemaValidation(false);285 286 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();287 validationContexts.add(validationContext);288 receiveMessageBean.setValidationContexts(validationContexts);289 receiveMessageBean.execute(context);290 }291 292 @Test(expectedExceptions = {ValidationException.class})293 @SuppressWarnings({ "unchecked", "rawtypes" })294 public void testMissingNamespace() {295 reset(endpoint, consumer, endpointConfiguration);296 when(endpoint.createConsumer()).thenReturn(consumer);297 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);298 when(endpointConfiguration.getTimeout()).thenReturn(5000L);299 300 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus'>"301 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"302 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"303 + "</ns1:element>" 304 + "</ns1:root>");305 306 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);307 when(endpoint.getActor()).thenReturn(null);308 309 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();310 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();311 receiveMessageBean.setMessageBuilder(controlMessageBuilder);312 controlMessageBuilder.setPayloadData("<root>"313 + "<element attributeA='attribute-value' attributeB='attribute-value'>"314 + "<sub-element attribute='A'>text-value</sub-element>"315 + "</element>" 316 + "</root>");317 318 validationContext.setSchemaValidation(false);319 320 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();321 validationContexts.add(validationContext);322 receiveMessageBean.setValidationContexts(validationContexts);323 receiveMessageBean.execute(context);324 }325 326 @Test(expectedExceptions = {ValidationException.class})327 @SuppressWarnings({ "unchecked", "rawtypes" })328 public void testWrongNamespace() {329 reset(endpoint, consumer, endpointConfiguration);330 when(endpoint.createConsumer()).thenReturn(consumer);331 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);332 when(endpointConfiguration.getTimeout()).thenReturn(5000L);333 334 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus'>"335 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"336 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"337 + "</ns1:element>" 338 + "</ns1:root>");339 340 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);341 when(endpoint.getActor()).thenReturn(null);342 343 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();344 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();345 receiveMessageBean.setMessageBuilder(controlMessageBuilder);346 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus/wrong'>"347 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"348 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"349 + "</ns1:element>" 350 + "</ns1:root>");351 352 validationContext.setSchemaValidation(false);353 354 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();355 validationContexts.add(validationContext);356 receiveMessageBean.setValidationContexts(validationContexts);357 receiveMessageBean.execute(context);358 }359 360 @Test361 @SuppressWarnings({ "unchecked", "rawtypes" })362 public void testExpectDefaultNamespace() {363 reset(endpoint, consumer, endpointConfiguration);364 when(endpoint.createConsumer()).thenReturn(consumer);365 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);366 when(endpointConfiguration.getTimeout()).thenReturn(5000L);367 368 Message message = new DefaultMessage("<root xmlns='http://citrus'>"369 + "<element attributeA='attribute-value' attributeB='attribute-value'>"370 + "<sub-element attribute='A'>text-value</sub-element>"371 + "</element>" 372 + "</root>");373 374 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);375 when(endpoint.getActor()).thenReturn(null);376 377 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();378 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();379 receiveMessageBean.setMessageBuilder(controlMessageBuilder);380 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus'>"381 + "<element attributeA='attribute-value' attributeB='attribute-value'>"382 + "<sub-element attribute='A'>text-value</sub-element>"383 + "</element>" 384 + "</root>");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);889 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);890 when(endpointConfiguration.getTimeout()).thenReturn(5000L);891 892 Message message = new DefaultMessage("<root xmlns='http://citrus/default'>"893 + "<element attributeA='attribute-value' attributeB='attribute-value' >"894 + "<sub-elementA attribute='A'>text-value</sub-elementA>"895 + "<sub-elementB attribute='B'>text-value</sub-elementB>"896 + "<sub-elementC attribute='C'>text-value</sub-elementC>"897 + "</element>" 898 + "</root>");899 900 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);901 when(endpoint.getActor()).thenReturn(null);902 HashMap<String, Object> validateMessageElements = new HashMap<>();903 validateMessageElements.put("//ns1:root/ns1:element/ns1:sub-elementA", "text-value");904 validateMessageElements.put("//ns1:sub-elementB", "text-value");905 906 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();907 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();908 receiveMessageBean.setMessageBuilder(controlMessageBuilder);909 validationContext.setXpathExpressions(validateMessageElements);910 911 Map<String, String> namespaces = new HashMap<String, String>();912 namespaces.put("ns1", "http://citrus/default");913 914 validationContext.setNamespaces(namespaces);915 916 validationContext.setSchemaValidation(false);917 918 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();919 validationContexts.add(validationContext);920 receiveMessageBean.setValidationContexts(validationContexts);921 receiveMessageBean.execute(context);922 }923 924 @Test925 @SuppressWarnings({ "unchecked", "rawtypes" })926 public void testValidateMessageElementsWithDifferentNamespacePrefix() {927 reset(endpoint, consumer, endpointConfiguration);928 when(endpoint.createConsumer()).thenReturn(consumer);929 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);930 when(endpointConfiguration.getTimeout()).thenReturn(5000L);931 932 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus/default'>"933 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value' >"934 + "<ns1:sub-elementA attribute='A'>text-value</ns1:sub-elementA>"935 + "<ns1:sub-elementB attribute='B'>text-value</ns1:sub-elementB>"936 + "<ns1:sub-elementC attribute='C'>text-value</ns1:sub-elementC>"937 + "</ns1:element>" 938 + "</ns1:root>");939 940 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);941 when(endpoint.getActor()).thenReturn(null);942 HashMap<String, Object> validateMessageElements = new HashMap<>();943 validateMessageElements.put("//pfx:root/pfx:element/pfx:sub-elementA", "text-value");944 validateMessageElements.put("//pfx:sub-elementB", "text-value");945 946 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();947 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();948 receiveMessageBean.setMessageBuilder(controlMessageBuilder);949 validationContext.setXpathExpressions(validateMessageElements);950 951 Map<String, String> namespaces = new HashMap<String, String>();952 namespaces.put("pfx", "http://citrus/default");953 954 validationContext.setNamespaces(namespaces);955 956 validationContext.setSchemaValidation(false);957 958 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();959 validationContexts.add(validationContext);960 receiveMessageBean.setValidationContexts(validationContexts);961 receiveMessageBean.execute(context);962 }963 964 @Test(expectedExceptions = {CitrusRuntimeException.class})965 @SuppressWarnings({ "unchecked", "rawtypes" })966 public void testWrongNamespaceContext() {967 reset(endpoint, consumer, endpointConfiguration);968 when(endpoint.createConsumer()).thenReturn(consumer);969 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);970 when(endpointConfiguration.getTimeout()).thenReturn(5000L);971 972 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus/default'>"973 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value' >"974 + "<ns1:sub-elementA attribute='A'>text-value</ns1:sub-elementA>"975 + "<ns1:sub-elementB attribute='B'>text-value</ns1:sub-elementB>"976 + "<ns1:sub-elementC attribute='C'>text-value</ns1:sub-elementC>"977 + "</ns1:element>" 978 + "</ns1:root>");979 980 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);981 when(endpoint.getActor()).thenReturn(null);982 HashMap<String, Object> validateMessageElements = new HashMap<>();983 validateMessageElements.put("//pfx:root/ns1:element/pfx:sub-elementA", "text-value");984 validateMessageElements.put("//pfx:sub-elementB", "text-value");985 986 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();987 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();988 receiveMessageBean.setMessageBuilder(controlMessageBuilder);989 validationContext.setXpathExpressions(validateMessageElements);990 991 Map<String, String> namespaces = new HashMap<String, String>();992 namespaces.put("pfx", "http://citrus/wrong");993 994 validationContext.setNamespaces(namespaces);995 996 validationContext.setSchemaValidation(false);997 998 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();999 validationContexts.add(validationContext);1000 receiveMessageBean.setValidationContexts(validationContexts);1001 receiveMessageBean.execute(context);1002 }1003}...
Source:ReceiveMessageBuilder.java
...479 * @param enabled480 * @return481 */482 public T schemaValidation(boolean enabled) {483 xmlMessageValidationContext.setSchemaValidation(enabled);484 jsonMessageValidationContext.setSchemaValidation(enabled);485 return self;486 }487 /**488 * Validates XML namespace with prefix and uri.489 * @param prefix490 * @param namespaceUri491 * @return492 */493 public T validateNamespace(String prefix, String namespaceUri) {494 xmlMessageValidationContext.getControlNamespaces().put(prefix, namespaceUri);495 return self;496 }497 498 /**499 * Adds message element validation.500 * @param path501 * @param controlValue502 * @return503 */504 public T validate(String path, Object controlValue) {505 if (JsonPathMessageValidationContext.isJsonPathExpression(path)) {506 getJsonPathValidationContext().getJsonPathExpressions().put(path, controlValue);507 } else {508 getXPathValidationContext().getXpathExpressions().put(path, controlValue);509 }510 return self;511 }512 513 /**514 * Adds ignore path expression for message element.515 * @param path516 * @return517 */518 public T ignore(String path) {519 if (messageType.equalsIgnoreCase(MessageType.XML.name())520 || messageType.equalsIgnoreCase(MessageType.XHTML.name())) {521 xmlMessageValidationContext.getIgnoreExpressions().add(path);522 } else if (messageType.equalsIgnoreCase(MessageType.JSON.name())) {523 jsonMessageValidationContext.getIgnoreExpressions().add(path);524 }525 return self;526 }527 528 /**529 * Adds XPath message element validation.530 * @param xPathExpression531 * @param controlValue532 * @return533 */534 public T xpath(String xPathExpression, Object controlValue) {535 validate(xPathExpression, controlValue);536 return self;537 }538 /**539 * Adds JsonPath message element validation.540 * @param jsonPathExpression541 * @param controlValue542 * @return543 */544 public T jsonPath(String jsonPathExpression, Object controlValue) {545 validate(jsonPathExpression, controlValue);546 return self;547 }548 549 /**550 * Sets explicit schema instance name to use for schema validation.551 * @param schemaName552 * @return553 */554 public T xsd(String schemaName) {555 xmlMessageValidationContext.setSchema(schemaName);556 return self;557 }558 /**559 * Sets explicit schema instance name to use for schema validation.560 * @param schemaName The name of the schema bean561 */562 public T jsonSchema(String schemaName) {563 jsonMessageValidationContext.setSchema(schemaName);564 return self;565 }566 567 /**568 * Sets explicit xsd schema repository instance to use for validation.569 * @param schemaRepository570 * @return571 */572 public T xsdSchemaRepository(String schemaRepository) {573 xmlMessageValidationContext.setSchemaRepository(schemaRepository);574 return self;575 }576 /**577 * Sets explicit json schema repository instance to use for validation.578 * @param schemaRepository The name of the schema repository bean579 * @return580 */581 public T jsonSchemaRepository(String schemaRepository) {582 jsonMessageValidationContext.setSchemaRepository(schemaRepository);583 return self;584 }585 586 /**587 * Adds explicit namespace declaration for later path validation expressions.588 * @param prefix589 * @param namespaceUri590 * @return591 */592 public T namespace(String prefix, String namespaceUri) {593 getXpathVariableExtractor().getNamespaces().put(prefix, namespaceUri);594 xmlMessageValidationContext.getNamespaces().put(prefix, namespaceUri);595 return self;596 }597 598 /**599 * Sets default namespace declarations on this action builder.600 * @param namespaceMappings601 * @return602 */603 public T namespaces(Map<String, String> namespaceMappings) {604 getXpathVariableExtractor().getNamespaces().putAll(namespaceMappings);605 xmlMessageValidationContext.getNamespaces().putAll(namespaceMappings);606 return self;607 }608 609 /**610 * Sets message selector string.611 * @param messageSelector612 * @return613 */614 public T selector(String messageSelector) {615 getAction().setMessageSelector(messageSelector);616 return self;617 }618 619 /**620 * Sets message selector elements.621 * @param messageSelector622 * @return623 */624 public T selector(Map<String, Object> messageSelector) {625 getAction().setMessageSelectorMap(messageSelector);626 return self;627 }628 629 /**630 * Sets explicit message validators for this receive action.631 * @param validators632 * @return633 */634 public T validator(MessageValidator<? extends ValidationContext> ... validators) {635 Stream.of(validators).forEach(getAction()::addValidator);636 return self;637 }638 639 /**640 * Sets explicit message validators by name.641 * @param validatorNames642 * @return643 */644 @SuppressWarnings("unchecked")645 public T validator(String ... validatorNames) {646 Assert.notNull(applicationContext, "Citrus application context is not initialized!");647 for (String validatorName : validatorNames) {648 getAction().addValidator(applicationContext.getBean(validatorName, MessageValidator.class));649 }650 return self;651 }652 /**653 * Sets explicit header validator for this receive action.654 * @param validators655 * @return656 */657 public T headerValidator(HeaderValidator... validators) {658 Stream.of(validators).forEach(headerValidationContext::addHeaderValidator);659 return self;660 }661 /**662 * Sets explicit header validators by name.663 * @param validatorNames664 * @return665 */666 @SuppressWarnings("unchecked")667 public T headerValidator(String ... validatorNames) {668 Assert.notNull(applicationContext, "Citrus application context is not initialized!");669 for (String validatorName : validatorNames) {670 headerValidationContext.addHeaderValidator(applicationContext.getBean(validatorName, HeaderValidator.class));671 }672 return self;673 }674 /**675 * Sets explicit data dictionary for this receive action.676 * @param dictionary677 * @return678 */679 public T dictionary(DataDictionary dictionary) {680 getAction().setDataDictionary(dictionary);681 return self;682 }683 /**684 * Sets explicit data dictionary by name.685 * @param dictionaryName686 * @return687 */688 @SuppressWarnings("unchecked")689 public T dictionary(String dictionaryName) {690 Assert.notNull(applicationContext, "Citrus application context is not initialized!");691 DataDictionary dictionary = applicationContext.getBean(dictionaryName, DataDictionary.class);692 getAction().setDataDictionary(dictionary);693 return self;694 }695 696 /**697 * Extract message header entry as variable.698 * @param headerName699 * @param variable700 * @return701 */702 public T extractFromHeader(String headerName, String variable) {703 if (headerExtractor == null) {704 headerExtractor = new MessageHeaderVariableExtractor();705 getAction().getVariableExtractors().add(headerExtractor);706 }707 708 headerExtractor.getHeaderMappings().put(headerName, variable);709 return self;710 }711 712 /**713 * Extract message element via XPath or JSONPath from message payload as new test variable.714 * @param path715 * @param variable716 * @return717 */718 public T extractFromPayload(String path, String variable) {719 if (JsonPathMessageValidationContext.isJsonPathExpression(path)) {720 getJsonPathVariableExtractor().getJsonPathExpressions().put(path, variable);721 } else {722 getXpathVariableExtractor().getXpathExpressions().put(path, variable);723 }724 return self;725 }726 727 /**728 * Adds validation callback to the receive action for validating 729 * the received message with Java code.730 * @param callback731 * @return732 */733 public T validationCallback(ValidationCallback callback) {734 if (callback instanceof ApplicationContextAware) {735 ((ApplicationContextAware) callback).setApplicationContext(applicationContext);736 }737 getAction().setValidationCallback(callback);738 return self;739 }740 /**741 * Sets the Spring bean application context.742 * @param applicationContext743 */744 public T withApplicationContext(ApplicationContext applicationContext) {745 this.applicationContext = applicationContext;746 return self;747 }748 /**749 * Get message builder, if already registered or create a new message builder and register it750 *751 * @return the message builder in use752 */753 protected AbstractMessageContentBuilder getMessageContentBuilder() {754 if (getAction().getMessageBuilder() != null && getAction().getMessageBuilder() instanceof AbstractMessageContentBuilder) {755 return (AbstractMessageContentBuilder) getAction().getMessageBuilder();756 } else {757 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();758 getAction().setMessageBuilder(messageBuilder);759 return messageBuilder;760 }761 }762 /**763 * Creates new variable extractor and adds it to test action.764 */765 private XpathPayloadVariableExtractor getXpathVariableExtractor() {766 if (xpathExtractor == null) {767 xpathExtractor = new XpathPayloadVariableExtractor();768 getAction().getVariableExtractors().add(xpathExtractor);769 }770 return xpathExtractor;771 }772 /**773 * Creates new variable extractor and adds it to test action.774 */775 private JsonPathVariableExtractor getJsonPathVariableExtractor() {776 if (jsonPathExtractor == null) {777 jsonPathExtractor = new JsonPathVariableExtractor();778 getAction().getVariableExtractors().add(jsonPathExtractor);779 }780 return jsonPathExtractor;781 }782 /**783 * Gets the validation context as XML validation context an raises exception if existing validation context is784 * not a XML validation context.785 * @return786 */787 private XpathMessageValidationContext getXPathValidationContext() {788 if (xmlMessageValidationContext instanceof XpathMessageValidationContext) {789 return ((XpathMessageValidationContext)xmlMessageValidationContext);790 } else {791 XpathMessageValidationContext xPathContext = new XpathMessageValidationContext();792 xPathContext.setNamespaces(xmlMessageValidationContext.getNamespaces());793 xPathContext.setControlNamespaces(xmlMessageValidationContext.getControlNamespaces());794 xPathContext.setIgnoreExpressions(xmlMessageValidationContext.getIgnoreExpressions());795 xPathContext.setSchema(xmlMessageValidationContext.getSchema());796 xPathContext.setSchemaRepository(xmlMessageValidationContext.getSchemaRepository());797 xPathContext.setSchemaValidation(xmlMessageValidationContext.isSchemaValidationEnabled());798 xPathContext.setDTDResource(xmlMessageValidationContext.getDTDResource());799 getAction().getValidationContexts().remove(xmlMessageValidationContext);800 getAction().getValidationContexts().add(xPathContext);801 xmlMessageValidationContext = xPathContext;802 return xPathContext;803 }804 }805 /**806 * Creates new script validation context if not done before and gets the script validation context.807 */808 private ScriptValidationContext getScriptValidationContext() {809 if (scriptValidationContext == null) {810 scriptValidationContext = new ScriptValidationContext(messageType.toString());811 getAction().getValidationContexts().add(scriptValidationContext);...
setSchemaValidation
Using AI Code Generation
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.testng.AbstractTestNGUnitTest;7import com.consol.citrus.validation.context.ValidationContext;8import com.consol.citrus.validation.xml.XmlMessageValidationContext;9import org.testng.Assert;10import org.testng.annotations.Test;11import org.xml.sax.SAXException;12import javax.xml.parsers.ParserConfigurationException;13import java.io.IOException;14public class SetSchemaValidationTest extends AbstractTestNGUnitTest {15 public void testSetSchemaValidation() throws IOException, SAXException, ParserConfigurationException {16 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();17 validationContext.setSchemaValidation(false);18 Message message = new Message("<TestMessage><Text>Hello World!</Text></TestMessage>").setMessageType(MessageType.XML.name());19 Assert.assertFalse(validationContext.isSchemaValidation());20 validationContext.setSchemaValidation(true);21 Assert.assertTrue(validationContext.isSchemaValidation());22 try {23 validationContext.validateMessagePayload(message, message, context);24 } catch (CitrusRuntimeException e) {25 Assert.fail("An error occurred while validating the XML message payload.");
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.validation.xml;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.exceptions.ValidationException;4import com.consol.citrus.message.Message;5import com.consol.citrus.validation.context.ValidationContext;6import com.consol.citrus.validation.xml.XmlMessageValidationContext;7import org.springframework.util.StringUtils;8public class XmlSchemaValidationMatcher extends AbstractXmlMessageValidationMatcher {9 public void validateMessagePayload(Message receivedMessage, Message controlMessage, TestContext context, ValidationContext validationContext) throws ValidationException {10 if (!(validationContext instanceof XmlMessageValidationContext)) {11 throw new ValidationException("Validation context is not of type XmlMessageValidationContext");12 }13 XmlMessageValidationContext xmlValidationContext = (XmlMessageValidationContext) validationContext;14 if (StringUtils.hasText(xmlValidationContext.getSchema())) {15 if (xmlValidationContext.isSchemaValidation()) {16 super.validateMessagePayload(receivedMessage, controlMessage, context, validationContext);17 }18 } else {19 throw new ValidationException("Unable to validate XML schema - no schema resource defined in validation context");20 }21 }22}23package com.consol.citrus.validation.xml;24import com.consol.citrus.context.TestContext;25import com.consol.citrus.exceptions.ValidationException;26import com.consol.citrus.message.Message;27import com.consol.citrus.validation.context.ValidationContext;28import com.consol.citrus.validation.xml.XmlMessageValidationContext;29import org.springframework.util.StringUtils;30public class XmlSchemaValidationMatcher extends AbstractXmlMessageValidationMatcher {31 public void validateMessagePayload(Message receivedMessage, Message controlMessage, TestContext context, ValidationContext validationContext) throws ValidationException {32 if (!(validationContext
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.validation.xml;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.exceptions.ValidationException;4import com.consol.citrus.message.Message;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.validation.MessageValidator;7import com.consol.citrus.validation.context.ValidationContext;8import com.consol.citrus.validation.xml.XmlMessageValidationContext;9import com.consol.citrus.validation.xml.XmlMessageValidationUtils;10import org.slf4j.Logger;11import org.slf4j.LoggerFactory;12import org.springframework.util.xml.DomUtils;13import org.springframework.xml.validation.XmlValidator;14import org.springframework.xml.xsd.XsdSchema;15import org.w3c.dom.Document;16import org.w3c.dom.Element;17import org.xml.sax.SAXException;18import javax.xml.parsers.DocumentBuilder;19import javax.xml.parsers.ParserConfigurationException;20import javax.xml.transform.Source;21import javax.xml.transform.dom.DOMSource;22import javax.xml.validation.Schema;23import java.io.IOException;24import java.util.ArrayList;25import java.util.List;26import java.util.Map;27import java.util.Set;28public class XmlSchemaValidator implements MessageValidator<XmlMessageValidationContext> {29 private static Logger log = LoggerFactory.getLogger(XmlSchemaValidator.class);30 private final List<XmlSchemaValidationErrorHandler> validationErrorListeners = new ArrayList<XmlSchemaValidationErrorHandler>();31 private boolean schemaValidation = true;32 private String schemaLanguage = XmlMessageValidationContext.SCHEMA_LANGUAGE_XML_SCHEMA;33 private String schemaResourcePath;34 private Schema schema;35 private XsdSchema xsdSchema;36 private boolean schemaValidationEnabled = true;37 private boolean schemaValidationEnforced = true;38 private XmlValidator schemaValidator;39 private DocumentBuilder documentBuilder;40 public XmlSchemaValidator() {
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.validation.xml;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.message.Message;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.MessageValidator;6import com.consol.citrus.validation.context.ValidationContext;7import com.consol.citrus.validation.xml.XmlMessageValidationContext;8import org.springframework.util.StringUtils;9import org.springframework.xml.xsd.SimpleXsdSchema;10import org.springframework.xml.xsd.XsdSchema;11import org.testng.Assert;12import org.testng.annotations.Test;13import org.xml.sax.SAXException;14import java.io.IOException;15import java.util.Collections;16public class XmlMessageValidationContextTest {17 public void testSchemaValidation() throws IOException, SAXException {18 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();19 validationContext.setSchemaValidation(true);20 validationContext.setSchemaRepository(Collections.singletonMap("test", new SimpleXsdSchema(getClass().getResource("test.xsd"))));21 MessageValidator messageValidator = new XmlMessageValidator();22 messageValidator.setValidationContext(validationContext);23 Message controlMessage = new Message("<testMessage><text>Hello</text></testMessage>")24 .setHeader("operation", "sayHello")25 .setHeader("correlationId", "1234567890")26 .setMessageType(MessageType.XML.name());27 Message receivedMessage = new Message("<testMessage><text>Hello</text></testMessage>")28 .setHeader("operation", "sayHello")29 .setHeader("correlationId", "1234567890")30 .setMessageType(MessageType.XML.name());31 messageValidator.validateMessagePayload(controlMessage, receivedMessage, new TestContext());32 }33 public void testSchemaValidationFail() throws IOException, SAXException {34 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();35 validationContext.setSchemaValidation(true);36 validationContext.setSchemaRepository(Collections.singletonMap("test", new SimpleXsdSchema(getClass().getResource("test.xsd"))));37 MessageValidator messageValidator = new XmlMessageValidator();38 messageValidator.setValidationContext(validationContext);39 Message controlMessage = new Message("<testMessage><text>Hello</text></testMessage>")40 .setHeader("operation", "sayHello")
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.dsl.testng;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.testng.CitrusParameters;4import com.consol.citrus.xml.namespace.NamespaceContextBuilder;5import com.consol.citrus.xml.schema.XsdSchemaRepository;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.ClassPathResource;8import org.springframework.http.HttpStatus;9import org.springframework.http.MediaType;10import org.testng.annotations.Test;11public class SetSchemaValidationTestNGIT extends AbstractTestNGCitrusTest {12 private XsdSchemaRepository schemaRepository;13 @CitrusParameters({"name"})14 public void SetSchemaValidation(String name) {15 variable("name", name);16 variable("schemaLocation", "classpath:com/consol/citrus/dsl/runner/echo.xsd");17 variable("namespacePrefix", "tns");18 echo("SetSchemaValidation");19 http(httpActionBuilder -> httpActionBuilder20 .client("httpClient")21 .send()22 .post()23 .contentType(MediaType.APPLICATION_XML_VALUE)24 + "<tns:text>${name}</tns:text>"25 + "</tns:echoRequest>"));26 http(httpActionBuilder -> httpActionBuilder27 .client("httpClient")28 .receive()29 .response(HttpStatus.OK)30 .schemaValidation(true)31 .schemaRepository(schemaRepository)32 .schemaValidationContext(xmlMessageValidationContextBuilder -> xmlMessageValidationContextBuilder33 .namespaceContextBuilder(new NamespaceContextBuilder()34 + "<tns:text>Hello ${name}!</tns:text>"35 + "</tns:echoResponse>"));36 }37}
setSchemaValidation
Using AI Code Generation
1public class 4 {2 public static void main(String[] args) {3 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();4 xmlMessageValidationContext.setSchemaValidation(true);5 }6}7public class 5 {8 public static void main(String[] args) {9 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();10 xmlMessageValidationContext.setSchemaValidation(true);11 }12}13public class 6 {14 public static void main(String[] args) {15 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();16 xmlMessageValidationContext.setSchemaValidation(true);17 }18}19public class 7 {20 public static void main(String[] args) {21 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();22 xmlMessageValidationContext.setSchemaValidation(true);23 }24}25public class 8 {26 public static void main(String[] args) {27 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();28 xmlMessageValidationContext.setSchemaValidation(true);29 }30}31public class 9 {32 public static void main(String[] args) {33 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();34 xmlMessageValidationContext.setSchemaValidation(true);35 }36}
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.dsl.runner;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;7public class SetSchemaValidationIT extends TestNGCitrusTestDesigner {8 public void setSchemaValidation() {9 variable("myVariable", "value");10 http()11 .client("httpClient")12 .send()13 .post("/test")14 .payload("<TestRequestMessage>" +15 "</TestRequestMessage>");16 http()17 .client("httpClient")18 .receive()19 .response(HttpStatus.OK)20 .payload("<TestResponseMessage>" +21 "</TestResponseMessage>");22 http()23 .client("httpClient")24 .send()25 .post("/test")26 .payload("<TestRequestMessage>" +27 "</TestRequestMessage>");28 http()29 .client("httpClient")30 .receive()31 .response(HttpStatus.OK)32 .payload("<TestResponseMessage>" +33 "</TestResponseMessage>");34 http()35 .client("httpClient")36 .send()37 .post("/test")38 .payload("<TestRequestMessage>" +39 "</TestRequestMessage>");40 http()41 .client("httpClient")42 .receive()43 .response(HttpStatus.OK)44 .payload("<TestResponseMessage>" +45 "</TestResponseMessage>");46 http()47 .client("httpClient")48 .send()49 .post("/test")50 .payload("<TestRequestMessage>" +51 "</TestRequestMessage>");52 http()53 .client("httpClient")54 .receive()55 .response(HttpStatus.OK)56 .payload("<TestResponseMessage>" +57 "</TestResponseMessage>");58 http()59 .client("httpClient")60 .send()61 .post("/test")62 .payload("<TestRequestMessage>" +63 "</TestRequestMessage>");64 http()
setSchemaValidation
Using AI Code Generation
1import com.consol.citrus.dsl.runner.TestRunner;2import com.consol.citrus.dsl.builder.BuilderSupport;3import com.consol.citrus.dsl.design.TestDesigner;4import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;5import com.consol.citrus.dsl.builder.AbstractTestBehaviorBuilder;6import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;7import com.consol.citrus.dsl.builder.SendMessageActionBuilder;8import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder;9import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder;10import com.consol.citrus.dsl.builder.EchoActionBuilder;11import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder;12import com.consol.citrus.dsl.builder.PurgeJmsTopicsActionBuilder;13import com.consol.citrus.dsl.builder.PurgeMessageChannelsActionBuilder;14import com.consol.citrus.dsl.builder.StopTimeActionBuilder;15import com.consol.citrus.dsl.builder.StartTimeActionBuilder;16import com.consol.citrus.dsl.builder.FailActionBuilder;17import com.consol.citrus.dsl.builder.SleepActionBuilder;18import com.consol.citrus.dsl.builder.ParallelBuilder;19import com.consol.citrus.dsl.builder.SequenceBuilder;20import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder.CreateVariablesActionBuilderSupport;21import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder.CreateVariablesActionBuilderImpl;22import com.consol.citrus.dsl.builder.EchoActionBuilder.EchoActionBuilderSupport;23import com.consol.citrus.dsl.builder.EchoActionBuilder.EchoActionBuilderImpl;24import com.consol.citrus.dsl.builder.FailActionBuilder.FailActionBuilderSupport;25import com.consol.citrus.dsl.builder.FailActionBuilder.FailActionBuilderImpl;26import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder.PurgeEndpointActionBuilderSupport;27import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder.PurgeEndpointActionBuilderImpl;28import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder.PurgeJmsQueuesActionBuilderSupport;29import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder.PurgeJmsQueuesActionBuilderImpl;30import com.consol.citrus.dsl.builder.PurgeJmsTopicsActionBuilder.PurgeJmsTopicsActionBuilderSupport;31import com
setSchemaValidation
Using AI Code Generation
1public class 4.java {2public void configure() {3setSchemaValidation(true);4}5}6public class 5.java {7public void configure() {8setSchemaValidation(false);9}10}11public class 6.java {12public void configure() {13setSchemaValidation(true);14}15}16public class 7.java {17public void configure() {18setSchemaValidation(false);19}20}21public class 8.java {22public void configure() {23setSchemaValidation(true);24}25}26public class 9.java {27public void configure() {28setSchemaValidation(false);29}30}31public class 10.java {32public void configure() {33setSchemaValidation(true);34}35}
setSchemaValidation
Using AI Code Generation
1public void validateWithSchemaValidation() {2 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();3 validationContext.setSchemaValidation(true);4 context.setValidationContext(validationContext);5 send("sendRequest");6 receive("receiveResponse");7}8public void validateWithSchemaValidation() {9 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();10 validationContext.setSchemaValidation(true);11 context.setValidationContext(validationContext);12 send("sendRequest");13 receive("receiveResponse");14}15public void validateWithSchemaValidation() {16 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();17 validationContext.setSchemaValidation(true);18 context.setValidationContext(validationContext);19 send("sendRequest");20 receive("receiveResponse");21}22public void validateWithSchemaValidation() {23 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();24 validationContext.setSchemaValidation(true);25 context.setValidationContext(validationContext);26 send("sendRequest");27 receive("receiveResponse");28}29public void validateWithSchemaValidation() {30 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();31 validationContext.setSchemaValidation(true);32 context.setValidationContext(validationContext);33 send("sendRequest");34 receive("receiveResponse");35}36public void validateWithSchemaValidation() {37 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();38 validationContext.setSchemaValidation(true);39 context.setValidationContext(validationContext);40 send("sendRequest");41 receive("receiveResponse");42}43 public XmlSchemaValidator() {
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.validation.xml;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.message.Message;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.MessageValidator;6import com.consol.citrus.validation.context.ValidationContext;7import com.consol.citrus.validation.xml.XmlMessageValidationContext;8import org.springframework.util.StringUtils;9import org.springframework.xml.xsd.SimpleXsdSchema;10import org.springframework.xml.xsd.XsdSchema;11import org.testng.Assert;12import org.testng.annotations.Test;13import org.xml.sax.SAXException;14import java.io.IOException;15import java.util.Collections;16public class XmlMessageValidationContextTest {17 public void testSchemaValidation() throws IOException, SAXException {18 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();19 validationContext.setSchemaValidation(true);20 validationContext.setSchemaRepository(Collections.singletonMap("test", new SimpleXsdSchema(getClass().getResource("test.xsd"))));21 MessageValidator messageValidator = new XmlMessageValidator();22 messageValidator.setValidationContext(validationContext);23 Message controlMessage = new Message("<testMessage><text>Hello</text></testMessage>")24 .setHeader("operation", "sayHello")25 .setHeader("correlationId", "1234567890")26 .setMessageType(MessageType.XML.name());27 Message receivedMessage = new Message("<testMessage><text>Hello</text></testMessage>")28 .setHeader("operation", "sayHello")29 .setHeader("correlationId", "1234567890")30 .setMessageType(MessageType.XML.name());31 messageValidator.validateMessagePayload(controlMessage, receivedMessage, new TestContext());32 }33 public void testSchemaValidationFail() throws IOException, SAXException {34 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();35 validationContext.setSchemaValidation(true);36 validationContext.setSchemaRepository(Collections.singletonMap("test", new SimpleXsdSchema(getClass().getResource("test.xsd"))));37 MessageValidator messageValidator = new XmlMessageValidator();38 messageValidator.setValidationContext(validationContext);39 Message controlMessage = new Message("<testMessage><text>Hello</text></testMessage>")40 .setHeader("operation", "sayHello")
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.dsl.testng;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.testng.CitrusParameters;4import com.consol.citrus.xml.namespace.NamespaceContextBuilder;5import com.consol.citrus.xml.schema.XsdSchemaRepository;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.ClassPathResource;8import org.springframework.http.HttpStatus;9import org.springframework.http.MediaType;10import org.testng.annotations.Test;11public class SetSchemaValidationTestNGIT extends AbstractTestNGCitrusTest {12 private XsdSchemaRepository schemaRepository;13 @CitrusParameters({"name"})14 public void SetSchemaValidation(String name) {15 variable("name", name);16 variable("schemaLocation", "classpath:com/consol/citrus/dsl/runner/echo.xsd");17 variable("namespacePrefix", "tns");18 echo("SetSchemaValidation");19 http(httpActionBuilder -> httpActionBuilder20 .client("httpClient")21 .send()22 .post()23 .contentType(MediaType.APPLICATION_XML_VALUE)24 + "<tns:text>${name}</tns:text>"25 + "</tns:echoRequest>"));26 http(httpActionBuilder -> httpActionBuilder27 .client("httpClient")28 .receive()29 .response(HttpStatus.OK)30 .schemaValidation(true)31 .schemaRepository(schemaRepository)32 .schemaValidationContext(xmlMessageValidationContextBuilder -> xmlMessageValidationContextBuilder33 .namespaceContextBuilder(new NamespaceContextBuilder()34 + "<tns:text>Hello ${name}!</tns:text>"35 + "</tns:echoResponse>"));36 }37}
setSchemaValidation
Using AI Code Generation
1public class 4 {2 public static void main(String[] args) {3 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();4 xmlMessageValidationContext.setSchemaValidation(true);5 }6}7public class 5 {8 public static void main(String[] args) {9 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();10 xmlMessageValidationContext.setSchemaValidation(true);11 }12}13public class 6 {14 public static void main(String[] args) {15 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();16 xmlMessageValidationContext.setSchemaValidation(true);17 }18}19public class 7 {20 public static void main(String[] args) {21 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();22 xmlMessageValidationContext.setSchemaValidation(true);23 }24}25public class 8 {26 public static void main(String[] args) {27 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();28 xmlMessageValidationContext.setSchemaValidation(true);29 }30}31public class 9 {32 public static void main(String[] args) {33 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();34 xmlMessageValidationContext.setSchemaValidation(true);35 }36}
setSchemaValidation
Using AI Code Generation
1import com.consol.citrus.dsl.runner.TestRunner;2import com.consol.citrus.dsl.builder.BuilderSupport;3import com.consol.citrus.dsl.design.TestDesigner;4import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;5import com.consol.citrus.dsl.builder.AbstractTestBehaviorBuilder;6import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;7import com.consol.citrus.dsl.builder.SendMessageActionBuilder;8import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder;9import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder;10import com.consol.citrus.dsl.builder.EchoActionBuilder;11import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder;12import com.consol.citrus.dsl.builder.PurgeJmsTopicsActionBuilder;13import com.consol.citrus.dsl.builder.PurgeMessageChannelsActionBuilder;14import com.consol.citrus.dsl.builder.StopTimeActionBuilder;15import com.consol.citrus.dsl.builder.StartTimeActionBuilder;16import com.consol.citrus.dsl.builder.FailActionBuilder;17import com.consol.citrus.dsl.builder.SleepActionBuilder;18import com.consol.citrus.dsl.builder.ParallelBuilder;19import com.consol.citrus.dsl.builder.SequenceBuilder;20import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder.CreateVariablesActionBuilderSupport;21import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder.CreateVariablesActionBuilderImpl;22import com.consol.citrus.dsl.builder.EchoActionBuilder.EchoActionBuilderSupport;23import com.consol.citrus.dsl.builder.EchoActionBuilder.EchoActionBuilderImpl;24import com.consol.citrus.dsl.builder.FailActionBuilder.FailActionBuilderSupport;25import com.consol.citrus.dsl.builder.FailActionBuilder.FailActionBuilderImpl;26import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder.PurgeEndpointActionBuilderSupport;27import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder.PurgeEndpointActionBuilderImpl;28import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder.PurgeJmsQueuesActionBuilderSupport;29import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder.PurgeJmsQueuesActionBuilderImpl;30import com.consol.citrus.dsl.builder.PurgeJmsTopicsActionBuilder.PurgeJmsTopicsActionBuilderSupport;31import com
setSchemaValidation
Using AI Code Generation
1public class 4.java {2public void configure() {3setSchemaValidation(true);4}5}6public class 5.java {7public void configure() {8setSchemaValidation(false);9}10}11public class 6.java {12public void configure() {13setSchemaValidation(true);14}15}16public class 7.java {17public void configure() {18setSchemaValidation(false);19}20}21public class 8.java {22public void configure() {23setSchemaValidation(true);24}25}26public class 9.java {27public void configure() {28setSchemaValidation(false);29}30}31public class 10.java {32public void configure() {33setSchemaValidation(true);34}35}
setSchemaValidation
Using AI Code Generation
1public void validateWithSchemaValidation() {2 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();3 validationContext.setSchemaValidation(true);4 context.setValidationContext(validationContext);5 send("sendRequest");6 receive("receiveResponse");7}8public void validateWithSchemaValidation() {9 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();10 validationContext.setSchemaValidation(true);11 context.setValidationContext(validationContext);12 send("sendRequest");13 receive("receiveResponse");14}15public void validateWithSchemaValidation() {16 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();17 validationContext.setSchemaValidation(true);18 context.setValidationContext(validationContext);19 send("sendRequest");20 receive("receiveResponse");21}22public void validateWithSchemaValidation() {23 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();24 validationContext.setSchemaValidation(true);25 context.setValidationContext(validationContext);26 send("sendRequest");27 receive("receiveResponse");28}29public void validateWithSchemaValidation() {30 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();31 validationContext.setSchemaValidation(true);32 context.setValidationContext(validationContext);33 send("sendRequest");34 receive("receiveResponse");35}36public void validateWithSchemaValidation() {37 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();38 validationContext.setSchemaValidation(true);39 context.setValidationContext(validationContext);40 send("sendRequest");41 receive("receiveResponse");42}
setSchemaValidation
Using AI Code Generation
1import com.consol.citrus.dsl.runner.TestRunner;2import com.consol.citrus.dsl.builder.BuilderSupport;3import com.consol.citrus.dsl.design.TestDesigner;4import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;5import com.consol.citrus.dsl.builder.AbstractTestBehaviorBuilder;6import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;7import com.consol.citrus.dsl.builder.SendMessageActionBuilder;8import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder;9import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder;10import com.consol.citrus.dsl.builder.EchoActionBuilder;11import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder;12import com.consol.citrus.dsl.builder.PurgeJmsTopicsActionBuilder;13import com.consol.citrus.dsl.builder.PurgeMessageChannelsActionBuilder;14import com.consol.citrus.dsl.builder.StopTimeActionBuilder;15import com.consol.citrus.dsl.builder.StartTimeActionBuilder;16import com.consol.citrus.dsl.builder.FailActionBuilder;17import com.consol.citrus.dsl.builder.SleepActionBuilder;18import com.consol.citrus.dsl.builder.ParallelBuilder;19import com.consol.citrus.dsl.builder.SequenceBuilder;20import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder.CreateVariablesActionBuilderSupport;21import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder.CreateVariablesActionBuilderImpl;22import com.consol.citrus.dsl.builder.EchoActionBuilder.EchoActionBuilderSupport;23import com.consol.citrus.dsl.builder.EchoActionBuilder.EchoActionBuilderImpl;24import com.consol.citrus.dsl.builder.FailActionBuilder.FailActionBuilderSupport;25import com.consol.citrus.dsl.builder.FailActionBuilder.FailActionBuilderImpl;26import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder.PurgeEndpointActionBuilderSupport;27import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder.PurgeEndpointActionBuilderImpl;28import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder.PurgeJmsQueuesActionBuilderSupport;29import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder.PurgeJmsQueuesActionBuilderImpl;30import com.consol.citrus.dsl.builder.PurgeJmsTopicsActionBuilder.PurgeJmsTopicsActionBuilderSupport;31import com
setSchemaValidation
Using AI Code Generation
1public class 4.java {2public void configure() {3setSchemaValidation(true);4}5}6public class 5.java {7public void configure() {8setSchemaValidation(false);9}10}11public class 6.java {12public void configure() {13setSchemaValidation(true);14}15}16public class 7.java {17public void configure() {18setSchemaValidation(false);19}20}21public class 8.java {22public void configure() {23setSchemaValidation(true);24}25}26public class 9.java {27public void configure() {28setSchemaValidation(false);29}30}31public class 10.java {32public void configure() {33setSchemaValidation(true);34}35}
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.validation.xml;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.exceptions.ValidationException;4import com.consol.citrus.message.Message;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.validation.MessageValidator;7import com.consol.citrus.validation.context.ValidationContext;8import com.consol.citrus.validation.xml.XmlMessageValidationContext;9import com.consol.citrus.validation.xml.XmlMessageValidationUtils;10import org.slf4j.Logger;11import org.slf4j.LoggerFactory;12import org.springframework.util.xml.DomUtils;13import org.springframework.xml.validation.XmlValidator;14import org.springframework.xml.xsd.XsdSchema;15import org.w3c.dom.Document;16import org.w3c.dom.Element;17import org.xml.sax.SAXException;18import javax.xml.parsers.DocumentBuilder;19import javax.xml.parsers.ParserConfigurationException;20import javax.xml.transform.Source;21import javax.xml.transform.dom.DOMSource;22import javax.xml.validation.Schema;23import java.io.IOException;24import java.util.ArrayList;25import java.util.List;26import java.util.Map;27import java.util.Set;28public class XmlSchemaValidator implements MessageValidator<XmlMessageValidationContext> {29 private static Logger log = LoggerFactory.getLogger(XmlSchemaValidator.class);30 private final List<XmlSchemaValidationErrorHandler> validationErrorListeners = new ArrayList<XmlSchemaValidationErrorHandler>();31 private boolean schemaValidation = true;32 private String schemaLanguage = XmlMessageValidationContext.SCHEMA_LANGUAGE_XML_SCHEMA;33 private String schemaResourcePath;34 private Schema schema;35 private XsdSchema xsdSchema;36 private boolean schemaValidationEnabled = true;37 private boolean schemaValidationEnforced = true;38 private XmlValidator schemaValidator;39 private DocumentBuilder documentBuilder;40 public XmlSchemaValidator() {
setSchemaValidation
Using AI Code Generation
1package com.consol.citrus.dsl.testng;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.testng.CitrusParameters;4import com.consol.citrus.xml.namespace.NamespaceContextBuilder;5import com.consol.citrus.xml.schema.XsdSchemaRepository;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.ClassPathResource;8import org.springframework.http.HttpStatus;9import org.springframework.http.MediaType;10import org.testng.annotations.Test;11public class SetSchemaValidationTestNGIT extends AbstractTestNGCitrusTest {12 private XsdSchemaRepository schemaRepository;13 @CitrusParameters({"name"})14 public void SetSchemaValidation(String name) {15 variable("name", name);16 variable("schemaLocation", "classpath:com/consol/citrus/dsl/runner/echo.xsd");17 variable("namespacePrefix", "tns");18 echo("SetSchemaValidation");19 http(httpActionBuilder -> httpActionBuilder20 .client("httpClient")21 .send()22 .post()23 .contentType(MediaType.APPLICATION_XML_VALUE)24 + "<tns:text>${name}</tns:text>"25 + "</tns:echoRequest>"));26 http(httpActionBuilder -> httpActionBuilder27 .client("httpClient")28 .receive()29 .response(HttpStatus.OK)30 .schemaValidation(true)31 .schemaRepository(schemaRepository)32 .schemaValidationContext(xmlMessageValidationContextBuilder -> xmlMessageValidationContextBuilder33 .namespaceContextBuilder(new NamespaceContextBuilder()34 + "<tns:text>Hello ${name}!</tns:text>"35 + "</tns:echoResponse>"));36 }37}
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!!