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

Best Citrus code snippet using com.consol.citrus.validation.xml.DomXmlMessageValidator.validateXmlTree

Source:DomXmlMessageValidator.java Github

copy

Full Screen

...309 if (log.isDebugEnabled()) {310 log.debug("Received message:\n" + XMLUtils.serialize(received));311 log.debug("Control message:\n" + XMLUtils.serialize(source));312 }313 validateXmlTree(received, source, validationContext, namespaceContextBuilder.buildContext(314 receivedMessage, validationContext.getNamespaces()), context);315 }316 317 /**318 * Validates XML header fragment data.319 * @param receivedHeaderData320 * @param controlHeaderData321 * @param validationContext322 * @param context323 */324 private void validateXmlHeaderFragment(String receivedHeaderData, String controlHeaderData,325 XmlMessageValidationContext validationContext, TestContext context) {326 log.debug("Start XML header data validation ...");327 Document received = XMLUtils.parseMessagePayload(receivedHeaderData);328 Document source = XMLUtils.parseMessagePayload(controlHeaderData);329 XMLUtils.stripWhitespaceNodes(received);330 XMLUtils.stripWhitespaceNodes(source);331 if (log.isDebugEnabled()) {332 log.debug("Received header data:\n" + XMLUtils.serialize(received));333 log.debug("Control header data:\n" + XMLUtils.serialize(source));334 }335 validateXmlTree(received, source, validationContext, 336 namespaceContextBuilder.buildContext(new DefaultMessage(receivedHeaderData), validationContext.getNamespaces()),337 context);338 }339 /**340 * Walk the XML tree and validate all nodes.341 *342 * @param received343 * @param source344 * @param validationContext345 */346 private void validateXmlTree(Node received, Node source, 347 XmlMessageValidationContext validationContext, NamespaceContext namespaceContext, TestContext context) {348 switch(received.getNodeType()) {349 case Node.DOCUMENT_TYPE_NODE:350 doDocumentTypeDefinition(received, source, validationContext, namespaceContext, context);351 break;352 case Node.DOCUMENT_NODE:353 validateXmlTree(received.getFirstChild(), source.getFirstChild(),354 validationContext, namespaceContext, context);355 break;356 case Node.ELEMENT_NODE:357 doElement(received, source, validationContext, namespaceContext, context);358 break;359 case Node.ATTRIBUTE_NODE:360 throw new IllegalStateException();361 case Node.COMMENT_NODE:362 validateXmlTree(received.getNextSibling(), source,363 validationContext, namespaceContext, context);364 break;365 case Node.PROCESSING_INSTRUCTION_NODE:366 doPI(received);367 break;368 }369 }370 /**371 * Handle document type definition with validation of publicId and systemId.372 * @param received373 * @param source374 * @param validationContext375 * @param namespaceContext376 */377 private void doDocumentTypeDefinition(Node received, Node source,378 XmlMessageValidationContext validationContext,379 NamespaceContext namespaceContext, TestContext context) {380 Assert.isTrue(source instanceof DocumentType, "Missing document type definition in expected xml fragment");381 DocumentType receivedDTD = (DocumentType) received;382 DocumentType sourceDTD = (DocumentType) source;383 if (log.isDebugEnabled()) {384 log.debug("Validating document type definition: " +385 receivedDTD.getPublicId() + " (" + receivedDTD.getSystemId() + ")");386 }387 if (!StringUtils.hasText(sourceDTD.getPublicId())) {388 Assert.isNull(receivedDTD.getPublicId(),389 ValidationUtils.buildValueMismatchErrorMessage("Document type public id not equal",390 sourceDTD.getPublicId(), receivedDTD.getPublicId()));391 } else if (sourceDTD.getPublicId().trim().equals(Citrus.IGNORE_PLACEHOLDER)) {392 if (log.isDebugEnabled()) {393 log.debug("Document type public id: '" + receivedDTD.getPublicId() +394 "' is ignored by placeholder '" + Citrus.IGNORE_PLACEHOLDER + "'");395 }396 } else {397 Assert.isTrue(StringUtils.hasText(receivedDTD.getPublicId()) &&398 receivedDTD.getPublicId().equals(sourceDTD.getPublicId()),399 ValidationUtils.buildValueMismatchErrorMessage("Document type public id not equal",400 sourceDTD.getPublicId(), receivedDTD.getPublicId()));401 }402 if (!StringUtils.hasText(sourceDTD.getSystemId())) {403 Assert.isNull(receivedDTD.getSystemId(),404 ValidationUtils.buildValueMismatchErrorMessage("Document type system id not equal",405 sourceDTD.getSystemId(), receivedDTD.getSystemId()));406 } else if (sourceDTD.getSystemId().trim().equals(Citrus.IGNORE_PLACEHOLDER)) {407 if (log.isDebugEnabled()) {408 log.debug("Document type system id: '" + receivedDTD.getSystemId() +409 "' is ignored by placeholder '" + Citrus.IGNORE_PLACEHOLDER + "'");410 }411 } else {412 Assert.isTrue(StringUtils.hasText(receivedDTD.getSystemId()) &&413 receivedDTD.getSystemId().equals(sourceDTD.getSystemId()),414 ValidationUtils.buildValueMismatchErrorMessage("Document type system id not equal",415 sourceDTD.getSystemId(), receivedDTD.getSystemId()));416 }417 validateXmlTree(received.getNextSibling(),418 source.getNextSibling(), validationContext, namespaceContext, context);419 }420 /**421 * Handle element node.422 *423 * @param received424 * @param source425 * @param validationContext426 */427 private void doElement(Node received, Node source,428 XmlMessageValidationContext validationContext, NamespaceContext namespaceContext, TestContext context) {429 doElementNameValidation(received, source);430 doElementNamespaceValidation(received, source);431 //check if element is ignored either by xpath or by ignore placeholder in source message432 if (XmlValidationUtils.isElementIgnored(source, received, validationContext.getIgnoreExpressions(), namespaceContext)) {433 return;434 }435 //work on attributes436 if (log.isDebugEnabled()) {437 log.debug("Validating attributes for element: " + received.getLocalName());438 }439 NamedNodeMap receivedAttr = received.getAttributes();440 NamedNodeMap sourceAttr = source.getAttributes();441 Assert.isTrue(countAttributes(receivedAttr) == countAttributes(sourceAttr),442 ValidationUtils.buildValueMismatchErrorMessage("Number of attributes not equal for element '"443 + received.getLocalName() + "'", countAttributes(sourceAttr), countAttributes(receivedAttr)));444 for (int i = 0; i < receivedAttr.getLength(); i++) {445 doAttribute(received, receivedAttr.item(i), source, validationContext, namespaceContext, context);446 }447 //check if validation matcher on element is specified448 if (isValidationMatcherExpression(source)) {449 ValidationMatcherUtils.resolveValidationMatcher(source.getNodeName(),450 received.getFirstChild().getNodeValue().trim(),451 source.getFirstChild().getNodeValue().trim(),452 context);453 return;454 }455 doText((Element) received, (Element) source);456 //work on child nodes457 List<Element> receivedChildElements = DomUtils.getChildElements((Element) received);458 List<Element> sourceChildElements = DomUtils.getChildElements((Element) source);459 Assert.isTrue(receivedChildElements.size() == sourceChildElements.size(),460 ValidationUtils.buildValueMismatchErrorMessage("Number of child elements not equal for element '"461 + received.getLocalName() + "'", sourceChildElements.size(), receivedChildElements.size()));462 for (int i = 0; i < receivedChildElements.size(); i++) {463 this.validateXmlTree(receivedChildElements.get(i), sourceChildElements.get(i),464 validationContext, namespaceContext, context);465 }466 if (log.isDebugEnabled()) {467 log.debug("Validation successful for element: " + received.getLocalName() +468 " (" + received.getNamespaceURI() + ")");469 }470 }471 /**472 * Handle text node during validation.473 *474 * @param received475 * @param source476 */477 private void doText(Element received, Element source) {...

Full Screen

Full Screen

validateXmlTree

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;3import com.consol.citrus.exceptions.CitrusRuntimeException;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.testng.CitrusParameters;6import com.consol.citrus.validation.xml.DomXmlMessageValidator;7import com.consol.citrus.validation.xml.XmlMessageValidationContext;8import org.testng.annotations.DataProvider;9import org.testng.annotations.Test;10import org.w3c.dom.Document;11import org.w3c.dom.Element;12import javax.xml.parsers.DocumentBuilder;13import javax.xml.parsers.DocumentBuilderFactory;14import javax.xml.parsers.ParserConfigurationException;15import java.io.ByteArrayInputStream;16import java.io.IOException;17import java.io.InputStream;18import java.util.Arrays;19public class ValidateXmlTreeTest extends TestNGCitrusTestRunner {20 @DataProvider(name = "validateXmlTreeDataProvider")21 public Object[][] validateXmlTreeDataProvider() {22 return new Object[][]{23 {true, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true},24 {true, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, false},25 {true, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true},26 {true, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true},27 {true, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true, true, false, true, false, false, true},28 {true, true, false, true, true, false, false, true, true, false, true, false, false

Full Screen

Full Screen

validateXmlTree

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;2import org.testng.annotations.Test;3public class DomXmlMessageValidatorTest extends TestNGCitrusTestDesigner {4 public void validateXmlTree() {5 variable("xmlTree", "<foo><bar>bar</bar></foo>");6 .ignoreWhitespace()7 .ignoreComments()8 .ignoreNamespaces()9 .ignoreXPath("/foo/bar")10 .ignoreXPath("/foo/baz")11 .ignoreXPath("/foo/baz/text()")12 .ignoreXPath("/foo/baz/@*")13 .ignoreXPath("/foo/baz/*")14 .ignoreXPath("/foo/baz/*[1]")15 .ignoreXPath("/foo/baz/*[last()]")16 .ignoreXPath("/foo/baz/*[position()=1]")17 .ignoreXPath("/foo/baz/*[position()=last()]")18 .ignoreXPath("/foo/baz/*[position()=1 and position()=last()]")19 .ignoreXPath("/foo/baz/*[position()=1 or position()=last()]")20 .ignoreXPath("/foo/baz/*[position()=2]")21 .ignoreXPath("/foo/baz/*[position()=last()-1]")22 .ignoreXPath("/foo/baz/*[position()=last()-1 and position()=last()-1]")23 .ignoreXPath("/foo/baz/*[position()=last()-1 or position()=last()-1]")24 .ignoreXPath("/foo/baz/*[position()=last()-1 or position()=last()]")25 .ignoreXPath("/foo/baz/*[position()=last()-1 or position()=last()-2]")26 .ignoreXPath("/foo/baz/*[position()=last()-1 or position()=last()-2 or position()=last()]")27 .ignoreXPath("/foo/baz/*[position()=last()-1 or position()=last()-2 or position()=last()-3]")28 .ignoreXPath("/foo/baz/*[position()=last()-1 or position()=last()-2 or position()=last()-3 or position()=last()-4]")29 .ignoreXPath("/foo/baz/*[position()=last()-1 or position

Full Screen

Full Screen

validateXmlTree

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.design.TestDesigner2import com.consol.citrus.dsl.design.TestDesignerSupport3import com.consol.citrus.dsl.runner.TestRunner4import com.consol.citrus.dsl.runner.TestRunnerSupport5import java.util.HashMap6import com.consol.citrus.dsl.design.TestDesigner7import com.consol.citrus.dsl.design.TestDesignerSupport8import com.consol.citrus.dsl.runner.TestRunner9import com.consol.citrus.dsl.runner.TestRunnerSupport10import java.util.HashMap11import com.consol.citrus.dsl.design.TestDesigner12import com.consol.citrus.dsl.design.TestDesignerSupport13import com.consol.citrus.dsl.runner.TestRunner14import com.consol.citrus.dsl.runner.TestRunnerSupport15import java.util.HashMap16import com.consol.citrus.dsl.design.TestDesigner17import com.consol.citrus.dsl.design.TestDesignerSupport18import com.consol.citrus.dsl.runner.TestRunner19import com.consol.citrus.dsl.runner.TestRunnerSupport20import java.util.HashMap21import com.consol.citrus.dsl.design.TestDesigner22import com.consol.citrus.dsl.design.TestDesignerSupport23import com.consol.citrus.dsl.runner.TestRunner24import com.consol.citrus.dsl.runner.TestRunnerSupport25import java.util.HashMap26import com.consol.citrus.dsl.design.TestDesigner27import com.consol.citrus.dsl.design.TestDesignerSupport28import com.consol.citrus.dsl.runner.TestRunner29import com.consol.citrus.dsl.runner.TestRunnerSupport30import java.util.HashMap31import com.consol.citrus.dsl.design.TestDesigner32import com.consol.citrus.dsl.design.TestDesignerSupport33import com.consol.citrus.dsl.runner.TestRunner34import com.consol.citrus.dsl.runner.TestRunnerSupport35import java.util.HashMap36import com.consol.citrus.dsl.design.TestDesigner37import com.consol.citrus.dsl.design.TestDesignerSupport38import com.consol.citrus.dsl.runner.TestRunner39import com.consol.citrus.dsl.runner.TestRunnerSupport40import java.util.HashMap41import com.consol.citrus.dsl.design.TestDesigner42import com.consol.citrus

Full Screen

Full Screen

validateXmlTree

Using AI Code Generation

copy

Full Screen

1def validateXmlTree(xmlMessage, xmlRefMessage) {2 def xmlValidator = new DomXmlMessageValidator()3 def xmlValidationContext = new XmlMessageValidationContext.Builder()4 .build()5 xmlValidator.validateMessage(xmlMessage, xmlRefMessage, xmlValidationContext)6}

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