How to use parseXPathValidationElements method of com.consol.citrus.config.xml.ReceiveMessageActionParser class

Best Citrus code snippet using com.consol.citrus.config.xml.ReceiveMessageActionParser.parseXPathValidationElements

Source:ReceiveMessageActionParser.java Github

copy

Full Screen

...238 */239 private XpathMessageValidationContext getXPathMessageValidationContext(Element messageElement, XmlMessageValidationContext parentContext) {240 XpathMessageValidationContext context = new XpathMessageValidationContext();241 242 parseXPathValidationElements(messageElement, context);243 context.setControlNamespaces(parentContext.getControlNamespaces());244 context.setNamespaces(parentContext.getNamespaces());245 context.setIgnoreExpressions(parentContext.getIgnoreExpressions());246 context.setSchema(parentContext.getSchema());247 context.setSchemaRepository(parentContext.getSchemaRepository());248 context.setSchemaValidation(parentContext.isSchemaValidationEnabled());249 context.setDTDResource(parentContext.getDTDResource());250 return context;251 }252 /**253 * Construct the JSONPath message validation context.254 * @param messageElement255 * @return256 */257 private JsonPathMessageValidationContext getJsonPathMessageValidationContext(Element messageElement) {258 JsonPathMessageValidationContext context = new JsonPathMessageValidationContext();259 //check for validate elements, these elements can either have script, jsonPath or namespace validation information260 //for now we only handle jsonPath validation261 Map<String, Object> validateJsonPathExpressions = new HashMap<>();262 List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");263 if (validateElements.size() > 0) {264 for (Iterator<?> iter = validateElements.iterator(); iter.hasNext();) {265 Element validateElement = (Element) iter.next();266 extractJsonPathValidateExpressions(validateElement, validateJsonPathExpressions);267 }268 context.setJsonPathExpressions(validateJsonPathExpressions);269 }270 return context;271 }272 /**273 * Construct the message validation context.274 * @param messageElement275 * @return276 */277 private ScriptValidationContext getScriptValidationContext(Element messageElement, String messageType) {278 ScriptValidationContext context = null;279 boolean done = false;280 List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");281 if (validateElements.size() > 0) {282 for (Iterator<?> iter = validateElements.iterator(); iter.hasNext();) {283 Element validateElement = (Element) iter.next();284 Element scriptElement = DomUtils.getChildElementByTagName(validateElement, "script");285 // check for nested validate script child node286 if (scriptElement != null) {287 if (!done) {288 done = true;289 } else {290 throw new BeanCreationException("Found multiple validation script definitions - " +291 "only supporting a single validation script for message validation");292 }293 context = new ScriptValidationContext(messageType);294 String type = scriptElement.getAttribute("type");295 context.setScriptType(type);296 String filePath = scriptElement.getAttribute("file");297 if (StringUtils.hasText(filePath)) {298 context.setValidationScriptResourcePath(filePath);299 if (scriptElement.hasAttribute("charset")) {300 context.setValidationScriptResourceCharset(scriptElement.getAttribute("charset"));301 }302 } else {303 context.setValidationScript(DomUtils.getTextValue(scriptElement));304 }305 }306 }307 }308 return context;309 }310 311 /**312 * Parses validation elements and adds information to the message validation context.313 * 314 * @param messageElement the message DOM element.315 * @param context the message validation context.316 */317 private void parseNamespaceValidationElements(Element messageElement, XmlMessageValidationContext context) {318 //check for validate elements, these elements can either have script, xpath or namespace validation information319 //for now we only handle namespace validation320 Map<String, String> validateNamespaces = new HashMap<String, String>();321 List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");322 if (validateElements.size() > 0) {323 for (Iterator<?> iter = validateElements.iterator(); iter.hasNext();) {324 Element validateElement = (Element) iter.next();325 //check for namespace validation elements326 List<?> validateNamespaceElements = DomUtils.getChildElementsByTagName(validateElement, "namespace");327 if (validateNamespaceElements.size() > 0) {328 for (Iterator<?> namespaceIterator = validateNamespaceElements.iterator(); namespaceIterator.hasNext();) {329 Element namespaceElement = (Element) namespaceIterator.next();330 validateNamespaces.put(namespaceElement.getAttribute("prefix"), namespaceElement.getAttribute("value"));331 }332 }333 }334 context.setControlNamespaces(validateNamespaces);335 }336 }337 /**338 * Parses validation elements and adds information to the message validation context.339 *340 * @param messageElement the message DOM element.341 * @param context the message validation context.342 */343 private void parseXPathValidationElements(Element messageElement, XpathMessageValidationContext context) {344 //check for validate elements, these elements can either have script, xpath or namespace validation information345 //for now we only handle xpath validation346 Map<String, Object> validateXpathExpressions = new HashMap<>();347 List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");348 if (validateElements.size() > 0) {349 for (Iterator<?> iter = validateElements.iterator(); iter.hasNext();) {350 Element validateElement = (Element) iter.next();351 extractXPathValidateExpressions(validateElement, validateXpathExpressions);352 }353 context.setXpathExpressions(validateXpathExpressions);354 }355 }356 /**357 * Extracts xpath validation expressions and fills map with them...

Full Screen

Full Screen

parseXPathValidationElements

Using AI Code Generation

copy

Full Screen

1public class ReceiveMessageActionParserTest {2 public void shouldParseValidationElements() throws Exception {3 final ReceiveMessageActionParser parser = new ReceiveMessageActionParser();4 final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(getClass().getResourceAsStream("/test.xml"));5 final Node node = document.getFirstChild();6 final List<ValidationContext> validationContexts = parser.parseXPathValidationElements(node);7 assertThat(validationContexts, hasSize(2));8 assertThat(validationContexts.get(0), instanceOf(XPathMessageValidationContext.class));9 assertThat(validationContexts.get(0).getPath(), is("/ns:TestMessage/ns:header/ns:headerField"));10 assertThat(validationContexts.get(0).getValidationExpression(), instanceOf(StaticMessageHeaderExpression.class));11 assertThat(validationContexts.get(0).getValidationExpression().getValue(null), is("headerValue"));12 assertThat(validationContexts.get(1), instanceOf(XPathMessageValidationContext.class));13 assertThat(validationContexts.get(1).getPath(), is("/ns:TestMessage/ns:body/ns:bodyField"));14 assertThat(validationContexts.get(1).getValidationExpression(), instanceOf(StaticMessageHeaderExpression.class));15 assertThat(validationContexts.get(1).getValidationExpression().getValue(null), is("bodyValue"));16 }17}

Full Screen

Full Screen

parseXPathValidationElements

Using AI Code Generation

copy

Full Screen

1public class ReceiveMessageActionParserTest {2 public void testParseXPathValidationElements() {3 ReceiveMessageActionParser parser = new ReceiveMessageActionParser();4 parser.setApplicationContext(new ClassPathXmlApplicationContext("com/consol/citrus/citrus-context.xml"));5 parser.setValidationContext(new ValidationContext());6 parser.setMessageConverter(new DefaultMessageConverter());7 parser.setMessageSelectorParser(new MessageSelectorParser());8 parser.setEndpointUriResolver(new StaticEndpointUriResolver());9 parser.setBeanDefinitionParserHelper(new BeanDefinitionParserHelper());10 BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ReceiveMessageActionFactoryBean.class);11 builder.addPropertyValue("endpoint", new RuntimeEndpointConfiguration());12 Element element = new DomElement("receive");13 element.addAttribute("message-type", "text");14 element.addAttribute("endpoint", "testEndpoint");15 Element xpathValidationElement = new DomElement("xpath-validation");16 xpathValidationElement.addAttribute("control-value", "true");17 element.add(xpathValidationElement);18 parser.parseValidationElements(element, builder);19 ReceiveMessageActionFactoryBean factoryBean = (ReceiveMessageActionFactoryBean) builder.getBeanDefinition().getFactoryBean();20 List<ValidationMatcher<? super Object>> validationMatchers = factoryBean.getValidationMatchers();21 Assert.assertEquals(validationMatchers.size(), 1);22 Assert.assertTrue(validationMatchers.get(0) instanceof XPathMessageValidationMatcher);23 Assert.assertEquals(((XPathMessageValidationMatcher) validationMatchers.get(0)).getControlValue(), "true");24 }25}26public void testParseXPathValidationElements() {27 ReceiveMessageActionParser parser = new ReceiveMessageActionParser();28 parser.setApplicationContext(new ClassPathXmlApplicationContext("com/consol/citrus/citrus-context.xml"));29 parser.setValidationContext(new ValidationContext());30 parser.setMessageConverter(new DefaultMessageConverter());31 parser.setMessageSelectorParser(new MessageSelectorParser());32 parser.setEndpointUriResolver(new StaticEndpointUriResolver());33 parser.setBeanDefinitionParserHelper(new BeanDefinitionParserHelper());34 BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Receive

Full Screen

Full Screen

parseXPathValidationElements

Using AI Code Generation

copy

Full Screen

1public class ReceiveMessageActionParserTest {2 public void testParseXPathValidationElements() throws Exception {3 Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File("src/test/resources/citrus-receive-message-action-parser-test.xml"));4 NodeList nodeList = document.getElementsByTagName("citrus:receive");5 Node node = nodeList.item(0);6 ReceiveMessageActionParser parser = new ReceiveMessageActionParser();7 ReceiveMessageAction action = new ReceiveMessageAction();8 parser.parseMessageSelector(node, action, new ParserContext(new XmlReaderContext(new ClassPathResource("citrus-receive-message-action-parser-test.xml"), new DefaultProblemReporter())));9 Assert.assertEquals(action.getMessageSelector().size(), 1L);10 Assert.assertEquals(action.getMessageSelector().get("foo"), "bar");11 }12}

Full Screen

Full Screen

parseXPathValidationElements

Using AI Code Generation

copy

Full Screen

1public void testReceiveMessageActionParser() throws Exception {2 List<String> xPathExpressions = new ArrayList<>();3 List<String> namespaces = new ArrayList<>();4 List<String> validationExpressions = new ArrayList<>();5 validationExpressions.add("citrus:randomNumber(10)");6 validationExpressions.add("citrus:randomNumber(10)");7 List<String> validationValues = new ArrayList<>();8 validationValues.add("1234567890");9 validationValues.add("0987654321");10 List<String> validationTypes = new ArrayList<>();11 validationTypes.add("number");12 validationTypes.add("number");13 List<String> xPathExpressions2 = new ArrayList<>();14 List<String> namespaces2 = new ArrayList<>();15 List<String> validationExpressions2 = new ArrayList<>();16 validationExpressions2.add("citrus:randomNumber(10)");17 validationExpressions2.add("citrus:randomNumber(10)");18 List<String> validationValues2 = new ArrayList<>();19 validationValues2.add("1234567890");20 validationValues2.add("0987654321");21 List<String> validationTypes2 = new ArrayList<>();22 validationTypes2.add("number");23 validationTypes2.add("number");24 ReceiveMessageActionParser parser = new ReceiveMessageActionParser();25 Element element = createReceiveMessageActionElement(xPathExpressions, namespaces, validationExpressions, validationValues, validationTypes);26 Element element2 = createReceiveMessageActionElement(xPathExpressions2, namespaces2, validationExpressions2, validationValues2, validationTypes2);27 List<ValidationContext> validationContexts = parser.parseXPathValidationElements(element);28 List<ValidationContext> validationContexts2 = parser.parseXPathValidationElements(element2);29 assertEquals(3,

Full Screen

Full Screen

parseXPathValidationElements

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.actions.ReceiveMessageAction2import com.consol.citrus.config.xml.ReceiveMessageActionParser3import com.consol.citrus.message.MessageType4import com.consol.citrus.validation.xml.XmlMessageValidationContext5import com.consol.citrus.validation.xml.XmlMessageValidationContext.ValidationType6import com.consol.citrus.validation.xml.XmlMessageValidationProcessor7import com.consol.citrus.xml.namespace.NamespaceContextBuilder8import org.springframework.beans.factory.annotation.Autowired9import org.springframework.beans.factory.annotation.Qualifier10import org.springframework.context.ApplicationContext11import org.springframework.context.annotation.Bean12import org.springframework.context.annotation.Configuration13import org.springframework.core.io.Resource14import org.springframework.util.StringUtils15import org.springframework.xml.transform.StringSource16import org.w3c.dom.Element17import org.xml.sax.InputSource18import javax.xml.transform.Source19import javax.xml.transform.stream.StreamSource20import javax.xml.validation.Schema21class CitrusConfig {22 fun receiveMessageActionParser() = ReceiveMessageActionParser()23 fun receiveMessageAction() = ReceiveMessageAction().apply {24 endpoint = applicationContext.getBean("soapClient", SoapClient::class.java)25 message = applicationContext.getBean("soapRequest", SoapRequest::class.java)26 validationContext = applicationContext.getBean("validationContext", XmlMessageValidationContext::class.java)27 validationProcessor = applicationContext.getBean("validationProcessor", XmlMessageValidationProcessor::class.java)28 parseXPathValidationElements(this, applicationContext.getBean("validationContext", XmlMessageValidationContext::class.java))29 }30 fun validationContext() = XmlMessageValidationContext().apply {31 schema = applicationContext.getBean("schema", Schema::class.java)32 namespaceContextBuilder = applicationContext.getBean("namespaceContextBuilder", NamespaceContextBuilder::class.java)33 }34 fun validationProcessor() = XmlMessageValidationProcessor()

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