Best Citrus code snippet using com.consol.citrus.actions.ReceiveMessageAction.addVariableExtractors
Source:ReceiveMessageActionTest.java
...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 ...
Source:HeaderValuesTest.java
...359 360 MessageHeaderVariableExtractor variableExtractor = new MessageHeaderVariableExtractor();361 variableExtractor.setHeaderMappings(extractHeaderValues);362 363 receiveMessageBean.addVariableExtractors(variableExtractor);364 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();365 validationContexts.add(new HeaderValidationContext());366 validationContexts.add(validationContext);367 receiveMessageBean.setValidationContexts(validationContexts);368 369 receiveMessageBean.execute(context);370 371 Assert.assertTrue(context.getVariables().containsKey("valueA"));372 Assert.assertEquals(context.getVariables().get("valueA"), "A");373 Assert.assertTrue(context.getVariables().containsKey("valueB"));374 Assert.assertEquals(context.getVariables().get("valueB"), "B");375 }376}...
Source:ReceiveMessageAction.java
...319 /**320 * Adds a new variable extractor.321 * @param variableExtractor the variableExtractor to set322 */323 public ReceiveMessageAction addVariableExtractors(VariableExtractor variableExtractor) {324 this.variableExtractors.add(variableExtractor);325 return this;326 }327 /**328 * Set the list of variable extractors.329 * @param variableExtractors the variableExtractors to set330 */331 public ReceiveMessageAction setVariableExtractors(List<VariableExtractor> variableExtractors) {332 this.variableExtractors = variableExtractors;333 return this;334 }335 /**336 * Sets the list of available validation contexts for this action.337 * @param validationContexts the validationContexts to set...
addVariableExtractors
Using AI Code Generation
1package com.consol.citrus.dsl.testng;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;4import com.consol.citrus.dsl.builder.SendMessageActionBuilder;5import com.consol.citrus.dsl.runner.TestRunner;6import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;7import com.consol.citrus.message.MessageType;8import org.springframework.http.HttpStatus;9import org.testng.annotations.Test;10import java.util.HashMap;11import java.util.Map;12public class TestNGReceiveMessageActionBuilderTest extends TestNGCitrusTestDesigner {13 public void addVariableExtractors() {14 description("TestNG 2 - Receive message action builder");15 variable("operation", "sayHello");16 variable("name", "John Doe");17 echo("Hello Citrus!");18 parallel().actions(19 sequential().actions(20 send("greetingClient")21 .messageType(MessageType.PLAINTEXT)22 sequential().actions(23 receive("greetingService")24 .messageType(MessageType.PLAINTEXT)25 );26 http().client("httpClient")27 .send()28 .get("/greeting")29 .queryParam("operation", "${operation}")30 .queryParam("name", "${name}");31 http().client("httpClient")32 .receive()33 .response(HttpStatus.OK)34 .extractFromPayload("/ns0:GreetingResponse/ns0:Message/text()", "greeting");35 echo("${greeting}");36 http().client("httpClient")37 .send()38 .post("/greeting")39 .contentType("text/xml")
addVariableExtractors
Using AI Code Generation
1package com.consol.citrus;2import com.consol.citrus.actions.ReceiveMessageAction;3import com.consol.citrus.context.TestContext;4import com.consol.citrus.message.Message;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.message.MessageTypeResolver;7import com.consol.citrus.message.MessageTypeResolverChain;8import com.consol.citrus.message.MessageTypeResolverChainBuilder;9import com.consol.citrus.message.MessageTypeResolverChainBuilderTest;10import com.consol.citrus.message.MessageTypeResolverChainTest;11import com.consol.citrus.message.MessageTypeResolverTest;12import com.consol.citrus.message.builder.DefaultMessageBuilder;13import com.consol.citrus.message.builder.StaticMessageContentBuilder;14import com.consol.citrus.message.builder.TemplateMessageBuilder;15import com.consol.citrus.message.builder.VariableMessageBuilder;16import com.consol.citrus.message.builder.XMLMessageContentBuilder;17import com.consol.citrus.message.builder.XMLMessagePayloadBuilder;18import com.consol.citrus.message.builder.XpathMessageHeaderBuilder;19import com.consol.citrus.message.builder.XpathPayloadVariableExtractor;20import com.consol.citrus.message.builder.XpathPayloadVariableExtractorTest;21import com.consol.citrus.message.builder.XpathVariableExtractor;22import com.consol.citrus.message.builder.XpathVariableExtractorTest;23import com.consol.citrus.message.correlation.MessageCorrelator;24import com.consol.citrus.message.correlation.MessageCorrelatorTest;25import com.consol.citrus.message.correlation.ReplyMessageCorrelator;26import com.consol.citrus.message.correlation.ReplyMessageCorrelatorTest;27import com.consol.citrus.message.correlation.ReplyMessageCorrelatorTest.TestReplyMessageCorrelator;28import com.consol.citrus.message.correlation.ReplyMessageCorrelatorTest.TestReplyMessageCorrelatorWithTimeout;29import com.consol.citrus.message.correlation.ReplyMessageCorrelatorTest.TestReplyMessageCorrelatorWithTimeoutAndSelector;30import com.consol.citrus.message.correlation.ReplyMessageCorrelatorTest.TestReplyMessageCorrelatorWithTimeoutAndSelectorAndMessageSelector;31import com.consol.citrus.message.correlation.ReplyMessageCorrelatorTest.TestReplyMessageCorrelatorWithTimeoutAnd
addVariableExtractors
Using AI Code Generation
1package com.consol.citrus.samples;2import java.util.HashMap;3import java.util.Map;4import org.springframework.context.annotation.Bean;5import org.springframework.context.annotation.Configuration;6import org.springframework.context.annotation.Import;7import org.springframework.core.io.ClassPathResource;8import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;9import org.springframework.ws.soap.addressing.core.impl.MessageAddressingPropertiesImpl;10import org.springframework.ws.soap.addressing.version.Addressing10;11import org.springframework.ws.soap.addressing.version.Addressing10Impl;12import org.springframework.ws.soap.addressing.version.AddressingVersion;13import org.springframework.ws.soap.addressing.version.AddressingVersionStrategy;14import org.springframework.ws.soap.addressing.version.AddressingVersionStrategyImpl;15import org.springframework.ws.soap.addressing.version.AddressingVersionStrategySupport;16import org.springframework.ws.soap.addressing.version.AddressingVersionStrategySupportImpl;17import org.springframework.ws.soap.addressing.version.AddressingVersionUtils;18import org.springframework.ws.soap.addressing.version.AddressingVersionUtilsImpl;19import org.springframework.ws.soap.addressing.version.AddressingVersionUtilsSupport;20import org.springframework.ws.soap.addressing.version.AddressingVersionUtilsSupportImpl;21import org.springframework.ws.soap.addressing.version.SoapAddressing10;22import org.springframework.ws.soap.addressing.version.SoapAddressing11;23import org.springframework.ws.soap.addressing.version.SoapAddressing12;24import org.springframework.ws.soap.addressing.version.SoapAddressingVersion;25import org.springframework.ws.soap.addressing.version.SoapAddressingVersionStrategy;26import org.springframework.ws.soap.addressing.version.SoapAddressingVersionStrategyImpl;27import org.springframework.ws.soap.addressing.version.SoapAddressingVersionUtils;28import org.springframework.ws.soap.addressing.version.SoapAddressingVersionUtilsImpl;29import org.springframework.ws.soap.addressing.version.SoapAddressingVersionUtilsSupport;30import org.springframework.ws.soap.addressing.version.SoapAddressingVersionUtilsSupportImpl;31import org.springframework.ws.soap.addressing.version.SoapAddressingVersionUtilsSupportImpl2;32import com.consol.citrus.actions.ReceiveMessageAction;33import com.consol.citrus.annotations.CitrusTest;34import com.consol.citrus.annotations.CitrusXmlTest;35import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;36import com.consol.citrus.dsl.runner.Cit
addVariableExtractors
Using AI Code Generation
1public class 4 {2 public static void main(String[] args) {3 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();4 Map<String, MessageVariableExtractor> messageVariableExtractors = new HashMap<String, MessageVariableExtractor>();5 messageVariableExtractors.put("myVariableExtractor", new MyVariableExtractor());6 receiveMessageAction.addVariableExtractors(messageVariableExtractors);7 }8}9public class 5 {10 public static void main(String[] args) {11 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();12 Map<String, MessageVariableExtractor> messageVariableExtractors = new HashMap<String, MessageVariableExtractor>();13 messageVariableExtractors.put("myVariableExtractor", new MyVariableExtractor());14 receiveMessageAction.addVariableExtractors(messageVariableExtractors);15 }16}17public class 6 {18 public static void main(String[] args) {19 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();20 Map<String, MessageVariableExtractor> messageVariableExtractors = new HashMap<String, MessageVariableExtractor>();21 messageVariableExtractors.put("myVariableExtractor", new MyVariableExtractor());22 receiveMessageAction.addVariableExtractors(messageVariableExtractors);23 }24}25public class 7 {26 public static void main(String[] args) {27 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();
addVariableExtractors
Using AI Code Generation
1ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();2receiveMessageAction.setActor("actor1");3receiveMessageAction.addVariableExtractors(new JsonPathMessageVariableExtractor());4receiveMessageAction.setMessageType("json");5receiveMessageAction.setEndpoint(endpoint);6receiveMessageAction.setMessagePayload("{ \"name\": \"John\", \"age\": \"20\"}");7receiveMessageAction.setValidationCallback(new MessageValidationContext.ValidationCallback() {8 public void validateMessage(Message receivedMessage, Message controlMessage, TestContext context) {9 assertThat(receivedMessage.getPayload()).isEqualTo(controlMessage.getPayload());10 assertThat(receivedMessage.getHeader("citrus_jms_messageId")).isNotNull();11 }12});13receiveMessageAction.execute(context);14ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();15receiveMessageAction.setActor("actor1");16receiveMessageAction.setVariableExtractors(Arrays.asList(new JsonPathMessageVariableExtractor()));17receiveMessageAction.setMessageType("json");18receiveMessageAction.setEndpoint(endpoint);19receiveMessageAction.setMessagePayload("{ \"name\": \"John\", \"age\": \"20\"}");20receiveMessageAction.setValidationCallback(new MessageValidationContext.ValidationCallback() {21 public void validateMessage(Message receivedMessage, Message controlMessage, TestContext context) {22 assertThat(receivedMessage.getPayload()).isEqualTo(controlMessage.getPayload());23 assertThat(receivedMessage.getHeader("citrus_jms_messageId")).isNotNull();24 }25});26receiveMessageAction.execute(context);27ReceiveTimeoutAction receiveTimeoutAction = new ReceiveTimeoutAction();28receiveTimeoutAction.setActor("actor1");29receiveTimeoutAction.addVariableExtractors(new JsonPathMessageVariableExtractor());30receiveTimeoutAction.setMessageType("json");31receiveTimeoutAction.setEndpoint(endpoint);32receiveTimeoutAction.setMessagePayload("{ \"name\": \"John\", \"age\": \"20\"}");33receiveTimeoutAction.setValidationCallback(new MessageValidationContext.ValidationCallback() {34 public void validateMessage(Message receivedMessage, Message controlMessage, TestContext context) {35 assertThat(receivedMessage.getPayload()).isEqualTo(controlMessage.getPayload());36 assertThat(receivedMessage.getHeader("citrus_jms_messageId")).isNotNull();37 }38});39receiveTimeoutAction.execute(context);
addVariableExtractors
Using AI Code Generation
1package com.consol.citrus.samples;2import org.springframework.context.annotation.Bean;3import org.springframework.context.annotation.Configuration;4import org.springframework.context.annotation.Import;5import com.consol.citrus.dsl.endpoint.CitrusEndpoints;6import com.consol.citrus.dsl.runner.TestRunner;7import com.consol.citrus.dsl.runner.TestRunnerSupport;8import com.consol.citrus.http.client.HttpClient;9import com.consol.citrus.http.message.HttpMessage;10import com.consol.citrus.message.MessageType;11import com.consol.citrus.variable.VariableExtractor;12import com.consol.citrus.variable.dictionary.json.JsonMappingVariableExtractor;13import com.consol.citrus.variable.dictionary.xml.NodeMappingDataDictionary;14import com.consol.citrus.variable.dictionary.xml.NodeMappingVariableExtractor;15import java.util.Arrays;16import java.util.HashMap;17import java.util.Map;18import org.springframework.core.io.ClassPathResource;19@Import(CitrusEndpoints.class)20public class TestConfig extends TestRunnerSupport {21 public HttpClient httpClient() {22 return CitrusEndpoints.http()23 .client()24 .build();25 }26 public void configure(TestRunner runner) {27 runner.http(builder -> builder.client(httpClient())28 .send()29 .post("/test")30 .contentType("application/json")31 .payload("{\"name\":\"John\"}"));32 runner.http(builder -> builder.client(httpClient())33 .receive()34 .response(HttpStatus.OK)35 .messageType(MessageType.JSON)36 .payload("{\"name\":\"John\", \"age\": 20}"));37 runner.http(builder -> builder.client(httpClient())38 .send()39 .get("/test")40 .accept("application/xml")41 .payload("<name>John</name>"));42 runner.http(builder -> builder.client(httpClient())43 .receive()44 .response(HttpStatus.OK)45 .messageType(MessageType.XML)46 .payload("<name>John</name><age>20</age>"));47 runner.http(builder -> builder.client(httpClient())48 .send()49 .post("/test")50 .contentType("application/xml")51 .payload("<name>John</name>"));52 runner.http(builder -> builder.client(httpClient())53 .receive()
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!!