Best Citrus code snippet using com.consol.citrus.validation.MessageValidatorRegistry.findMessageValidators
Source:MessageValidatorRegistryTest.java
...37 List<MessageValidator<? extends ValidationContext>> messageValidators = new ArrayList<>();38 messageValidators.add(new PlainTextMessageValidator());39 messageValidatorRegistry.setMessageValidators(messageValidators);40 messageValidatorRegistry.afterPropertiesSet();41 List<MessageValidator<? extends ValidationContext>> matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage(""));42 Assert.assertNotNull(matchingValidators);43 Assert.assertEquals(matchingValidators.size(), 1L);44 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);45 try {46 messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage(""));47 Assert.fail("Missing exception due to no matching validator implementation");48 } catch (CitrusRuntimeException e) {49 Assert.assertTrue(e.getMessage().startsWith("Could not find proper message validator for message type"));50 }51 messageValidatorRegistry.getMessageValidators().add(new DomXmlMessageValidator());52 messageValidatorRegistry.getMessageValidators().add(new GroovyScriptMessageValidator());53 List<ValidationContext> validationContexts = new ArrayList<>();54 validationContexts.add(new HeaderValidationContext());55 validationContexts.add(new XmlMessageValidationContext());56 validationContexts.add(new JsonMessageValidationContext());57 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage(""));58 Assert.assertNotNull(matchingValidators);59 Assert.assertEquals(matchingValidators.size(), 2L);60 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);61 Assert.assertEquals(matchingValidators.get(1).getClass(), GroovyScriptMessageValidator.class);62 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));63 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));64 validationContexts.add(new ScriptValidationContext(MessageType.PLAINTEXT.name()));65 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage(""));66 Assert.assertNotNull(matchingValidators);67 Assert.assertEquals(matchingValidators.size(), 2L);68 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);69 Assert.assertEquals(matchingValidators.get(1).getClass(), GroovyScriptMessageValidator.class);70 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));71 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));72 validationContexts = new ArrayList<>();73 validationContexts.add(new HeaderValidationContext());74 validationContexts.add(new XmlMessageValidationContext());75 validationContexts.add(new JsonMessageValidationContext());76 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage(""));77 Assert.assertNotNull(matchingValidators);78 Assert.assertEquals(matchingValidators.size(), 1L);79 Assert.assertEquals(matchingValidators.get(0).getClass(), DomXmlMessageValidator.class);80 }81 @Test82 public void testMessageValidatorRegistryXmlConfig() throws Exception {83 MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorConfig().getMessageValidatorRegistry();84 messageValidatorRegistry.afterPropertiesSet();85 //non XML message type86 List<MessageValidator<? extends ValidationContext>> matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage(""));87 Assert.assertNotNull(matchingValidators);88 Assert.assertEquals(matchingValidators.size(), 3L);89 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);90 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);91 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);92 List<ValidationContext> validationContexts = new ArrayList<>();93 validationContexts.add(new HeaderValidationContext());94 validationContexts.add(new XmlMessageValidationContext());95 validationContexts.add(new JsonMessageValidationContext());96 //XML message type and empty payload97 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage(""));98 Assert.assertNotNull(matchingValidators);99 Assert.assertEquals(matchingValidators.size(), 4L);100 Assert.assertEquals(matchingValidators.get(0).getClass(), DomXmlMessageValidator.class);101 Assert.assertEquals(matchingValidators.get(1).getClass(), XpathMessageValidator.class);102 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyXmlMessageValidator.class);103 Assert.assertEquals(matchingValidators.get(3).getClass(), DefaultMessageHeaderValidator.class);104 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));105 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));106 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));107 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));108 //XML message type and non empty payload109 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage("<id>12345</id>"));110 Assert.assertNotNull(matchingValidators);111 Assert.assertEquals(matchingValidators.size(), 4L);112 Assert.assertEquals(matchingValidators.get(0).getClass(), DomXmlMessageValidator.class);113 Assert.assertEquals(matchingValidators.get(1).getClass(), XpathMessageValidator.class);114 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyXmlMessageValidator.class);115 Assert.assertEquals(matchingValidators.get(3).getClass(), DefaultMessageHeaderValidator.class);116 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));117 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));118 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));119 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));120 //script XML validation context121 validationContexts.add(new ScriptValidationContext(MessageType.XML.name()));122 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage(""));123 Assert.assertNotNull(matchingValidators);124 Assert.assertEquals(matchingValidators.size(), 4L);125 Assert.assertEquals(matchingValidators.get(0).getClass(), DomXmlMessageValidator.class);126 Assert.assertEquals(matchingValidators.get(1).getClass(), XpathMessageValidator.class);127 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyXmlMessageValidator.class);128 Assert.assertEquals(matchingValidators.get(3).getClass(), DefaultMessageHeaderValidator.class);129 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));130 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));131 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));132 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));133 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage("<id>12345</id>"));134 Assert.assertNotNull(matchingValidators);135 Assert.assertEquals(matchingValidators.size(), 4L);136 Assert.assertEquals(matchingValidators.get(0).getClass(), DomXmlMessageValidator.class);137 Assert.assertEquals(matchingValidators.get(1).getClass(), XpathMessageValidator.class);138 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyXmlMessageValidator.class);139 Assert.assertEquals(matchingValidators.get(3).getClass(), DefaultMessageHeaderValidator.class);140 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));141 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));142 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));143 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));144 //xpath message validation context145 validationContexts = new ArrayList<>();146 validationContexts.add(new HeaderValidationContext());147 validationContexts.add(new XmlMessageValidationContext());148 validationContexts.add(new JsonMessageValidationContext());149 validationContexts.add(new XpathMessageValidationContext());150 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage(""));151 Assert.assertNotNull(matchingValidators);152 Assert.assertEquals(matchingValidators.size(), 4L);153 Assert.assertEquals(matchingValidators.get(0).getClass(), DomXmlMessageValidator.class);154 Assert.assertEquals(matchingValidators.get(1).getClass(), XpathMessageValidator.class);155 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyXmlMessageValidator.class);156 Assert.assertEquals(matchingValidators.get(3).getClass(), DefaultMessageHeaderValidator.class);157 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));158 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));159 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));160 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));161 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage("<id>12345</id>"));162 Assert.assertNotNull(matchingValidators);163 Assert.assertEquals(matchingValidators.size(), 4L);164 Assert.assertEquals(matchingValidators.get(0).getClass(), DomXmlMessageValidator.class);165 Assert.assertEquals(matchingValidators.get(1).getClass(), XpathMessageValidator.class);166 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyXmlMessageValidator.class);167 Assert.assertEquals(matchingValidators.get(3).getClass(), DefaultMessageHeaderValidator.class);168 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));169 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));170 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));171 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));172 }173 @Test174 public void testMessageValidatorRegistryJsonConfig() throws Exception {175 MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorConfig().getMessageValidatorRegistry();176 messageValidatorRegistry.afterPropertiesSet();177 List<ValidationContext> validationContexts = new ArrayList<>();178 validationContexts.add(new HeaderValidationContext());179 validationContexts.add(new XmlMessageValidationContext());180 validationContexts.add(new JsonMessageValidationContext());181 //JSON message type and empty payload182 List<MessageValidator<? extends ValidationContext>> matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage(""));183 Assert.assertNotNull(matchingValidators);184 Assert.assertEquals(matchingValidators.size(), 4L);185 Assert.assertEquals(matchingValidators.get(0).getClass(), JsonTextMessageValidator.class);186 Assert.assertEquals(matchingValidators.get(1).getClass(), JsonPathMessageValidator.class);187 Assert.assertEquals(matchingValidators.get(2).getClass(), DefaultMessageHeaderValidator.class);188 Assert.assertEquals(matchingValidators.get(3).getClass(), GroovyJsonMessageValidator.class);189 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));190 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));191 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));192 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));193 //JSON message type and non empty payload194 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage("{ \"id\": 12345 }"));195 Assert.assertNotNull(matchingValidators);196 Assert.assertEquals(matchingValidators.size(), 4L);197 Assert.assertEquals(matchingValidators.get(0).getClass(), JsonTextMessageValidator.class);198 Assert.assertEquals(matchingValidators.get(1).getClass(), JsonPathMessageValidator.class);199 Assert.assertEquals(matchingValidators.get(2).getClass(), DefaultMessageHeaderValidator.class);200 Assert.assertEquals(matchingValidators.get(3).getClass(), GroovyJsonMessageValidator.class);201 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));202 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));203 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));204 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));205 //script JSON validation context206 validationContexts.add(new ScriptValidationContext(MessageType.JSON.name()));207 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage(""));208 Assert.assertNotNull(matchingValidators);209 Assert.assertEquals(matchingValidators.size(), 4L);210 Assert.assertEquals(matchingValidators.get(0).getClass(), JsonTextMessageValidator.class);211 Assert.assertEquals(matchingValidators.get(1).getClass(), JsonPathMessageValidator.class);212 Assert.assertEquals(matchingValidators.get(2).getClass(), DefaultMessageHeaderValidator.class);213 Assert.assertEquals(matchingValidators.get(3).getClass(), GroovyJsonMessageValidator.class);214 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));215 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));216 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));217 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));218 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage("{ \"id\": 12345 }"));219 Assert.assertNotNull(matchingValidators);220 Assert.assertEquals(matchingValidators.size(), 4L);221 Assert.assertEquals(matchingValidators.get(0).getClass(), JsonTextMessageValidator.class);222 Assert.assertEquals(matchingValidators.get(1).getClass(), JsonPathMessageValidator.class);223 Assert.assertEquals(matchingValidators.get(2).getClass(), DefaultMessageHeaderValidator.class);224 Assert.assertEquals(matchingValidators.get(3).getClass(), GroovyJsonMessageValidator.class);225 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));226 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));227 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));228 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));229 //json path message validation context230 validationContexts = new ArrayList<>();231 validationContexts.add(new HeaderValidationContext());232 validationContexts.add(new XmlMessageValidationContext());233 validationContexts.add(new JsonMessageValidationContext());234 validationContexts.add(new JsonPathMessageValidationContext());235 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage(""));236 Assert.assertNotNull(matchingValidators);237 Assert.assertEquals(matchingValidators.size(), 4L);238 Assert.assertEquals(matchingValidators.get(0).getClass(), JsonTextMessageValidator.class);239 Assert.assertEquals(matchingValidators.get(1).getClass(), JsonPathMessageValidator.class);240 Assert.assertEquals(matchingValidators.get(2).getClass(), DefaultMessageHeaderValidator.class);241 Assert.assertEquals(matchingValidators.get(3).getClass(), GroovyJsonMessageValidator.class);242 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));243 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));244 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));245 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));246 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage("{ \"id\": 12345 }"));247 Assert.assertNotNull(matchingValidators);248 Assert.assertEquals(matchingValidators.size(), 4L);249 Assert.assertEquals(matchingValidators.get(0).getClass(), JsonTextMessageValidator.class);250 Assert.assertEquals(matchingValidators.get(1).getClass(), JsonPathMessageValidator.class);251 Assert.assertEquals(matchingValidators.get(2).getClass(), DefaultMessageHeaderValidator.class);252 Assert.assertEquals(matchingValidators.get(3).getClass(), GroovyJsonMessageValidator.class);253 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));254 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));255 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));256 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));257 }258 @Test259 public void testMessageValidatorRegistryPlaintextConfig() throws Exception {260 MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorConfig().getMessageValidatorRegistry();261 messageValidatorRegistry.afterPropertiesSet();262 List<ValidationContext> validationContexts = new ArrayList<>();263 validationContexts.add(new HeaderValidationContext());264 validationContexts.add(new XmlMessageValidationContext());265 validationContexts.add(new JsonMessageValidationContext());266 //Plaintext message type and empty payload267 List<MessageValidator<? extends ValidationContext>> matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage(""));268 Assert.assertNotNull(matchingValidators);269 Assert.assertEquals(matchingValidators.size(), 3L);270 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);271 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);272 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);273 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));274 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));275 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));276 //Plaintext message type and non empty payload277 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage("id=12345"));278 Assert.assertNotNull(matchingValidators);279 Assert.assertEquals(matchingValidators.size(), 3L);280 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);281 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);282 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);283 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));284 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));285 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));286 //script plaintext validation context287 validationContexts.add(new ScriptValidationContext(MessageType.PLAINTEXT.name()));288 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage(""));289 Assert.assertNotNull(matchingValidators);290 Assert.assertEquals(matchingValidators.size(), 3L);291 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);292 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);293 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);294 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));295 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));296 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));297 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage("id=12345"));298 Assert.assertNotNull(matchingValidators);299 Assert.assertEquals(matchingValidators.size(), 3L);300 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);301 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);302 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);303 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));304 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));305 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));306 }307 @Test308 public void testMessageValidatorRegistryFallback() throws Exception {309 MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorConfig().getMessageValidatorRegistry();310 messageValidatorRegistry.afterPropertiesSet();311 List<ValidationContext> validationContexts = new ArrayList<>();312 validationContexts.add(new HeaderValidationContext());313 validationContexts.add(new XmlMessageValidationContext());314 validationContexts.add(new JsonMessageValidationContext());315 List<MessageValidator<? extends ValidationContext>> matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage("{ \"id\": 12345 }"));316 Assert.assertNotNull(matchingValidators);317 Assert.assertEquals(matchingValidators.size(), 4L);318 Assert.assertEquals(matchingValidators.get(0).getClass(), JsonTextMessageValidator.class);319 Assert.assertEquals(matchingValidators.get(1).getClass(), JsonPathMessageValidator.class);320 Assert.assertEquals(matchingValidators.get(2).getClass(), DefaultMessageHeaderValidator.class);321 Assert.assertEquals(matchingValidators.get(3).getClass(), GroovyJsonMessageValidator.class);322 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));323 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));324 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));325 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));326 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage("<id>12345</id>"));327 Assert.assertNotNull(matchingValidators);328 Assert.assertEquals(matchingValidators.size(), 4L);329 Assert.assertEquals(matchingValidators.get(0).getClass(), DomXmlMessageValidator.class);330 Assert.assertEquals(matchingValidators.get(1).getClass(), XpathMessageValidator.class);331 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyXmlMessageValidator.class);332 Assert.assertEquals(matchingValidators.get(3).getClass(), DefaultMessageHeaderValidator.class);333 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));334 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));335 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));336 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(3)).findValidationContext(validationContexts));337 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage("<id>12345</id>"));338 Assert.assertNotNull(matchingValidators);339 Assert.assertEquals(matchingValidators.size(), 3L);340 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);341 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);342 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);343 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));344 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));345 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));346 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name(), new DefaultMessage("{ \"id\": 12345 }"));347 Assert.assertNotNull(matchingValidators);348 Assert.assertEquals(matchingValidators.size(), 3L);349 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);350 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);351 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);352 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));353 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));354 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));355 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.XML.name(), new DefaultMessage("id=12345"));356 Assert.assertNotNull(matchingValidators);357 Assert.assertEquals(matchingValidators.size(), 3L);358 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);359 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);360 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);361 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));362 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));363 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));364 matchingValidators = messageValidatorRegistry.findMessageValidators(MessageType.JSON.name(), new DefaultMessage("id=12345"));365 Assert.assertNotNull(matchingValidators);366 Assert.assertEquals(matchingValidators.size(), 3L);367 Assert.assertEquals(matchingValidators.get(0).getClass(), PlainTextMessageValidator.class);368 Assert.assertEquals(matchingValidators.get(1).getClass(), DefaultMessageHeaderValidator.class);369 Assert.assertEquals(matchingValidators.get(2).getClass(), GroovyScriptMessageValidator.class);370 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(0)).findValidationContext(validationContexts));371 Assert.assertNotNull(((AbstractMessageValidator)matchingValidators.get(1)).findValidationContext(validationContexts));372 Assert.assertNull(((AbstractMessageValidator)matchingValidators.get(2)).findValidationContext(validationContexts));373 }374 @Test(expectedExceptions = CitrusRuntimeException.class)375 public void testEmptyListOfMessageValidators() throws Exception {376 MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();377 messageValidatorRegistry.afterPropertiesSet();378 }...
Source:MessageValidatorRegistry.java
...45 * @param messageType the message type46 * @param message the message object47 * @return the list of matching message validators.48 */49 public List<MessageValidator<? extends ValidationContext>> findMessageValidators(String messageType, Message message) {50 List<MessageValidator<? extends ValidationContext>> matchingValidators = new ArrayList<>();51 for (MessageValidator<? extends ValidationContext> validator : messageValidators) {52 if (validator.supportsMessageType(messageType, message)) {53 matchingValidators.add(validator);54 }55 }56 if (matchingValidators.isEmpty() || matchingValidators.stream().allMatch(validator -> DefaultMessageHeaderValidator.class.isAssignableFrom(validator.getClass()))) {57 // try to find fallback message validator for given message payload58 if (message.getPayload() instanceof String &&59 StringUtils.hasText(message.getPayload(String.class))) {60 String payload = message.getPayload(String.class).trim();61 if (payload.startsWith("<") && !messageType.equals(MessageType.XML.name())) {62 matchingValidators = findFallbackMessageValidators(MessageType.XML.name(), message);63 } else if ((payload.trim().startsWith("{") || payload.trim().startsWith("[")) && !messageType.equals(MessageType.JSON.name())) {...
findMessageValidators
Using AI Code Generation
1package com.consol.citrus;2import com.consol.citrus.validation.MessageValidator;3import com.consol.citrus.validation.MessageValidatorRegistry;4import com.consol.citrus.validation.context.ValidationContext;5import com.consol.citrus.validation.xml.XmlMessageValidationContext;6import com.consol.citrus.validation.xml.XmlMessageValidationContextBuilder;7import com.consol.citrus.validation.xml.XmlMessageValidator;8import com.consol.citrus.message.DefaultMessage;9import java.util.List;10import java.util.Map;11import java.util.HashMap;12public class Main {13 public static void main(String[] args) {14 MessageValidatorRegistry registry = new MessageValidatorRegistry();15 registry.addMessageValidator(new XmlMessageValidator());16 Map<String, String> namespaces = new HashMap<String, String>();17 ValidationContext context = new XmlMessageValidationContextBuilder().withNamespaces(namespaces).build();18 System.out.println("Validators for message validation: " + validators);19 }20}
findMessageValidators
Using AI Code Generation
1package com.consol.citrus.validation;2import java.util.List;3import org.springframework.context.ApplicationContext;4import org.springframework.context.support.ClassPathXmlApplicationContext;5import com.consol.citrus.message.MessageType;6public class FindMessageValidators {7 public static void main(String[] args) {8 ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");9 MessageValidatorRegistry messageValidatorRegistry = ctx.getBean(MessageValidatorRegistry.class);10 List<MessageValidator> messageValidators = messageValidatorRegistry.findMessageValidators(MessageType.PLAINTEXT.name());11 System.out.println("Message Validators: " + messageValidators);12 }13}
findMessageValidators
Using AI Code Generation
1import com.consol.citrus.validation.MessageValidatorRegistry;2import com.consol.citrus.validation.MessageValidator;3import java.util.Set;4import java.util.Iterator;5public class 4 {6public static void main(String[] args) {7MessageValidatorRegistry mvr = new MessageValidatorRegistry();8Set<MessageValidator> s = mvr.findMessageValidators("XML", "JSON");9Iterator<MessageValidator> i = s.iterator();10while(i.hasNext()) {11System.out.println(i.next());12}13}14}15import com.consol.citrus.validation.MessageValidatorRegistry;16import com.consol.citrus.validation.MessageValidator;17public class 5 {18public static void main(String[] args) {19MessageValidatorRegistry mvr = new MessageValidatorRegistry();20MessageValidator mv = mvr.findMessageValidator("XML");21System.out.println(mv);22}23}24import com.consol.citrus.validation.MessageValidatorRegistry;25import com.consol.citrus.validation.MessageValidator;26public class 6 {27public static void main(String[] args) {28MessageValidatorRegistry mvr = new MessageValidatorRegistry();29MessageValidator mv = mvr.findMessageValidator("XML");30System.out.println(mv);31}32}33import com.consol.citrus.validation.MessageValidatorRegistry;34import com.consol.citrus.validation.MessageValidator;35public class 7 {36public static void main(String[] args) {37MessageValidatorRegistry mvr = new MessageValidatorRegistry();38MessageValidator mv = mvr.findMessageValidator("XML");39System.out.println(mv);40}41}
findMessageValidators
Using AI Code Generation
1package com.consol.citrus.validation;2import java.util.List;3import org.springframework.context.ApplicationContext;4import org.springframework.context.support.ClassPathXmlApplicationContext;5import org.testng.annotations.Test;6public class FindMessageValidators {7 public void testFindMessageValidators() {8 ApplicationContext context = new ClassPathXmlApplicationContext("classpath:com/consol/citrus/validation/findMessageValidators.xml");9 MessageValidatorRegistry registry = context.getBean("messageValidatorRegistry", MessageValidatorRegistry.class);10 List<MessageValidator<? extends ValidationContext>> validators = registry.findMessageValidators("TestMessage", "TestMessage");11 System.out.println("Found " + validators.size() + " message validators");12 }13}14package com.consol.citrus.validation;15import org.springframework.stereotype.Component;16public class TestMessageValidator implements MessageValidator<TestMessage> {17 public void validateMessagePayload(TestMessage message, TestMessage control, TestValidationContext context) {18 }19 public void validateMessageHeader(TestMessage message, TestMessage control, TestValidationContext context) {20 }21 public boolean supportsMessageType(String messageType) {22 return messageType.equals("TestMessage
findMessageValidators
Using AI Code Generation
1package com.consol.citrus.validation;2import java.util.List;3import java.util.Map;4import java.util.Set;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.context.ApplicationContext;7import org.testng.Assert;8import org.testng.annotations.Test;9import com.consol.citrus.context.TestContext;10import com.consol.citrus.message.DefaultMessage;11import com.consol.citrus.message.Message;12import com.consol.citrus.validation.context.ValidationContext;13import com.consol.citrus.validation.matcher.ValidationMatcher;14import com.consol.citrus.validation.matcher.ValidationMatcherUtils;15import com.consol.citrus.validation.script.GroovyScriptMessageProcessor;16import com.consol.citrus.validation.script.ScriptValidationContext;17import com.consol.citrus.validation.xml.DomXmlMessageValidationContext;18import com.consol.citrus.validation.xml.DomXmlMessageValidator;19import com.consol.citrus.validation.xml.XpathMessageProcessor;20import com.consol.citrus.validation.xml.XpathMessageValidationContext;21import com.consol.citrus.xml.namespace.NamespaceContextBuilder;22import com.consol.citrus.xml.namespace.SimpleNamespaceContextBuilder;23import com.consol.citrus.xml.schema.SchemaRepository;24import com.consol.citrus.xml.schema.XmlSchemaRepository;25import com.consol.citrus.xml.schema.XsdSchemaValidationContext;26import com.consol.citrus.xml.schema.XsdSchemaValidator;27public class FindMessageValidatorsTest {28private ApplicationContext applicationContext;29public void testFindMessageValidators() {30TestContext context = new TestContext();31DefaultMessage message = new DefaultMessage("<TestMessage><Text>Hello Citrus!</Text></TestMessage>");32DefaultMessage controlMessage = new DefaultMessage("<TestMessage><Text>Hello Citrus!</Text></TestMessage>");33Map<String, Object> messageHeaders = message.getHeaders();34Map<String, Object> controlMessageHeaders = controlMessage.getHeaders();35List<MessageValidator> messageValidators = new MessageValidatorRegistry(applicationContext).findMessageValidators(message, controlMessage, context);36Assert.assertEquals(messageValidators.size(), 1);37Assert.assertEquals(messageValidators.get(0).getClass(), DomXmlMessageValidator.class);38DomXmlMessageValidator validator = (DomXmlMessageValidator) messageValidators.get(0);39Map<String, ValidationContext> validationContexts = validator.getValidationContexts();40Assert.assertEquals(validationContexts.size(), 2);41Assert.assertTrue(validationContexts.containsKey("XPATH"));
findMessageValidators
Using AI Code Generation
1package com.consol.citrus.validation;2import java.util.List;3import org.testng.annotations.Test;4import org.testng.Assert;5import org.testng.AssertJUnit;6import org.testng.annotations.BeforeMethod;7import org.testng.annotations.AfterMethod;8import org.testng.annotations.DataProvider;9import org.testng.annotations.Test;10import com.consol.citrus.exceptions.CitrusRuntimeException;11import com.consol.citrus.message.Message;12import com.consol.citrus.message.MessageType;13import com.consol.citrus.validation.context.ValidationContext;14import com.consol.citrus.validation.context.ValidationContextFactory;15import com.consol.citrus.validation.xml.XmlMessageValidationContext;16import com.consol.citrus.validation.xml.XmlMessageValidationContextFactory;17import com.consol.citrus.validation.xml.XmlMessageValidationContextFactoryTest;18import com.consol.citrus.validation.xml.XmlMessageValidator;19import com.consol.citrus.validation.xml.XmlSchemaValidationContext;20import com.consol.citrus.validation.xml.XpathMessageValidationContext;21public class MessageValidatorRegistryTest {22 public void testFindMessageValidators() throws Exception {23 MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();24 List<MessageValidator<? extends ValidationContext>> messageValidators = messageValidatorRegistry.findMessageValidators(25 MessageType.PLAINTEXT.name(), new ValidationContextFactory[] { new XmlMessageValidationContextFactory() });26 AssertJUnit.assertEquals(1, messageValidators.size());27 AssertJUnit.assertEquals(XmlMessageValidator.class, messageValidators.get(0).getClass());28 }29}30package com.consol.citrus.validation;31import java.util.List;32import org.testng.annotations.Test;33import org.testng.Assert;34import org.testng.AssertJUnit;35import org.testng.annotations.BeforeMethod;36import org.testng.annotations.AfterMethod;37import org.testng.annotations.DataProvider;38import org.testng.annotations.Test;39import com.consol.citrus.exceptions.CitrusRuntimeException;40import com.consol.citrus.message.Message;41import com.consol.citrus.message.MessageType;42import com.consol.citrus.validation.context.ValidationContext;43import com.consol.citrus.validation.context.ValidationContextFactory;44import com.consol.citrus.validation.xml.XmlMessageValidationContext;45import com.consol.citrus.validation.xml.XmlMessageValidationContextFactory;46import com.consol.citrus.validation.xml.XmlMessageValidationContextFactoryTest;
findMessageValidators
Using AI Code Generation
1public class 4 {2 public static void main(String[] args) {3 MessageValidatorRegistry registry = new MessageValidatorRegistry();4 registry.findMessageValidators("com.consol.citrus.validation.xml.XmlMessageValidationContext");5 }6}7public class 5 {8 public static void main(String[] args) {9 MessageValidatorRegistry registry = new MessageValidatorRegistry();10 registry.findMessageValidator("com.consol.citrus.validation.xml.XmlMessageValidationContext");11 }12}13public class 6 {14 public static void main(String[] args) {15 MessageValidatorRegistry registry = new MessageValidatorRegistry();16 registry.findMessageValidator("com.consol.citrus.validation.xml.XmlMessageValidationContext");17 }18}19public class 7 {20 public static void main(String[] args) {21 MessageValidatorRegistry registry = new MessageValidatorRegistry();22 registry.findMessageValidator("com.consol.citrus.validation.xml.XmlMessageValidationContext");23 }24}25public class 8 {26 public static void main(String[] args) {27 MessageValidatorRegistry registry = new MessageValidatorRegistry();28 registry.findMessageValidator("com.consol.citrus.validation.xml.XmlMessageValidationContext");29 }30}31public class 9 {32 public static void main(String[] args) {33 MessageValidatorRegistry registry = new MessageValidatorRegistry();34 registry.findMessageValidator("com.consol.citrus.validation.xml.XmlMessageValidationContext");35 }36}37public class 10 {38 public static void main(String[] args) {39 MessageValidatorRegistry registry = new MessageValidatorRegistry();40 registry.findMessageValidator("com.consol.citrus.validation.xml.XmlMessage
findMessageValidators
Using AI Code Generation
1package com.consol.citrus.validation;2import java.util.List;3public class Path4 {4public static void main(String[] args) {5MessageValidatorRegistry registry = new MessageValidatorRegistry();6List<MessageValidator<?>> validators = registry.findMessageValidators("text/xml");7for (MessageValidator<?> validator : validators) {8System.out.println(validator);9}10}11}12package com.consol.citrus.validation;13import java.util.List;14public class Path5 {15public static void main(String[] args) {16MessageValidatorRegistry registry = new MessageValidatorRegistry();17List<MessageValidator<?>> validators = registry.findMessageValidators("text/xml");18for (MessageValidator<?> validator : validators) {19System.out.println(validator);20}21}22}23package com.consol.citrus.validation;24import java.util.List;25public class Path6 {26public static void main(String[] args) {27MessageValidatorRegistry registry = new MessageValidatorRegistry();28List<MessageValidator<?>> validators = registry.findMessageValidators("text/xml");29for (MessageValidator<?> validator : validators) {30System.out.println(validator);31}32}33}34package com.consol.citrus.validation;35import java.util.List;36public class Path7 {37public static void main(String[] args) {38MessageValidatorRegistry registry = new MessageValidatorRegistry();39List<MessageValidator<?>> validators = registry.findMessageValidators("text/xml");40for (MessageValidator<?> validator : validators) {41System.out.println(validator);42}43}44}45package com.consol.citrus.validation;46import java.util.List;47public class Path8 {48public static void main(String[] args) {49MessageValidatorRegistry registry = new MessageValidatorRegistry();50List<MessageValidator<?>> validators = registry.findMessageValidators("text/xml");51for (MessageValidator<?> validator : validators) {52System.out.println(validator);53}54}55}
findMessageValidators
Using AI Code Generation
1MessageValidatorRegistry registry = new MessageValidatorRegistry();2List<MessageValidator<? extends ValidationContext>> validators = registry.findMessageValidators("myValidator", context);3MessageValidatorRegistry registry = new MessageValidatorRegistry();4MessageValidator<? extends ValidationContext> validator = registry.findMessageValidator("myValidator", context);5MessageValidatorRegistry registry = new MessageValidatorRegistry();6ValidationContext context = registry.findValidationContext("myValidator", context);7MessageValidatorRegistry registry = new MessageValidatorRegistry();8List<ValidationContext> contexts = registry.findValidationContexts("myValidator", context);9MessageValidatorRegistry registry = new MessageValidatorRegistry();10ValidationContext context = registry.findValidationContext("myValidator", context);11MessageValidatorRegistry registry = new MessageValidatorRegistry();12List<ValidationContext> contexts = registry.findValidationContexts("myValidator", context);13MessageValidatorRegistry registry = new MessageValidatorRegistry();14ValidationContext context = registry.findValidationContext("myValidator", context);15MessageValidatorRegistry registry = new MessageValidatorRegistry();16List<ValidationContext> contexts = registry.findValidationContexts("myValidator", context);17MessageValidatorRegistry registry = new MessageValidatorRegistry();18ValidationContext context = registry.findValidationContext("myValidator", context);19MessageValidatorRegistry registry = new MessageValidatorRegistry();20List<ValidationContext> contexts = registry.findValidationContexts("myValidator", context);21MessageValidatorRegistry registry = new MessageValidatorRegistry();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!