How to use getValidators method of com.consol.citrus.actions.ReceiveMessageAction class

Best Citrus code snippet using com.consol.citrus.actions.ReceiveMessageAction.getValidators

Source:ReceiveMessageTestRunnerTest.java Github

copy

Full Screen

...771 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));772 Assert.assertEquals(action.getName(), "receive");773 Assert.assertEquals(action.getEndpoint(), messageEndpoint);774 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());775 Assert.assertEquals(action.getValidators().size(), 1L);776 Assert.assertEquals(action.getValidators().get(0), validator);777 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);778 Assert.assertEquals(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getPayloadData(), "TestMessage");779 Assert.assertTrue(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));780 }781 782 @Test783 public void testReceiveBuilderWithValidatorName() {784 final PlainTextMessageValidator validator = new PlainTextMessageValidator();785 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);786 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);787 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);788 when(configuration.getTimeout()).thenReturn(100L);789 when(messageEndpoint.getActor()).thenReturn(null);790 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));791 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));792 when(applicationContextMock.getBean("plainTextValidator", MessageValidator.class)).thenReturn(validator);793 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());794 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());795 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());796 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {797 @Override798 public void execute() {799 receive(action -> action.endpoint(messageEndpoint)800 .messageType(MessageType.PLAINTEXT)801 .payload("TestMessage")802 .header("operation", "sayHello")803 .validator("plainTextValidator"));804 }805 };806 TestCase test = builder.getTestCase();807 Assert.assertEquals(test.getActionCount(), 1);808 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);809 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));810 Assert.assertEquals(action.getName(), "receive");811 Assert.assertEquals(action.getEndpoint(), messageEndpoint);812 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());813 Assert.assertEquals(action.getValidators().size(), 1L);814 Assert.assertEquals(action.getValidators().get(0), validator);815 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);816 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");817 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));818 }819 @Test820 public void testReceiveBuilderWithDictionary() {821 final DataDictionary dictionary = new NodeMappingDataDictionary();822 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);823 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);824 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);825 when(configuration.getTimeout()).thenReturn(100L);826 when(messageEndpoint.getActor()).thenReturn(null);827 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));828 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));829 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());830 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());831 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());832 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {833 @Override834 public void execute() {835 receive(action -> action.endpoint(messageEndpoint)836 .messageType(MessageType.PLAINTEXT)837 .payload("TestMessage")838 .header("operation", "sayHello")839 .dictionary(dictionary));840 }841 };842 TestCase test = builder.getTestCase();843 Assert.assertEquals(test.getActionCount(), 1);844 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);845 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));846 Assert.assertEquals(action.getName(), "receive");847 Assert.assertEquals(action.getEndpoint(), messageEndpoint);848 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());849 Assert.assertEquals(action.getDataDictionary(), dictionary);850 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);851 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");852 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));853 }854 @Test855 public void testReceiveBuilderWithDictionaryName() {856 final DataDictionary dictionary = new NodeMappingDataDictionary();857 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);858 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);859 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);860 when(configuration.getTimeout()).thenReturn(100L);861 when(messageEndpoint.getActor()).thenReturn(null);862 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));863 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));864 when(applicationContextMock.getBean("customDictionary", DataDictionary.class)).thenReturn(dictionary);865 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());866 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());867 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());868 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {869 @Override870 public void execute() {871 receive(action -> action.endpoint(messageEndpoint)872 .messageType(MessageType.PLAINTEXT)873 .payload("TestMessage")874 .header("operation", "sayHello")875 .dictionary("customDictionary"));876 }877 };878 TestCase test = builder.getTestCase();879 Assert.assertEquals(test.getActionCount(), 1);880 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);881 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));882 Assert.assertEquals(action.getName(), "receive");883 Assert.assertEquals(action.getEndpoint(), messageEndpoint);884 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());885 Assert.assertEquals(action.getDataDictionary(), dictionary);886 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);887 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");888 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));889 }890 @Test891 public void testReceiveBuilderWithSelector() {892 SelectiveConsumer selectiveConsumer = Mockito.mock(SelectiveConsumer.class);893 reset(messageEndpoint, selectiveConsumer, configuration);894 when(messageEndpoint.createConsumer()).thenReturn(selectiveConsumer);895 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);896 when(configuration.getTimeout()).thenReturn(100L);897 when(messageEndpoint.getActor()).thenReturn(null);898 when(selectiveConsumer.receive(eq("operation = 'sayHello'"), any(TestContext.class), anyLong())).thenReturn(899 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")900 .setHeader("operation", "sayHello"));901 final Map<String, String> messageSelector = new HashMap<>();902 messageSelector.put("operation", "sayHello");903 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {904 @Override905 public void execute() {906 receive(action -> action.endpoint(messageEndpoint)907 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")908 .selector(messageSelector));909 }910 };911 TestCase test = builder.getTestCase();912 Assert.assertEquals(test.getActionCount(), 1);913 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);914 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));915 Assert.assertEquals(action.getName(), "receive");916 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());917 Assert.assertEquals(action.getEndpoint(), messageEndpoint);918 Assert.assertEquals(action.getMessageSelectorMap(), messageSelector);919 }920 921 @Test922 public void testReceiveBuilderWithSelectorExpression() {923 SelectiveConsumer selectiveConsumer = Mockito.mock(SelectiveConsumer.class);924 reset(messageEndpoint, selectiveConsumer, configuration);925 when(messageEndpoint.createConsumer()).thenReturn(selectiveConsumer);926 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);927 when(configuration.getTimeout()).thenReturn(100L);928 when(messageEndpoint.getActor()).thenReturn(null);929 when(selectiveConsumer.receive(eq("operation = 'sayHello'"), any(TestContext.class), anyLong())).thenReturn(930 new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")931 .setHeader("operation", "sayHello"));932 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {933 @Override934 public void execute() {935 receive(action -> action.endpoint(messageEndpoint)936 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")937 .selector("operation = 'sayHello'"));938 }939 };940 TestCase test = builder.getTestCase();941 Assert.assertEquals(test.getActionCount(), 1);942 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);943 944 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));945 Assert.assertEquals(action.getName(), "receive");946 947 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());948 Assert.assertEquals(action.getEndpoint(), messageEndpoint);949 950 Assert.assertTrue(action.getMessageSelectorMap().isEmpty());951 Assert.assertEquals(action.getMessageSelector(), "operation = 'sayHello'");952 }953 954 @Test955 public void testReceiveBuilderExtractFromPayload() {956 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);957 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);958 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);959 when(configuration.getTimeout()).thenReturn(100L);960 when(messageEndpoint.getActor()).thenReturn(null);961 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(962 new DefaultMessage("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")963 .setHeader("operation", "sayHello"));964 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));965 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());966 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());967 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());968 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {969 @Override970 public void execute() {971 receive(action -> action.endpoint(messageEndpoint)972 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")973 .extractFromPayload("/TestRequest/Message", "text")974 .extractFromPayload("/TestRequest/Message/@lang", "language"));975 }976 };977 TestContext context = builder.getTestContext();978 Assert.assertNotNull(context.getVariable("text"));979 Assert.assertNotNull(context.getVariable("language"));980 Assert.assertEquals(context.getVariable("text"), "Hello World!");981 Assert.assertEquals(context.getVariable("language"), "ENG");982 TestCase test = builder.getTestCase();983 Assert.assertEquals(test.getActionCount(), 1);984 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);985 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));986 Assert.assertEquals(action.getName(), "receive");987 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());988 Assert.assertEquals(action.getEndpoint(), messageEndpoint);989 Assert.assertEquals(action.getVariableExtractors().size(), 1);990 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);991 Assert.assertTrue(((XpathPayloadVariableExtractor) action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message"));992 Assert.assertTrue(((XpathPayloadVariableExtractor) action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));993 }994 @Test995 public void testReceiveBuilderExtractJsonPathFromPayload() {996 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);997 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);998 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);999 when(configuration.getTimeout()).thenReturn(100L);1000 when(messageEndpoint.getActor()).thenReturn(null);1001 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(1002 new DefaultMessage("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")1003 .setHeader("operation", "sayHello"));1004 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));1005 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1006 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1007 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1008 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {1009 @Override1010 public void execute() {1011 receive(action -> action.endpoint(messageEndpoint)1012 .messageType(MessageType.JSON)1013 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")1014 .extractFromPayload("$.text", "text")1015 .extractFromPayload("$.toString()", "payload")1016 .extractFromPayload("$.person", "person"));1017 }1018 };1019 TestContext context = builder.getTestContext();1020 Assert.assertNotNull(context.getVariable("text"));1021 Assert.assertNotNull(context.getVariable("person"));1022 Assert.assertNotNull(context.getVariable("payload"));1023 Assert.assertEquals(context.getVariable("text"), "Hello World!");1024 Assert.assertEquals(context.getVariable("payload"), "{\"person\":{\"surname\":\"Doe\",\"name\":\"John\"},\"index\":5,\"text\":\"Hello World!\",\"id\":\"x123456789x\"}");1025 Assert.assertTrue(context.getVariable("person").contains("\"John\""));1026 TestCase test = builder.getTestCase();1027 Assert.assertEquals(test.getActionCount(), 1);1028 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1029 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1030 Assert.assertEquals(action.getName(), "receive");1031 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1032 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1033 Assert.assertEquals(action.getVariableExtractors().size(), 1);1034 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);1035 Assert.assertTrue(((JsonPathVariableExtractor) action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.text"));1036 Assert.assertTrue(((JsonPathVariableExtractor) action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.person"));1037 }1038 1039 @Test1040 public void testReceiveBuilderExtractFromHeader() {1041 reset(messageEndpoint, messageConsumer, configuration);1042 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1043 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1044 when(configuration.getTimeout()).thenReturn(100L);1045 when(messageEndpoint.getActor()).thenReturn(null);1046 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(1047 new DefaultMessage("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1048 .setHeader("operation", "sayHello")1049 .setHeader("requestId", "123456"));1050 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {1051 @Override1052 public void execute() {1053 receive(action -> action.endpoint(messageEndpoint)1054 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1055 .extractFromHeader("operation", "operationHeader")1056 .extractFromHeader("requestId", "id"));1057 }1058 };1059 TestContext context = builder.getTestContext();1060 Assert.assertNotNull(context.getVariable("operationHeader"));1061 Assert.assertNotNull(context.getVariable("id"));1062 Assert.assertEquals(context.getVariable("operationHeader"), "sayHello");1063 Assert.assertEquals(context.getVariable("id"), "123456");1064 TestCase test = builder.getTestCase();1065 Assert.assertEquals(test.getActionCount(), 1);1066 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1067 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1068 Assert.assertEquals(action.getName(), "receive");1069 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1070 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1071 Assert.assertEquals(action.getVariableExtractors().size(), 1);1072 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);1073 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));1074 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));1075 }1076 1077 @Test1078 public void testReceiveBuilderExtractCombined() {1079 reset(messageEndpoint, messageConsumer, configuration);1080 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1081 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1082 when(configuration.getTimeout()).thenReturn(100L);1083 when(messageEndpoint.getActor()).thenReturn(null);1084 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(1085 new DefaultMessage("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1086 .setHeader("operation", "sayHello")1087 .setHeader("requestId", "123456"));1088 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {1089 @Override1090 public void execute() {1091 receive(action -> action.endpoint(messageEndpoint)1092 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1093 .extractFromHeader("operation", "operationHeader")1094 .extractFromHeader("requestId", "id")1095 .extractFromPayload("/TestRequest/Message", "text")1096 .extractFromPayload("/TestRequest/Message/@lang", "language"));1097 }1098 };1099 TestContext context = builder.getTestContext();1100 Assert.assertNotNull(context.getVariable("operationHeader"));1101 Assert.assertNotNull(context.getVariable("id"));1102 Assert.assertEquals(context.getVariable("operationHeader"), "sayHello");1103 Assert.assertEquals(context.getVariable("id"), "123456");1104 Assert.assertNotNull(context.getVariable("text"));1105 Assert.assertNotNull(context.getVariable("language"));1106 Assert.assertEquals(context.getVariable("text"), "Hello World!");1107 Assert.assertEquals(context.getVariable("language"), "ENG");1108 TestCase test = builder.getTestCase();1109 Assert.assertEquals(test.getActionCount(), 1);1110 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1111 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1112 Assert.assertEquals(action.getName(), "receive");1113 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1114 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1115 Assert.assertEquals(action.getVariableExtractors().size(), 2);1116 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);1117 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));1118 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));1119 Assert.assertTrue(action.getVariableExtractors().get(1) instanceof XpathPayloadVariableExtractor);1120 Assert.assertTrue(((XpathPayloadVariableExtractor) action.getVariableExtractors().get(1)).getXpathExpressions().containsKey("/TestRequest/Message"));1121 Assert.assertTrue(((XpathPayloadVariableExtractor) action.getVariableExtractors().get(1)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));1122 }1123 1124 @Test1125 public void testReceiveBuilderWithValidationCallback() {1126 final AbstractValidationCallback callback = Mockito.mock(AbstractValidationCallback.class);1127 reset(callback, messageEndpoint, messageConsumer, configuration);1128 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1129 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1130 when(configuration.getTimeout()).thenReturn(100L);1131 when(messageEndpoint.getActor()).thenReturn(null);1132 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("TestMessage").setHeader("operation", "sayHello"));1133 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {1134 @Override1135 public void execute() {1136 receive(action -> action.endpoint(messageEndpoint)1137 .messageType(MessageType.PLAINTEXT)1138 .payload("TestMessage")1139 .header("operation", "sayHello")1140 .validationCallback(callback));1141 }1142 };1143 TestCase test = builder.getTestCase();1144 Assert.assertEquals(test.getActionCount(), 1);1145 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1146 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1147 Assert.assertEquals(action.getName(), "receive");1148 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1149 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());1150 Assert.assertEquals(action.getValidationCallback(), callback);1151 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1152 Assert.assertEquals(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getPayloadData(), "TestMessage");1153 Assert.assertTrue(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));1154 verify(callback).setApplicationContext(applicationContext);1155 verify(callback).validate(any(Message.class), any(TestContext.class));1156 }1157 @Test1158 public void testReceiveBuilderWithValidatonScript() {1159 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1160 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);1161 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1162 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1163 when(configuration.getTimeout()).thenReturn(100L);1164 when(messageEndpoint.getActor()).thenReturn(null);1165 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("{\"message\": \"Hello Citrus!\"}").setHeader("operation", "sayHello"));1166 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));1167 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1168 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1169 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1170 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1171 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {1172 @Override1173 public void execute() {1174 receive(action -> action.endpoint(messageEndpoint)1175 .messageType(MessageType.JSON)1176 .validateScript("assert json.message == 'Hello Citrus!'")1177 .validator("groovyMessageValidator"));1178 }1179 };1180 TestCase test = builder.getTestCase();1181 Assert.assertEquals(test.getActionCount(), 1);1182 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1183 1184 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1185 Assert.assertEquals(action.getName(), "receive");1186 1187 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1188 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1189 Assert.assertEquals(action.getValidators().size(), 1L);1190 Assert.assertEquals(action.getValidators().get(0), validator);1191 Assert.assertEquals(action.getValidationContexts().size(), 4L);1192 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1193 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1194 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1195 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1196 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1197 1198 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1199 Assert.assertEquals(validationContext.getValidationScript(), "assert json.message == 'Hello Citrus!'");1200 Assert.assertNull(validationContext.getValidationScriptResourcePath());1201 }1202 1203 @Test1204 public void testReceiveBuilderWithValidatonScriptResourcePath() throws IOException {1205 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1206 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);1207 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1208 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1209 when(configuration.getTimeout()).thenReturn(100L);1210 when(messageEndpoint.getActor()).thenReturn(null);1211 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("{\"message\": \"Hello Citrus!\"}").setHeader("operation", "sayHello"));1212 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));1213 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1214 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1215 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1216 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1217 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {1218 @Override1219 public void execute() {1220 receive(action -> action.endpoint(messageEndpoint)1221 .messageType(MessageType.JSON)1222 .validateScriptResource("classpath:com/consol/citrus/dsl/runner/validation.groovy")1223 .validator("groovyMessageValidator"));1224 }1225 };1226 TestCase test = builder.getTestCase();1227 Assert.assertEquals(test.getActionCount(), 1);1228 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1229 1230 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1231 Assert.assertEquals(action.getName(), "receive");1232 1233 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1234 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1235 Assert.assertEquals(action.getValidators().size(), 1L);1236 Assert.assertEquals(action.getValidators().get(0), validator);1237 Assert.assertEquals(action.getValidationContexts().size(), 4L);1238 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1239 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1240 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1241 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1242 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1243 1244 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1245 Assert.assertEquals(validationContext.getValidationScript(), "");1246 Assert.assertEquals(validationContext.getValidationScriptResourcePath(), "classpath:com/consol/citrus/dsl/runner/validation.groovy");1247 }1248 @Test1249 public void testReceiveBuilderWithValidatonScriptResource() throws IOException {1250 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1251 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);1252 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1253 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1254 when(configuration.getTimeout()).thenReturn(100L);1255 when(messageEndpoint.getActor()).thenReturn(null);1256 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("{\"message\": \"Hello Citrus!\"}").setHeader("operation", "sayHello"));1257 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));1258 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1259 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1260 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1261 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1262 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {1263 @Override1264 public void execute() {1265 receive(action -> action.endpoint(messageEndpoint)1266 .messageType(MessageType.JSON)1267 .validateScript(new ClassPathResource("com/consol/citrus/dsl/runner/validation.groovy"))1268 .validator("groovyMessageValidator"));1269 }1270 };1271 TestCase test = builder.getTestCase();1272 Assert.assertEquals(test.getActionCount(), 1);1273 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1274 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1275 Assert.assertEquals(action.getName(), "receive");1276 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1277 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1278 Assert.assertEquals(action.getValidators().size(), 1L);1279 Assert.assertEquals(action.getValidators().get(0), validator);1280 Assert.assertEquals(action.getValidationContexts().size(), 4L);1281 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1282 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1283 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1284 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1285 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1286 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1287 Assert.assertEquals(validationContext.getValidationScript(), "assert json.message == 'Hello Citrus!'");1288 Assert.assertNull(validationContext.getValidationScriptResourcePath());1289 }1290 1291 @Test1292 public void testReceiveBuilderWithValidatonScriptAndHeader() {1293 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1294 reset(applicationContextMock, messageEndpoint, messageConsumer, configuration);1295 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);1296 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);1297 when(configuration.getTimeout()).thenReturn(100L);1298 when(messageEndpoint.getActor()).thenReturn(null);1299 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("{\"message\": \"Hello Citrus!\"}").setHeader("operation", "sayHello"));1300 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));1301 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1302 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1303 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1304 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1305 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {1306 @Override1307 public void execute() {1308 receive(action -> action.endpoint(messageEndpoint)1309 .messageType(MessageType.JSON)1310 .validateScript("assert json.message == 'Hello Citrus!'")1311 .validator("groovyMessageValidator")1312 .header("operation", "sayHello"));1313 }1314 };1315 TestCase test = builder.getTestCase();1316 Assert.assertEquals(test.getActionCount(), 1);1317 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);1318 1319 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));1320 Assert.assertEquals(action.getName(), "receive");1321 1322 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1323 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1324 Assert.assertEquals(action.getValidators().size(), 1L);1325 Assert.assertEquals(action.getValidators().get(0), validator);1326 Assert.assertEquals(action.getValidationContexts().size(), 4L);1327 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1328 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1329 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1330 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1331 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1332 1333 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1334 Assert.assertEquals(validationContext.getValidationScript(), "assert json.message == 'Hello Citrus!'");1335 Assert.assertNull(validationContext.getValidationScriptResourcePath());1336 1337 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1338 Assert.assertNull(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData());1339 Assert.assertNull(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadResourcePath());...

Full Screen

Full Screen

Source:ReceiveMessageTestDesignerTest.java Github

copy

Full Screen

...664 Assert.assertEquals(action.getName(), "receive");665 666 Assert.assertEquals(action.getEndpoint(), messageEndpoint);667 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());668 Assert.assertEquals(action.getValidators().size(), 1L);669 Assert.assertEquals(action.getValidators().get(0), validator);670 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);671 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");672 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));673 }674 675 @Test676 public void testReceiveBuilderWithValidatorName() {677 final PlainTextMessageValidator validator = new PlainTextMessageValidator();678 679 reset(applicationContextMock);680 when(applicationContextMock.getBean("plainTextValidator", MessageValidator.class)).thenReturn(validator);681 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());682 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());683 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());684 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {685 @Override686 public void configure() {687 receive(messageEndpoint)688 .messageType(MessageType.PLAINTEXT)689 .payload("TestMessage")690 .header("operation", "sayHello")691 .validator("plainTextValidator");692 }693 };694 builder.configure();695 TestCase test = builder.getTestCase();696 Assert.assertEquals(test.getActionCount(), 1);697 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);698 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);699 700 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();701 Assert.assertEquals(action.getName(), "receive");702 703 Assert.assertEquals(action.getEndpoint(), messageEndpoint);704 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());705 Assert.assertEquals(action.getValidators().size(), 1L);706 Assert.assertEquals(action.getValidators().get(0), validator);707 708 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);709 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");710 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));711 }712 @Test713 public void testReceiveBuilderWithDictionary() {714 final DataDictionary dictionary = new NodeMappingDataDictionary();715 reset(applicationContextMock);716 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());717 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());718 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());719 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {720 @Override721 public void configure() {722 receive(messageEndpoint)723 .messageType(MessageType.PLAINTEXT)724 .payload("TestMessage")725 .header("operation", "sayHello")726 .dictionary(dictionary);727 }728 };729 builder.configure();730 TestCase test = builder.getTestCase();731 Assert.assertEquals(test.getActionCount(), 1);732 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);733 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);734 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();735 Assert.assertEquals(action.getName(), "receive");736 Assert.assertEquals(action.getEndpoint(), messageEndpoint);737 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());738 Assert.assertEquals(action.getDataDictionary(), dictionary);739 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);740 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");741 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));742 }743 @Test744 public void testReceiveBuilderWithDictionaryName() {745 final DataDictionary dictionary = new NodeMappingDataDictionary();746 reset(applicationContextMock);747 when(applicationContextMock.getBean("customDictionary", DataDictionary.class)).thenReturn(dictionary);748 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());749 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());750 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());751 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {752 @Override753 public void configure() {754 receive(messageEndpoint)755 .messageType(MessageType.PLAINTEXT)756 .payload("TestMessage")757 .header("operation", "sayHello")758 .dictionary("customDictionary");759 }760 };761 builder.configure();762 TestCase test = builder.getTestCase();763 Assert.assertEquals(test.getActionCount(), 1);764 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);765 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);766 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();767 Assert.assertEquals(action.getName(), "receive");768 Assert.assertEquals(action.getEndpoint(), messageEndpoint);769 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());770 Assert.assertEquals(action.getDataDictionary(), dictionary);771 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);772 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");773 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));774 }775 776 @Test777 public void testReceiveBuilderWithSelector() {778 final Map<String, String> messageSelector = new HashMap<String, String>();779 messageSelector.put("operation", "sayHello");780 781 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {782 @Override783 public void configure() {784 receive(messageEndpoint)785 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")786 .selector(messageSelector);787 }788 };789 builder.configure();790 TestCase test = builder.getTestCase();791 Assert.assertEquals(test.getActionCount(), 1);792 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);793 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);794 795 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();796 Assert.assertEquals(action.getName(), "receive");797 798 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());799 Assert.assertEquals(action.getEndpoint(), messageEndpoint);800 801 Assert.assertEquals(action.getMessageSelectorMap(), messageSelector);802 }803 804 @Test805 public void testReceiveBuilderWithSelectorExpression() {806 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {807 @Override808 public void configure() {809 receive(messageEndpoint)810 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")811 .selector("operation = 'sayHello'");812 }813 };814 builder.configure();815 TestCase test = builder.getTestCase();816 Assert.assertEquals(test.getActionCount(), 1);817 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);818 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);819 820 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();821 Assert.assertEquals(action.getName(), "receive");822 823 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());824 Assert.assertEquals(action.getEndpoint(), messageEndpoint);825 826 Assert.assertTrue(action.getMessageSelectorMap().isEmpty());827 Assert.assertEquals(action.getMessageSelector(), "operation = 'sayHello'");828 }829 830 @Test831 public void testReceiveBuilderExtractFromPayload() {832 reset(applicationContextMock);833 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());834 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());835 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());836 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {837 @Override838 public void configure() {839 receive(messageEndpoint)840 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")841 .extractFromPayload("/TestRequest/Message", "text")842 .extractFromPayload("/TestRequest/Message/@lang", "language");843 }844 };845 builder.configure();846 TestCase test = builder.getTestCase();847 Assert.assertEquals(test.getActionCount(), 1);848 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);849 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);850 851 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();852 Assert.assertEquals(action.getName(), "receive");853 854 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());855 Assert.assertEquals(action.getEndpoint(), messageEndpoint);856 857 Assert.assertEquals(action.getVariableExtractors().size(), 1);858 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);859 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message"));860 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));861 }862 @Test863 public void testReceiveBuilderExtractJsonPathFromPayload() {864 reset(applicationContextMock);865 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());866 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());867 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());868 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {869 @Override870 public void configure() {871 receive(messageEndpoint)872 .messageType(MessageType.JSON)873 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")874 .extractFromPayload("$.text", "text")875 .extractFromPayload("$.person", "person");876 }877 };878 builder.configure();879 TestCase test = builder.getTestCase();880 Assert.assertEquals(test.getActionCount(), 1);881 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);882 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);883 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();884 Assert.assertEquals(action.getName(), "receive");885 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());886 Assert.assertEquals(action.getEndpoint(), messageEndpoint);887 Assert.assertEquals(action.getVariableExtractors().size(), 1);888 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);889 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.text"));890 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.person"));891 }892 893 @Test894 public void testReceiveBuilderExtractFromHeader() {895 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {896 @Override897 public void configure() {898 receive(messageEndpoint)899 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")900 .extractFromHeader("operation", "ops")901 .extractFromHeader("requestId", "id");902 }903 };904 builder.configure();905 TestCase test = builder.getTestCase();906 Assert.assertEquals(test.getActionCount(), 1);907 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);908 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);909 910 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();911 Assert.assertEquals(action.getName(), "receive");912 913 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());914 Assert.assertEquals(action.getEndpoint(), messageEndpoint);915 916 Assert.assertEquals(action.getVariableExtractors().size(), 1);917 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);918 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));919 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));920 }921 922 @Test923 public void testReceiveBuilderExtractCombined() {924 reset(applicationContextMock);925 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());926 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());927 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());928 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {929 @Override930 public void configure() {931 receive(messageEndpoint)932 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")933 .extractFromHeader("operation", "ops")934 .extractFromHeader("requestId", "id")935 .extractFromPayload("/TestRequest/Message", "text")936 .extractFromPayload("/TestRequest/Message/@lang", "language");937 }938 };939 builder.configure();940 TestCase test = builder.getTestCase();941 Assert.assertEquals(test.getActionCount(), 1);942 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);943 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);944 945 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();946 Assert.assertEquals(action.getName(), "receive");947 948 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());949 Assert.assertEquals(action.getEndpoint(), messageEndpoint);950 951 Assert.assertEquals(action.getVariableExtractors().size(), 2);952 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);953 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));954 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));955 956 Assert.assertTrue(action.getVariableExtractors().get(1) instanceof XpathPayloadVariableExtractor);957 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(1)).getXpathExpressions().containsKey("/TestRequest/Message"));958 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(1)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));959 }960 961 @Test962 public void testReceiveBuilderWithValidationCallback() {963 final ValidationCallback callback = Mockito.mock(ValidationCallback.class);964 965 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {966 @Override967 public void configure() {968 receive(messageEndpoint)969 .messageType(MessageType.PLAINTEXT)970 .payload("TestMessage")971 .header("operation", "sayHello")972 .validationCallback(callback);973 }974 };975 builder.configure();976 TestCase test = builder.getTestCase();977 Assert.assertEquals(test.getActionCount(), 1);978 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);979 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);980 981 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();982 Assert.assertEquals(action.getName(), "receive");983 984 Assert.assertEquals(action.getEndpoint(), messageEndpoint);985 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());986 Assert.assertEquals(action.getValidationCallback(), callback);987 988 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);989 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");990 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));991 }992 993 @Test994 public void testReceiveBuilderWithValidatonScript() {995 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();996 997 reset(applicationContextMock);998 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);999 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1000 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1001 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1002 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {1003 @Override1004 public void configure() {1005 receive(messageEndpoint)1006 .messageType(MessageType.JSON)1007 .validateScript("assert true")1008 .validator("groovyMessageValidator");1009 }1010 };1011 builder.configure();1012 TestCase test = builder.getTestCase();1013 Assert.assertEquals(test.getActionCount(), 1);1014 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1015 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1016 1017 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1018 Assert.assertEquals(action.getName(), "receive");1019 1020 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1021 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1022 Assert.assertEquals(action.getValidators().size(), 1L);1023 Assert.assertEquals(action.getValidators().get(0), validator);1024 Assert.assertEquals(action.getValidationContexts().size(), 4L);1025 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1026 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1027 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1028 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1029 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1030 1031 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1032 Assert.assertEquals(validationContext.getValidationScript(), "assert true");1033 Assert.assertNull(validationContext.getValidationScriptResourcePath());1034 }1035 1036 @Test1037 public void testReceiveBuilderWithValidatonScriptResource() throws IOException {1038 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1039 1040 reset(applicationContextMock);1041 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1042 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1043 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1044 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1045 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {1046 @Override1047 public void configure() {1048 receive(messageEndpoint)1049 .messageType(MessageType.JSON)1050 .validateScript(new ClassPathResource("com/consol/citrus/dsl/runner/validation.groovy"))1051 .validator("groovyMessageValidator");1052 }1053 };1054 builder.configure();1055 TestCase test = builder.getTestCase();1056 Assert.assertEquals(test.getActionCount(), 1);1057 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1058 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1059 1060 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1061 Assert.assertEquals(action.getName(), "receive");1062 1063 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1064 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1065 Assert.assertEquals(action.getValidators().size(), 1L);1066 Assert.assertEquals(action.getValidators().get(0), validator);1067 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1068 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1069 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1070 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1071 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1072 1073 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1074 Assert.assertEquals(validationContext.getValidationScript(), "assert json.message == 'Hello Citrus!'");1075 Assert.assertNull(validationContext.getValidationScriptResourcePath());1076 }1077 @Test1078 public void testReceiveBuilderWithValidatonScriptResourcePath() throws IOException {1079 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1080 reset(applicationContextMock);1081 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1082 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1083 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1084 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1085 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {1086 @Override1087 public void configure() {1088 receive(messageEndpoint)1089 .messageType(MessageType.JSON)1090 .validateScriptResource("/path/to/file/File.groovy")1091 .validator("groovyMessageValidator");1092 }1093 };1094 builder.configure();1095 TestCase test = builder.getTestCase();1096 Assert.assertEquals(test.getActionCount(), 1);1097 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1098 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1099 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1100 Assert.assertEquals(action.getName(), "receive");1101 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1102 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1103 Assert.assertEquals(action.getValidators().size(), 1L);1104 Assert.assertEquals(action.getValidators().get(0), validator);1105 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1106 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1107 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1108 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1109 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1110 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1111 Assert.assertEquals(validationContext.getValidationScript(), "");1112 Assert.assertEquals(validationContext.getValidationScriptResourcePath(), "/path/to/file/File.groovy");1113 }1114 1115 @Test1116 public void testReceiveBuilderWithValidatonScriptAndHeader() {1117 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1118 1119 reset(applicationContextMock);1120 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1121 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1122 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1123 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1124 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {1125 @Override1126 public void configure() {1127 receive(messageEndpoint)1128 .messageType(MessageType.JSON)1129 .validateScript("assert true")1130 .validator("groovyMessageValidator")1131 .header("operation", "sayHello");1132 }1133 };1134 builder.configure();1135 TestCase test = builder.getTestCase();1136 Assert.assertEquals(test.getActionCount(), 1);1137 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1138 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1139 1140 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1141 Assert.assertEquals(action.getName(), "receive");1142 1143 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1144 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1145 Assert.assertEquals(action.getValidators().size(), 1L);1146 Assert.assertEquals(action.getValidators().get(0), validator);1147 1148 Assert.assertEquals(action.getValidationContexts().size(), 4L);1149 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1150 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1151 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1152 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1153 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1154 1155 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1156 Assert.assertEquals(validationContext.getValidationScript(), "assert true");1157 Assert.assertNull(validationContext.getValidationScriptResourcePath());1158 1159 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1160 Assert.assertNull(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData());...

Full Screen

Full Screen

Source:ReceiveMessageActionBuilderTest.java Github

copy

Full Screen

...80 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));81 Assert.assertEquals(action.getName(), "receive");82 Assert.assertEquals(action.getEndpoint(), messageEndpoint);83 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());84 Assert.assertEquals(action.getValidators().size(), 1L);85 Assert.assertEquals(action.getValidators().get(0), validator);86 Assert.assertEquals(action.getValidationContexts().size(), 2L);87 Assert.assertTrue(action.getValidationContexts().stream().anyMatch(HeaderValidationContext.class::isInstance));88 Assert.assertTrue(action.getValidationContexts().stream().anyMatch(ScriptValidationContext.class::isInstance));89 ScriptValidationContext validationContext = action.getValidationContexts().stream()90 .filter(ScriptValidationContext.class::isInstance).findFirst()91 .map(ScriptValidationContext.class::cast)92 .orElseThrow(() -> new AssertionError("Missing validation context"));93 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);94 Assert.assertEquals(validationContext.getValidationScript().trim(), "assert json.message == 'Hello Citrus!'");95 Assert.assertNull(validationContext.getValidationScriptResourcePath());96 }97 @Test98 public void testReceiveBuilderWithValidationScriptResourcePath() throws IOException {99 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();100 reset(referenceResolver, messageEndpoint, messageConsumer, configuration);101 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);102 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);103 when(configuration.getTimeout()).thenReturn(100L);104 when(messageEndpoint.getActor()).thenReturn(null);105 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("{\"message\": \"Hello Citrus!\"}").setHeader("operation", "sayHello"));106 when(referenceResolver.resolve(TestContext.class)).thenReturn(context);107 when(referenceResolver.resolve("groovyMessageValidator")).thenReturn(validator);108 when(referenceResolver.resolve(TestActionListeners.class)).thenReturn(new TestActionListeners());109 when(referenceResolver.resolveAll(SequenceBeforeTest.class)).thenReturn(new HashMap<>());110 when(referenceResolver.resolveAll(SequenceAfterTest.class)).thenReturn(new HashMap<>());111 context.setReferenceResolver(referenceResolver);112 DefaultTestCaseRunner runner = new DefaultTestCaseRunner(context);113 runner.run(receive(messageEndpoint)114 .message()115 .type(MessageType.JSON)116 .validate(groovy().scriptResource("classpath:com/consol/citrus/actions/dsl/validation.groovy"))117 .validator("groovyMessageValidator"));118 TestCase test = runner.getTestCase();119 Assert.assertEquals(test.getActionCount(), 1);120 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);121 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));122 Assert.assertEquals(action.getName(), "receive");123 Assert.assertEquals(action.getEndpoint(), messageEndpoint);124 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());125 Assert.assertEquals(action.getValidators().size(), 1L);126 Assert.assertEquals(action.getValidators().get(0), validator);127 Assert.assertEquals(action.getValidationContexts().size(), 2L);128 Assert.assertTrue(action.getValidationContexts().stream().anyMatch(HeaderValidationContext.class::isInstance));129 Assert.assertTrue(action.getValidationContexts().stream().anyMatch(ScriptValidationContext.class::isInstance));130 ScriptValidationContext validationContext = action.getValidationContexts().stream()131 .filter(ScriptValidationContext.class::isInstance).findFirst()132 .map(ScriptValidationContext.class::cast)133 .orElseThrow(() -> new AssertionError("Missing validation context"));134 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);135 Assert.assertEquals(validationContext.getValidationScript(), "");136 Assert.assertEquals(validationContext.getValidationScriptResourcePath(), "classpath:com/consol/citrus/actions/dsl/validation.groovy");137 }138 @Test139 public void testReceiveBuilderWithValidationScriptResource() throws IOException {140 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();141 reset(referenceResolver, messageEndpoint, messageConsumer, configuration);142 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);143 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);144 when(configuration.getTimeout()).thenReturn(100L);145 when(messageEndpoint.getActor()).thenReturn(null);146 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("{\"message\": \"Hello Citrus!\"}").setHeader("operation", "sayHello"));147 when(referenceResolver.resolve(TestContext.class)).thenReturn(context);148 when(referenceResolver.resolve("groovyMessageValidator")).thenReturn(validator);149 when(referenceResolver.resolve(TestActionListeners.class)).thenReturn(new TestActionListeners());150 when(referenceResolver.resolveAll(SequenceBeforeTest.class)).thenReturn(new HashMap<>());151 when(referenceResolver.resolveAll(SequenceAfterTest.class)).thenReturn(new HashMap<>());152 context.setReferenceResolver(referenceResolver);153 DefaultTestCaseRunner runner = new DefaultTestCaseRunner(context);154 runner.run(receive(messageEndpoint)155 .message()156 .type(MessageType.JSON)157 .validate(groovy().script(new ClassPathResource("com/consol/citrus/actions/dsl/validation.groovy")))158 .validator("groovyMessageValidator"));159 TestCase test = runner.getTestCase();160 Assert.assertEquals(test.getActionCount(), 1);161 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);162 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));163 Assert.assertEquals(action.getName(), "receive");164 Assert.assertEquals(action.getEndpoint(), messageEndpoint);165 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());166 Assert.assertEquals(action.getValidators().size(), 1L);167 Assert.assertEquals(action.getValidators().get(0), validator);168 Assert.assertEquals(action.getValidationContexts().size(), 2L);169 Assert.assertTrue(action.getValidationContexts().stream().anyMatch(HeaderValidationContext.class::isInstance));170 Assert.assertTrue(action.getValidationContexts().stream().anyMatch(ScriptValidationContext.class::isInstance));171 ScriptValidationContext validationContext = action.getValidationContexts().stream()172 .filter(ScriptValidationContext.class::isInstance).findFirst()173 .map(ScriptValidationContext.class::cast)174 .orElseThrow(() -> new AssertionError("Missing validation context"));175 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);176 Assert.assertEquals(validationContext.getValidationScript().trim(), "assert json.message == 'Hello Citrus!'");177 Assert.assertNull(validationContext.getValidationScriptResourcePath());178 }179 @Test180 public void testReceiveBuilderWithValidationScriptAndHeader() {181 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();182 reset(referenceResolver, messageEndpoint, messageConsumer, configuration);183 when(messageEndpoint.createConsumer()).thenReturn(messageConsumer);184 when(messageEndpoint.getEndpointConfiguration()).thenReturn(configuration);185 when(configuration.getTimeout()).thenReturn(100L);186 when(messageEndpoint.getActor()).thenReturn(null);187 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new DefaultMessage("{\"message\": \"Hello Citrus!\"}").setHeader("operation", "sayHello"));188 when(referenceResolver.resolve(TestContext.class)).thenReturn(context);189 when(referenceResolver.resolve("groovyMessageValidator")).thenReturn(validator);190 when(referenceResolver.resolve(TestActionListeners.class)).thenReturn(new TestActionListeners());191 when(referenceResolver.resolveAll(SequenceBeforeTest.class)).thenReturn(new HashMap<>());192 when(referenceResolver.resolveAll(SequenceAfterTest.class)).thenReturn(new HashMap<>());193 context.setReferenceResolver(referenceResolver);194 DefaultTestCaseRunner runner = new DefaultTestCaseRunner(context);195 runner.run(receive(messageEndpoint)196 .message()197 .type(MessageType.JSON)198 .validate(groovy().script("assert json.message == 'Hello Citrus!'"))199 .validator("groovyMessageValidator")200 .header("operation", "sayHello"));201 TestCase test = runner.getTestCase();202 Assert.assertEquals(test.getActionCount(), 1);203 Assert.assertEquals(test.getActions().get(0).getClass(), ReceiveMessageAction.class);204 ReceiveMessageAction action = ((ReceiveMessageAction)test.getActions().get(0));205 Assert.assertEquals(action.getName(), "receive");206 Assert.assertEquals(action.getEndpoint(), messageEndpoint);207 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());208 Assert.assertEquals(action.getValidators().size(), 1L);209 Assert.assertEquals(action.getValidators().get(0), validator);210 Assert.assertEquals(action.getValidationContexts().size(), 2L);211 Assert.assertTrue(action.getValidationContexts().stream().anyMatch(HeaderValidationContext.class::isInstance));212 Assert.assertTrue(action.getValidationContexts().stream().anyMatch(ScriptValidationContext.class::isInstance));213 ScriptValidationContext validationContext = action.getValidationContexts().stream()214 .filter(ScriptValidationContext.class::isInstance).findFirst()215 .map(ScriptValidationContext.class::cast)216 .orElseThrow(() -> new AssertionError("Missing validation context"));217 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);218 Assert.assertEquals(validationContext.getValidationScript().trim(), "assert json.message == 'Hello Citrus!'");219 Assert.assertNull(validationContext.getValidationScriptResourcePath());220 Assert.assertTrue(action.getMessageBuilder() instanceof DefaultMessageBuilder);221 Assert.assertEquals(((DefaultMessageBuilder)action.getMessageBuilder()).buildMessagePayload(context, action.getMessageType()), "");222 Assert.assertTrue(((DefaultMessageBuilder)action.getMessageBuilder()).buildMessageHeaders(context).containsKey("operation"));223 }...

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.actions.ReceiveMessageAction;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.endpoint.Endpoint;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.json.JsonMessageValidator;9import com.consol.citrus.validation.json.JsonTextMessageValidator;10import com.consol.citrus.validation.script.GroovyScriptMessageValidator;11import com.consol.citrus.validation.script.ScriptMessageValidator;12import com.consol.citrus.validation.text.PlainTextMessageValidator;13import com.consol.citrus.validation.xml.DomXmlMessageValidator;14import com.consol.citrus.validation.xml.XpathMessageValidator;15import com.consol.citrus.validation.xml.XmlMessageValidator;16import com.consol.citrus.validation.xml.XsdSchemaMessageValidator;17import com.consol.citrus.validation.xml.XsdSchemaRepository;18import com.consol.citrus.validation.xml.XsdSchemaValidationContext;19import com.consol.citrus.validation.xml.XsdSchemaValidationContextBuilder;20import com.consol.citrus.validation.xml.XmlSchemaValidationContext;21import com.consol.citrus.validation.xml.XmlSchemaValidationContextBuilder;22import com.consol.citrus.validation.xml.XmlValidationContext;23import com.consol.citrus.validation.xml.XmlValidationContextBuilder;24import com.consol.citrus.validation.xsd.XsdSchemaRepository;25import com.consol.citrus.validation.xsd.XsdSchemaValidationContext;26import com.consol.citrus.validation.xsd.XsdSchemaValidationContextBuilder;27import org.springframework.core.io.ClassPathResource;28import org.springframework.core.io.Resource;29import org.springframework.util.CollectionUtils;30import org.springframework.util.StringUtils;31import org.springframework.xml.xsd.SimpleXsdSchema;32import org.springframework.xml.xsd.XsdSchema;33import org.springframework.xml.xsd.XsdSchemaCollection;34import org.springframework.xml.xsd.XsdSchemaCollectionFactoryBean;35import org.springframework.xml.xsd.XsdSchemaFactoryBean;36import org.testng.annotations.Test;37import java.io.IOException;38import java.util.ArrayList;39import java.util.List;40import java.util.Map;41import java.util.Properties;42import java.util.Set;43import java.util.stream.Collectors;44public class CitrusTest {45 public void test1() {

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.actions;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.message.Message;4import com.consol.citrus.validation.MessageValidator;5import com.consol.citrus.validation.context.ValidationContext;6import com.consol.citrus.validation.xml.XmlMessageValidationContext;7import com.consol.citrus.validation.xml.XmlMessageValidationContextBuilder;8import com.consol.citrus.validation.xml.XmlMessageValidator;9import org.springframework.util.CollectionUtils;10import java.util.ArrayList;11import java.util.Arrays;12import java.util.List;13public class ReceiveMessageAction extends AbstractTestAction {14 private Message message;15 private String messageName;16 private String messageEndpoint;17 private String messageType;18 private String messageSelector;19 private ValidationContext validationContext;20 private XmlMessageValidationContextBuilder validationContextBuilder;21 private List<MessageValidator<? extends ValidationContext>> messageValidators = new ArrayList<MessageValidator<? extends ValidationContext>>();22 public ReceiveMessageAction() {23 this.validationContextBuilder = new XmlMessageValidationContextBuilder();24 }25 public ReceiveMessageAction(ValidationContext validationContext) {26 this.validationContext = validationContext;27 }28 public ReceiveMessageAction(XmlMessageValidationContextBuilder validationContextBuilder) {29 this.validationContextBuilder = validationContextBuilder;30 }31 public void doExecute(TestContext context) {32 Message receivedMessage = context.receive(messageEndpoint, messageType, messageSelector);33 if (message != null) {34 context.setVariable(messageName, receivedMessage);35 }36 if (validationContext != null) {37 validateMessage(receivedMessage, context, validationContext);38 } else {39 validateMessage(receivedMessage, context, validationContextBuilder.build(receivedMessage, context));40 }41 }42 protected void validateMessage(Message receivedMessage, TestContext context, ValidationContext validationContext) {43 if (CollectionUtils.isEmpty(messageValidators)) {44 messageValidators.add(new XmlMessageValidator());45 }46 for (MessageValidator<? extends ValidationContext> messageValidator : messageValidators) {47 if (messageValidator.supportsMessageType(receivedMessage.getClass(), validationContext.getClass())) {48 messageValidator.validateMessage(receivedMessage, message, context, validationContext);49 }50 }51 }

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import java.util.ArrayList;3import java.util.List;4import org.testng.annotations.Test;5import com.consol.citrus.actions.ReceiveMessageAction;6import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;7import com.consol.citrus.message.MessageType;8import com.consol.citrus.validation.builder.StaticMessageContentBuilder;9import com.consol.citrus.validation.json.JsonTextMessageValidator;10import com.consol.citrus.validation.script.GroovyScriptMessageValidator;11import com.consol.citrus.validation.text.PlainTextMessageValidator;12import com.consol.citrus.validation.xml.XpathMessageValidator;13import com.consol.citrus.validation.xml.XmlMessageValidationContext;14import com.consol.citrus.validation.xml.XmlMessageValidator;15public class ReceiveMessageActionTest extends TestNGCitrusTestDesigner {16 public void receiveMessageActionTest() {17 List<XmlMessageValidator> validators = new ArrayList<XmlMessageValidator>();18 validators.add(new XmlMessageValidator());19 validators.add(new XpathMessageValidator());20 validators.add(new PlainTextMessageValidator());21 validators.add(new GroovyScriptMessageValidator());22 validators.add(new JsonTextMessageValidator());23 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();24 receiveMessageAction.setMessageType(MessageType.XML);25 receiveMessageAction.setValidators(validators);26 receiveMessageAction.setValidationContext(new XmlMessageValidationContext());27 receiveMessageAction.setMessage(new StaticMessageContentBuilder("<TestRequest>"));28 variable("name", "citrus:concat('Hello ', 'Citrus')");29 variable("id", "1234");30 receiveMessageAction.setMessageName("TestRequestMessage");

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import org.testng.annotations.Test;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;5public class ReceiveMessageActionRunner extends TestNGCitrusTestDesigner {6public void receiveMessageActionJava(){7ReceiveMessageActionBuilder receiveMessageActionBuilder = receive(receiveMessageActionBuilder -> {8receiveMessageActionBuilder.endpoint("myEndpoint");9receiveMessageActionBuilder.message("msg");10receiveMessageActionBuilder.validators("validator1","validator2");11});12}13}14package com.consol.citrus.dsl.runner;15import org.testng.annotations.Test;16import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;17import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;18public class ReceiveMessageActionRunner extends TestNGCitrusTestDesigner {19public void receiveMessageActionJava(){20ReceiveMessageActionBuilder receiveMessageActionBuilder = receive(receiveMessageActionBuilder -> {21receiveMessageActionBuilder.endpoint("myEndpoint");22receiveMessageActionBuilder.message("msg");23receiveMessageActionBuilder.validators("validator1","validator2");24});25}26}27package com.consol.citrus.dsl.runner;28import org.testng.annotations.Test;29import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;30import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;31public class ReceiveMessageActionRunner extends TestNGCitrusTestDesigner {32public void receiveMessageActionJava(){33ReceiveMessageActionBuilder receiveMessageActionBuilder = receive(receiveMessageActionBuilder -> {34receiveMessageActionBuilder.endpoint("myEndpoint");35receiveMessageActionBuilder.message("msg");36receiveMessageActionBuilder.validators("validator1","validator2");37});38}39}40package com.consol.citrus.dsl.runner;41import org.testng.annotations.Test;42import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;43import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;44public class ReceiveMessageActionRunner extends TestNGCitrusTestDesigner {

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1package org.example;2import org.testng.annotations.Test;3import org.testng.AssertJUnit;4import org.testng.Assert;5import com.consol.citrus.annotations.CitrusTest;6import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;7import com.consol.citrus.message.MessageType;8import com.consol.citrus.validation.json.JsonTextMessageValidator;9import com.consol.citrus.validation.xml.XmlMessageValidator;10import com.consol.citrus.validation.xml.XsdSchemaValidationContext;11import com.consol.citrus.validation.xml.XsdSchemaValidator;12public class 4 extends TestNGCitrusTestDesigner {13public void 4() {14description("This is a test to check the getValidators method of ReceiveMessageAction class");15variable("variableName", "variableValue");16receive(action -> action.endpoint("endpointName").timeout(1000).messageType(MessageType.JSON).message("messageName").payload("payloadName").header("headerName", "headerValue").validator("validatorName").validators("validatorsName").validator("validatorName", "validator").validators("validatorsName", "validators").validator("validatorName", "validator", "validator").validators("validatorsName", "validators", "validators").validator("validatorName", "validator", "validator", "validator").validators("validatorsName", "validators", "validators", "validators").validator("validatorName", "validator", "validator", "validator", "validator").validators("validatorsName", "validators", "validators", "validators", "validators").validator("validatorName", "validator", "validator", "validator", "validator", "validator").validators("validatorsName", "validators", "validators", "validators", "validators", "validators").validator("validatorName", "validator", "validator", "validator", "validator", "validator", "validator").validators("validatorsName", "validators", "validators", "validators", "validators", "validators", "validators").validator("validatorName", "validator", "validator", "validator", "validator", "validator", "validator", "validator").validators("validatorsName", "validators", "validators", "validators", "validators", "validators", "validators", "validators"));17}18}19package org.example;20import org.testng.annotations.Test;21import org.testng.AssertJUnit;22import org

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1package com.citrus.test;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.testng.CitrusParameters;4import org.testng.annotations.Test;5public class GetValidatorsTest extends AbstractTestNGCitrusTest {6 @CitrusParameters("name")7 public void getValidatorsTest() {8 receive()9 .message()10 .getValidators();11 }12}13package com.citrus.test;14import com.consol.citrus.annotations.CitrusTest;15import com.consol.citrus.testng.CitrusParameters;16import org.testng.annotations.Test;17public class GetVariablesTest extends AbstractTestNGCitrusTest {18 @CitrusParameters("name")19 public void getVariablesTest() {20 receive()21 .message()22 .getVariables();23 }24}25package com.citrus.test;26import com.consol.citrus.annotations.CitrusTest;27import com.consol.citrus.testng.CitrusParameters;28import org.testng.annotations.Test;29public class GetValidationCallbackTest extends AbstractTestNGCitrusTest {30 @CitrusParameters("name")31 public void getValidationCallbackTest() {32 receive()33 .message()34 .getValidationCallback();35 }36}37package com.citrus.test;38import com.consol.citrus.annotations.CitrusTest;39import com.consol.citrus.testng.CitrusParameters;40import org.testng.annotations.Test;41public class GetValidationContextTest extends AbstractTestNGCitrusTest {42 @CitrusParameters("name")43 public void getValidationContextTest() {44 receive()45 .message()46 .getValidationContext();47 }48}49package com.citrus.test;50import

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.actions.ReceiveMessageAction;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.validation.builder.DefaultMessageBuilder;5import com.consol.citrus.validation.builder.StaticMessageContentBuilder;6import com.consol.citrus.validation.xml.XmlMessageValidationContext;7import com.consol.citrus.validation.xml.XmlMessageValidationContext.ValidationMode;8import com.consol.citrus.validation.xml.XpathMessageValidationContext;9import com.consol.citrus.validation.xml.XpathMessageValidationContext.ValidationType;10import org.testng.annotations.Test;11public class Test4 {12 public void test4() {13 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();14 receiveMessageAction.setEndpoint(new HttpEndpoint());15 receiveMessageAction.setMessageType(MessageType.XML.name());16 receiveMessageAction.setMessageBuilder(new DefaultMessageBuilder(new StaticMessageContentBuilder("<testMessage>Hello World!</testMessage>")));17 XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();18 xmlMessageValidationContext.setValidationMode(ValidationMode.STRICT);19 XpathMessageValidationContext xpathMessageValidationContext = new XpathMessageValidationContext();20 xpathMessageValidationContext.setValidationType(ValidationType.CONTAINS);21 receiveMessageAction.setValidationContext(xmlMessageValidationContext);22 receiveMessageAction.setValidationContext(xpathMessageValidationContext);23 System.out.println("The list of validators is " + receiveMessageAction.getValidators());24 }25}26package com.consol.citrus;27import com.consol.citrus.actions.ReceiveMessageAction;28import com.consol.citrus.message.MessageType;29import com.consol.citrus.validation.builder.DefaultMessageBuilder;30import com.consol.citrus.validation.builder.StaticMessageContentBuilder;31import com.consol.citrus.validation.xml.XmlMessageValidationContext;32import com.consol.citrus.validation.xml.XmlMessageValidationContext.ValidationMode;

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import java.util.ArrayList;3public class Test {4 public static void main(String[] args) {5 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();6 ArrayList<Validator<?>> validators = new ArrayList<Validator<?>>();7 validators.add(new DefaultMessageValidator());8 receiveMessageAction.setValidators(validators);9 System.out.println(receiveMessageAction.getValidators());10 }11}12package com.consol.citrus;13import java.util.ArrayList;14public class Test {15 public static void main(String[] args) {16 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();17 ArrayList<Validator<?>> validators = new ArrayList<Validator<?>>();18 validators.add(new DefaultMessageValidator());19 receiveMessageAction.setValidators(validators);20 System.out.println(receiveMessageAction.getValidators());21 }22}23package com.consol.citrus;24import java.util.ArrayList;25public class Test {26 public static void main(String[] args) {27 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();28 ArrayList<Validator<?>> validators = new ArrayList<Validator<?>>();29 validators.add(new DefaultMessageValidator());30 receiveMessageAction.setValidators(validators);31 System.out.println(receiveMessageAction.getValidator());32 }33}34package com.consol.citrus;35import java.util.ArrayList;36public class Test {37 public static void main(String[] args) {38 ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();39 ArrayList<Validator<?>> validators = new ArrayList<Validator<?>>();40 validators.add(new DefaultMessageValidator());41 receiveMessageAction.setValidator(new DefaultMessageValidator());42 System.out.println(receiveMessageAction.getValidator());43 }44}

Full Screen

Full Screen

getValidators

Using AI Code Generation

copy

Full Screen

1package org.citrusframework.demo;2import java.util.List;3import org.citrusframework.demo.actions.ReceiveMessageAction;4import org.citrusframework.demo.validators.MessageValidator;5import org.testng.annotations.Test;6public class ReceiveMessageActionTest {7public void testReceiveMessageAction() {8ReceiveMessageAction receiveMessageAction = new ReceiveMessageAction();9List<MessageValidator> validators = receiveMessageAction.getValidators();10System.out.println(validators);11}12}13package org.citrusframework.demo.actions;14import java.util.ArrayList;15import java.util.List;16import org.citrusframework.demo.validators.MessageValidator;17import org.citrusframework.demo.validators.impl.PayloadTemplateMessageValidator;18import org.citrusframework.demo.validators.impl.XpathMessageValidator;19import org.springframework.util.StringUtils;20import com.consol.citrus.actions.ReceiveMessageAction;21public class ReceiveMessageActionTest extends ReceiveMessageAction {22public List<MessageValidator> getValidators() {23List<MessageValidator> validators = new ArrayList<MessageValidator>();24if (StringUtils.hasText(getPayloadTemplateResourcePath())) {25validators.add(new PayloadTemplateMessageValidator(getPayloadTemplateResourcePath(), getPayloadData()));26}27if (StringUtils.hasText(getValidationScript())) {28validators.add(new ScriptMessageValidator(getValidationScript(), getScriptEngine()));29}30if (StringUtils.hasText(getValidationContext())) {31validators.add(new ScriptMessageValidator(getValidationContext(), getScriptEngine()));32}33if (StringUtils.hasText(getValidationScriptResourcePath())) {34validators.add(new ScriptMessageValidator(getValidationScriptResourcePath(), getScriptEngine()));35}36if (StringUtils.hasText(getValidationContextResourcePath())) {37validators.add(new ScriptMessageValidator(getValidationContextResourcePath(), getScriptEngine()));38}39if (getValidationCallback() != null) {40validators.add(new CallbackMessageValidator(getValidationCallback()));41}42if (getValidationCallbackClass() != null) {43validators.add(new CallbackMessageValidator(getValidationCallbackClass()));44}45if (getValidationCallbackInstance() != null) {46validators.add(new CallbackMessageValidator(getValidationCallbackInstance()));47}48if (StringUtils.hasText(getValidationXPathExpressions())) {49validators.add(new XpathMessageValidator(getValidationXPathExpressions()));50}51if (StringUtils.hasText(getValidationXPathNamespaces())) {52validators.add(new XpathMessageValidator(getValidationXPathNamespaces()));53}54if (getValidationJsonPathExpressions() != null) {55validators.add(new JsonPathMessageValidator(getValidationJsonPathExpressions()));56}57if (get

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful