Class XMLTestReportProcessor

  • All Implemented Interfaces:
    XMLConstants, TestReportProcessor, XMLReflectConstants, XTRConstants
    Direct Known Subclasses:
    SVGAccuracyTestProcessor

    public class XMLTestReportProcessor
    extends java.lang.Object
    implements TestReportProcessor, XTRConstants, XMLConstants
    This implementation of the TestReportProcessor interface converts the TestReports it processes into an XML document that it outputs in a directory. The directory used by the object can be configured at creation time.
    The XMLTestReportProcessor can optionally notify a report consumer of the XML file it created.
    Version:
    $Id: XMLTestReportProcessor.java 1851346 2019-01-15 13:41:00Z ssteiner $
    • Field Detail

      • ERROR_REPORT_DIRECTORY_UNUSABLE

        public static final java.lang.String ERROR_REPORT_DIRECTORY_UNUSABLE
        Error message if report directory does not exist.
        See Also:
        Constant Field Values
      • ERROR_REPORT_RESOURCES_DIRECTORY_UNUSABLE

        public static final java.lang.String ERROR_REPORT_RESOURCES_DIRECTORY_UNUSABLE
        Error message if report resources directory does not exist.
        See Also:
        Constant Field Values
      • XML_TEST_REPORT_DEFAULT_DIRECTORY

        public static final java.lang.String XML_TEST_REPORT_DEFAULT_DIRECTORY
        Default report directory
      • XML_REPORT_DIRECTORY

        public static final java.lang.String XML_REPORT_DIRECTORY
        Directory where the XML report is created
      • XML_RESOURCES_DIRECTORY

        public static final java.lang.String XML_RESOURCES_DIRECTORY
        Directory where resources (e.g., images) referenced by the XML report are copied.
      • XML_TEST_REPORT_NAME

        public static final java.lang.String XML_TEST_REPORT_NAME
        Test report name
      • reportDate

        protected java.lang.String reportDate
        String encoding the date the report was generated.
      • reportDirectory

        protected java.io.File reportDirectory
        Directory into which this processor puts all files and resources.
      • xmlDirectory

        protected java.io.File xmlDirectory
        Directory into which XML files are created
      • xmlResourcesDirectory

        protected java.io.File xmlResourcesDirectory
        Directory into whichr resources refered to by XML files are created
      • EOL

        private static java.lang.String EOL
      • PROPERTY_LINE_SEPARATOR

        private static java.lang.String PROPERTY_LINE_SEPARATOR
      • PROPERTY_LINE_SEPARATOR_DEFAULT

        private static java.lang.String PROPERTY_LINE_SEPARATOR_DEFAULT
    • Constructor Detail

      • XMLTestReportProcessor

        public XMLTestReportProcessor()
        Default constructor
      • XMLTestReportProcessor

        public XMLTestReportProcessor​(XMLTestReportProcessor.XMLReportConsumer consumer)
        Parameters:
        consumer - consumer for the XML report generated by this object. May be null.
    • Method Detail

      • checkDirectory

        public void checkDirectory​(java.io.File dir,
                                   java.lang.String errorCode)
                            throws TestException
        Checks that the input File represents a directory that can be used. If the directory does not exist, this method will attempt to create it.
        Throws:
        TestException
      • initializeReportDirectories

        public void initializeReportDirectories()
                                         throws TestException
        By default, the report directory is given by a configuration variable. Each test run will create a sub directory with the current date and time as the same. All the resources created by the report processor are then put into that "dated" directory.
        Throws:
        TestException
      • makeTwoDigits

        protected java.lang.String makeTwoDigits​(int i)
        Forces a two digit string
      • getReportDirectory

        public java.io.File getReportDirectory()
        Returns the report directory
      • getReportResourcesDirectory

        public java.io.File getReportResourcesDirectory()
        By default, the report resources directory is given by a configuration variable.
      • processReport

        protected void processReport​(TestReport report,
                                     org.w3c.dom.Element reportElement,
                                     org.w3c.dom.Document reportDocument)
                              throws java.io.IOException
        Recursively processes the input TestReport adding the report information to the input element.
        Throws:
        java.io.IOException
      • processEntry

        protected void processEntry​(TestReport.Entry entry,
                                    org.w3c.dom.Element descriptionElement,
                                    org.w3c.dom.Document reportDocument)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • createResourceFileForName

        protected java.io.File createResourceFileForName​(java.lang.String fileName)
        Untility method. Creates a file in the resources directory for the given name. If a file in that directory does not exist yet, then it is used. Otherwise, a file with the same name with a digit suffix is created. For example, if "myFile.png" is requested, then "myFile.png" is created or "myFile<n>.png" where <n> will be one or several digits.
      • createResourceFileForName

        protected java.io.File createResourceFileForName​(java.lang.String fileName,
                                                         int instance)
      • copy

        protected void copy​(java.io.File in,
                            java.io.File out)
                     throws java.io.IOException
        Utility method. Copies in to out
        Throws:
        java.io.IOException
      • serializeReport

        protected java.io.File serializeReport​(org.w3c.dom.Element reportElement)
                                        throws java.io.IOException
        Saves the XML document into a file
        Throws:
        java.io.IOException
      • serializeElement

        protected void serializeElement​(org.w3c.dom.Element element,
                                        java.lang.String prefix,
                                        java.io.Writer writer)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeAttributes

        protected void serializeAttributes​(org.w3c.dom.Element element,
                                           java.io.Writer writer)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • encode

        protected java.lang.String encode​(java.lang.String attrValue)
        Poor way of replacing '<', '>', '"', '&' and ''' in attribute values.
      • replace

        protected void replace​(java.lang.StringBuffer s,
                               char c,
                               java.lang.String r)