Class WritingXmlValidator


  • public class WritingXmlValidator
    extends Object
    Utility class that supports testing if two XML documents have the same content.
    Author:
    Matthias Müller
    • Field Detail

      • writeXml

        public static boolean writeXml
        Set to true to (over)write the control-files on (default false) (see also controlFileSource).
      • logXml

        public static boolean logXml
        Set to true to log the actual XML document (parsed from an JAXB object or a String) when validating (default false).
      • controlFileSource

        public static String controlFileSource
        The default relative path to write control-files to when writeXml is true (default: src/test/resources/).
    • Constructor Detail

      • WritingXmlValidator

        public WritingXmlValidator()
    • Method Detail

      • writeToDisk

        public static File writeToDisk​(Object data,
                                       String name)
                                throws IOException
        Writes the document represented by data to a File.
        Parameters:
        data - a JAXB object from package org.appng.xml.platform
        name - the path to the file (relative to controlFileSource )
        Returns:
        the generated File
        Throws:
        IOException - if an I/O error occurs while writing the file
      • writeToDiskPlain

        public static File writeToDiskPlain​(String data,
                                            String name)
                                     throws IOException
        Writes the document represented by data to a File.
        Parameters:
        data - a XML string
        name - the path to the file (relative to controlFileSource )
        Returns:
        the generated File
        Throws:
        IOException - if an I/O error occurs while writing the file
      • validateXml

        public static void validateXml​(BaseObject object,
                                       String controlFile)
                                throws IOException
        Validates that the document represented by object is equal to the document parsed from the controlFile.
        Parameters:
        object - a JAXB object from package org.appng.xml.platform
        controlFile - the path to the control file (relative to the classpath)
        Throws:
        IOException - if an I/O error occurs while validating
        AssertionError - if the validation fails
      • validateXml

        public static void validateXml​(BaseObject object,
                                       String controlFile,
                                       DifferenceListener differenceListener)
                                throws IOException
        Validates that the document represented by object is equal to the document parsed from the controlFile.
        Parameters:
        object - a JAXB object from package org.appng.xml.platform
        controlFile - the path to the control file (relative to the classpath)
        differenceListener - an optional DifferenceListener that is applied when building the Diff between the documents
        Throws:
        IOException - if an I/O error occurs while validating
        AssertionError - if the validation fails
      • validateXml

        public static void validateXml​(String result,
                                       String controlFile)
                                throws IOException
        Validates that the document represented by result is equal to the document parsed from the controlFile.
        Parameters:
        result - a XML string
        controlFile - the path to the control file (relative to the classpath)
        Throws:
        IOException - if an I/O error occurs while validating
        AssertionError - if the validation fails
      • validateXml

        public static void validateXml​(String result,
                                       String controlFile,
                                       DifferenceListener differenceListener)
                                throws IOException
        Validates that the document represented by result is equal to the document parsed from the controlFile.
        Parameters:
        result - a XML string
        controlFile - the path to the control file (relative to the classpath)
        differenceListener - an optional DifferenceListener that is applied when building the Diff between the documents
        Throws:
        IOException - if an I/O error occurs while validating
        AssertionError - if the validation fails
      • validateXml

        public static void validateXml​(String result,
                                       File controlFile,
                                       DifferenceListener differenceListener)
                                throws IOException
        Validates that the document represented by result is equal to the document parsed from the controlFile.
        Parameters:
        result - a XML string
        controlFile - the control file
        differenceListener - an optional DifferenceListener that is applied when building the Diff between the documents
        Throws:
        IOException - if an I/O error occurs while validating
        AssertionError - if the validation fails
      • validateXml

        public static void validateXml​(String result,
                                       String controlFile,
                                       boolean trimComment)
                                throws IOException
        Validates that the document represented by result is equal to the document parsed from the controlFile.
        Parameters:
        result - a XML string
        controlFile - the path to the control file (relative to the classpath)
        trimComment - set to true to un-comment previously commented elements
        Throws:
        IOException - if an I/O error occurs while validating
        AssertionError - if the validation fails
      • validateXml

        public static void validateXml​(String result,
                                       String controlFile,
                                       boolean trimComment,
                                       DifferenceListener differenceListener)
                                throws IOException
        Validates that the document represented by result is equal to the document parsed from the controlFile.
        Parameters:
        result - a XML string
        controlFile - the path to the control file (relative to the classpath)
        trimComment - set to true to un-comment previously commented elements
        differenceListener - an optional DifferenceListener that is applied when building the Diff between the documents
        Throws:
        IOException - if an I/O error occurs while validating
        AssertionError - if the validation fails
      • validateXml

        public static void validateXml​(String result,
                                       File controlFile,
                                       boolean trimComment,
                                       DifferenceListener differenceListener)
                                throws IOException
        Validates that the document represented by result is equal to the document parsed from the controlFile.
        Parameters:
        result - a XML string
        controlFile - the control file
        trimComment - set to true to un-comment previously commented elements
        differenceListener - an optional DifferenceListener that is applied when building the Diff between the documents
        Throws:
        IOException - if an I/O error occurs while validating
        AssertionError - if the validation fails