How to use DomXmlMessageValidator method of com.consol.citrus.validation.MessageValidatorConfig class

Best Citrus code snippet using com.consol.citrus.validation.MessageValidatorConfig.DomXmlMessageValidator

Source:MessageValidatorRegistryTest.java Github

copy

Full Screen

...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));...

Full Screen

Full Screen

Source:MessageValidatorConfig.java Github

copy

Full Screen

...19import com.consol.citrus.validation.script.*;20import com.consol.citrus.validation.text.*;21import com.consol.citrus.validation.xhtml.XhtmlMessageValidator;22import com.consol.citrus.validation.xhtml.XhtmlXpathMessageValidator;23import com.consol.citrus.validation.xml.DomXmlMessageValidator;24import com.consol.citrus.validation.xml.XpathMessageValidator;25import org.springframework.context.annotation.Bean;26import org.springframework.context.annotation.Configuration;27/**28 * @author Christoph Deppisch29 * @since 2.030 */31@Configuration32public class MessageValidatorConfig {33 private final DefaultMessageHeaderValidator defaultMessageHeaderValidator = new DefaultMessageHeaderValidator();34 private final DomXmlMessageValidator defaultXmlMessageValidator = new DomXmlMessageValidator();35 private final XpathMessageValidator defaultXpathMessageValidator = new XpathMessageValidator();36 private final JsonTextMessageValidator defaultJsonMessageValidator = new JsonTextMessageValidator();37 private final JsonPathMessageValidator defaultJsonPathMessageValidator = new JsonPathMessageValidator();38 private final PlainTextMessageValidator defaultPlaintextMessageValidator = new PlainTextMessageValidator();39 private final BinaryMessageValidator defaultBinaryMessageValidator = new BinaryMessageValidator();40 private final BinaryBase64MessageValidator defaultBinaryBase64MessageValidator = new BinaryBase64MessageValidator();41 private final GzipBinaryBase64MessageValidator defaultGzipBinaryBase64MessageValidator = new GzipBinaryBase64MessageValidator();42 private final XhtmlMessageValidator defaultXhtmlMessageValidator = new XhtmlMessageValidator();43 private final XhtmlXpathMessageValidator defaultXhtmlXpathMessageValidator = new XhtmlXpathMessageValidator();44 private final GroovyXmlMessageValidator defaultGroovyXmlMessageValidator = new GroovyXmlMessageValidator();45 private final GroovyJsonMessageValidator defaultGroovyJsonMessageValidator = new GroovyJsonMessageValidator();46 private final GroovyScriptMessageValidator defaultGroovyTextMessageValidator = new GroovyScriptMessageValidator();47 @Bean(name = "defaultXmlMessageValidator")48 public DomXmlMessageValidator getDefaultXmlMessageValidator() {49 return defaultXmlMessageValidator;50 }51 @Bean(name = "defaultMessageHeaderValidator")52 public DefaultMessageHeaderValidator getDefaultMessageHeaderValidator() {53 return defaultMessageHeaderValidator;54 }55 @Bean(name = "defaultXpathMessageValidator")56 public XpathMessageValidator getDefaultXpathMessageValidator() {57 return defaultXpathMessageValidator;58 }59 @Bean(name = "defaultJsonMessageValidator")60 public JsonTextMessageValidator getDefaultJsonTextMessageValidator() {61 return defaultJsonMessageValidator;62 }...

Full Screen

Full Screen

DomXmlMessageValidator

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;4import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.validation.builder.StaticMessageContentBuilder;7import com.consol.citrus.validation.xml.DomXmlMessageValidator;8import org.springframework.core.io.ClassPathResource;9import org.testng.annotations.Test;10import java.io.IOException;11public class DomXmlMessageValidatorTest extends TestNGCitrusTestRunner {12 public void validateXmlMessage() throws IOException {13 variable("name", "Citrus");14 variable("id", "1234");15 send("messageSender")16 .payload("<TestMessage><text>Hello ${name}!</text><id>${id}</id></TestMessage>")17 .messageType(MessageType.XML);18 receive("messageReceiver")19 .payload("<TestMessage><text>Hello Citrus!</text><id>1234</id></TestMessage>")20 .messageType(MessageType.XML)21 .validator(new DomXmlMessageValidator()22 .controlSchema(new ClassPathResource("schema.xsd"))23 .ignoreSchemaLocation(true));24 }25}26package com.consol.citrus.samples;27import com.consol.citrus.annotations.CitrusTest;28import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;29import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;30import com.consol.citrus.message.MessageType;31import com.consol.citrus.validation.builder.StaticMessageContentBuilder;32import com.consol.citrus.validation.xml.DomXmlMessageValidator;33import com.consol.citrus.validation.xml.XpathMessageValidator;34import org.springframework.core.io.ClassPathResource;35import org.testng.annotations.Test;36import java.io.IOException;37public class XpathMessageValidatorTest extends TestNGCitrusTestRunner {38 public void validateXmlMessage() throws IOException {39 variable("name", "Citrus");

Full Screen

Full Screen

DomXmlMessageValidator

Using AI Code Generation

copy

Full Screen

1public class DomXmlMessageValidator extends AbstractMessageValidator<DomXmlMessageValidationContext> {2 public void validateMessage(Message receivedMessage, Message controlMessage, MessageValidationContext validationContext) {3 try {4 DomXmlMessageValidationContext domXmlMessageValidationContext = new DomXmlMessageValidationContext();5 domXmlMessageValidationContext.setReceivedMessage(receivedMessage);6 domXmlMessageValidationContext.setControlMessage(controlMessage);7 domXmlMessageValidationContext.setValidationContext(validationContext);8 validateMessage(domXmlMessageValidationContext);9 } catch (Exception e) {10 throw new CitrusRuntimeException("Failed to validate XML message", e);11 }12 }13}14public class DomXmlMessageValidator extends AbstractMessageValidator<DomXmlMessageValidationContext> {15 public void validateMessage(Message receivedMessage, Message controlMessage, MessageValidationContext validationContext) {16 try {17 DomXmlMessageValidationContext domXmlMessageValidationContext = new DomXmlMessageValidationContext();18 domXmlMessageValidationContext.setReceivedMessage(receivedMessage);19 domXmlMessageValidationContext.setControlMessage(controlMessage);20 domXmlMessageValidationContext.setValidationContext(validationContext);21 validateMessage(domXmlMessageValidationContext);22 } catch (Exception e) {23 throw new CitrusRuntimeException("Failed to validate XML message", e);24 }25 }26}

Full Screen

Full Screen

DomXmlMessageValidator

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.validation.xml;2import com.consol.citrus.message.Message;3import com.consol.citrus.testng.AbstractTestNGUnitTest;4import org.testng.Assert;5import org.testng.annotations.Test;6import org.w3c.dom.Document;7import javax.xml.parsers.DocumentBuilder;8import javax.xml.parsers.DocumentBuilderFactory;9import javax.xml.transform.Source;10import javax.xml.transform.dom.DOMSource;11public class DomXmlMessageValidatorTest extends AbstractTestNGUnitTest {12 public void testValidateMessagePayload() throws Exception {13 DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();14 Document controlDocument = documentBuilder.parse("src/test/resources/expected.xml");15 Document testDocument = documentBuilder.parse("src/test/resources/test.xml");16 DomXmlMessageValidator validator = new DomXmlMessageValidator();17 validator.setIgnoreWhitespace(true);18 validator.setIgnoreNamespaces(true);19 validator.setIgnoreComments(true);20 validator.validateMessagePayload(new DOMSource(controlDocument), new DOMSource(testDocument), context);21 }22 public void testValidateMessagePayloadWithResult() throws Exception {23 DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();24 Document controlDocument = documentBuilder.parse("src/test/resources/expected.xml");25 Document testDocument = documentBuilder.parse("src/test/resources/test.xml");26 DomXmlMessageValidator validator = new DomXmlMessageValidator();27 validator.setIgnoreWhitespace(true);28 validator.setIgnoreNamespaces(true);29 validator.setIgnoreComments(true);30 validator.validateMessagePayload(new DOMSource(controlDocument), new DOMSource(testDocument), context, new Message("TestMessage"));31 }32 public void testValidateMessagePayloadWithResultAndSchemaValidation() throws Exception {33 DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();34 Document controlDocument = documentBuilder.parse("src/test/resources/expected.xml");35 Document testDocument = documentBuilder.parse("src/test/resources/test.xml");36 DomXmlMessageValidator validator = new DomXmlMessageValidator();37 validator.setSchemaValidation(true);38 validator.setSchema("classpath:com/consol/citrus/validation/xml/test.xsd");39 validator.setIgnoreWhitespace(true);40 validator.setIgnoreNamespaces(true);41 validator.setIgnoreComments(true);42 validator.validateMessagePayload(new DOMSource(controlDocument), new DOMSource(testDocument), context, new Message("TestMessage"));43 }

Full Screen

Full Screen

DomXmlMessageValidator

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.validation.xml;2import com.consol.citrus.testng.AbstractTestNGUnitTest;3import org.testng.annotations.Test;4import java.io.IOException;5import static org.testng.Assert.assertEquals;6public class DomXmlMessageValidatorTest extends AbstractTestNGUnitTest {7public void testValidateMessageWithDTD() throws IOException {8String controlMessage = "<foo></foo>";9DomXmlMessageValidator domXmlMessageValidator = new DomXmlMessageValidator();10boolean isSame = domXmlMessageValidator.validateMessage(xmlMessage, controlMessage, context);11assertEquals(isSame, false);12}13}14package com.consol.citrus.validation.xml;15import com.consol.citrus.testng.AbstractTestNGUnitTest;16import org.testng.annotations.Test;17import java.io.IOException;18import static org.testng.Assert.assertEquals;19public class XpathXmlMessageValidatorTest extends AbstractTestNGUnitTest {20public void testValidateMessageWithXPath() throws IOException {21String xmlMessage = "<foo><bar>123</bar></foo>";22String controlMessage = "<foo><bar>123</bar></foo>";23XpathXmlMessageValidator xpathXmlMessageValidator = new XpathXmlMessageValidator();24boolean isSame = xpathXmlMessageValidator.validateMessage(xmlMessage, controlMessage, context);25assertEquals(isSame, true);26}27}28package com.consol.citrus.validation.xml;29import com.consol.citrus.testng.AbstractTestNGUnitTest;30import org.testng.annotations.Test;31import java.io.IOException;32import static org.testng.Assert.assertEquals;33public class XpathXmlMessageValidatorTest extends AbstractTestNGUnitTest {34public void testValidateMessageWithXPath() throws IOException {35String xmlMessage = "<foo><bar>123</bar></foo>";

Full Screen

Full Screen

DomXmlMessageValidator

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.message.Message;2import com.consol.citrus.message.MessageType;3import com.consol.citrus.validation.dom.DomXmlMessageValidator;4import com.consol.citrus.validation.xml.XmlMessageValidationContext;5import com.consol.citrus.exceptions.ValidationException;6import com.consol.citrus.message.DefaultMessage;7import com.consol.citrus.context.TestContext;8import com.consol.citrus.context.TestContextImpl;9import com.consol.citrus.validation.context.ValidationContext;10import com.consol.citrus.validation.context.ValidationContextFactory;11public class DomValidatorExample {12 public static void main(String[] args) {13 try {14 TestContext testContext = new TestContextImpl();15 ValidationContext validationContext = ValidationContextFactory.newInstance().create(MessageType.XML.name(), testContext);16 DomXmlMessageValidator domXmlMessageValidator = new DomXmlMessageValidator();17 Message message = new DefaultMessage("<testMessage><text>Hello World!</text></testMessage>");18 Message controlMessage = new DefaultMessage("<testMessage><text>Hello World!</text></testMessage>");19 domXmlMessageValidator.validateMessage(message, controlMessage, validationContext, testContext);20 System.out.println("Success");21 } catch (ValidationException ve) {22 System.out.println("Failure");23 }24 }25}26import com.consol.citrus.message.Message;27import com.consol.citrus.message.MessageType;28import com.consol.citrus.validation.dom.DomXmlMessage

Full Screen

Full Screen

DomXmlMessageValidator

Using AI Code Generation

copy

Full Screen

1String controlMessage = "<foo></foo>";2DomXmlMessageValidator domXmlMessageValidator = new DomXmlMessageValidator();3boolean isSame = domXmlMessageValidator.validateMessage(xmlMessage, controlMessage, context);4assertEquals(isSame, false);5}6}7package com.consol.citrus.validation.xml;8import com.consol.citrus.testng.AbstractTestNGUnitTest;9import org.testng.annotations.Test;10import java.io.IOException;11import static org.testng.Assert.assertEquals;12public class XpathXmlMessageValidatorTest extends AbstractTestNGUnitTest {13public void testValidateMessageWithXPath() throws IOException {14String xmlMessage = "<foo><bar>123</bar></foo>";15String controlMessage = "<foo><bar>123</bar></foo>";16XpathXmlMessageValidator xpathXmlMessageValidator = new XpathXmlMessageValidator();17boolean isSame = xpathXmlMessageValidator.validateMessage(xmlMessage, controlMessage, context);18assertEquals(isSame, true);19}20}21package com.consol.citrus.validation.xml;22import com.consol.citrus.testng.AbstractTestNGUnitTest;23import org.testng.annotations.Test;24import java.io.IOException;25import static org.testng.Assert.assertEquals;26public class XpathXmlMessageValidatorTest extends AbstractTestNGUnitTest {27public void testValidateMessageWithXPath() throws IOException {28String xmlMessage = "<foo><bar>123</bar></foo>";

Full Screen

Full Screen

DomXmlMessageValidator

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.message.Message;2import com.consol.citrus.message.MessageType;3import com.consol.citrus.validation.dom.DomXmlMessageValidator;4import com.consol.citrus.validation.xml.XmlMessageValidationContext;5import com.consol.citrus.exceptions.ValidationException;6import com.consol.citrus.message.DefaultMessage;7import com.consol.citrus.context.TestContext;8import com.consol.citrus.context.TestContextImpl;9import com.consol.citrus.validation.context.ValidationContext;10import com.consol.citrus.validation.context.ValidationContextFactory;11public class DomValidatorExample {12 public static void main(String[] args) {13 try {14 TestContext testContext = new TestContextImpl();15 ValidationContext validationContext = ValidationContextFactory.newInstance().create(MessageType.XML.name(), testContext);16 DomXmlMessageValidator domXmlMessageValidator = new DomXmlMessageValidator();17 Message message = new DefaultMessage("<testMessage><text>Hello World!</text></testMessage>");18 Message controlMessage = new DefaultMessage("<testMessage><text>Hello World!</text></testMessage>");19 domXmlMessageValidator.validateMessage(message, controlMessage, validationContext, testContext);20 System.out.println("Success");21 } catch (ValidationException ve) {22 System.out.println("Failure");23 }24 }25}26import com.consol.citrus.message.Message;27import com.consol.citrus.message.MessageType;28import com.consol.citrus.validation.dom.DomXmlMessage

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