Class StatelessXmlReporter

  • All Implemented Interfaces:
    StatelessReportEventListener<WrappedReportEntry,​TestSetStats>
    Direct Known Subclasses:
    NullStatelessXmlReporter

    public class StatelessXmlReporter
    extends java.lang.Object
    implements StatelessReportEventListener<WrappedReportEntry,​TestSetStats>
    XML format reporter writing to TEST-reportName[-suffix].xml file like written and read by Ant's <junit> and <junitreport> tasks, then supported by many tools like CI servers.
    <?xml version="1.0" encoding="UTF-8"?>
     <testsuite name="suite name" [group="group"] tests="0" failures="0" errors="0" skipped="0" time="{float}">
      <properties>
        <property name="name" value="value"/>
        [...]
      </properties>
      <testcase time="{float}" name="test name [classname="class name"] [group="group"]"/>
      <testcase time="{float}" name="test name [classname="class name"] [group="group"]">
        <error message="message" type="exception class name">stacktrace</error>
        <system-out>system out content (present only if not empty)</system-out>
        <system-err>system err content (present only if not empty)</system-err>
      </testcase>
      <testcase time="{float}" name="test name [classname="class name"] [group="group"]">
        <failure message="message" type="exception class name">stacktrace</failure>
        <system-out>system out content (present only if not empty)</system-out>
        <system-err>system err content (present only if not empty)</system-err>
      </testcase>
      <testcase time="{float}" name="test name [classname="class name"] [group="group"]">
        <skipped/>
      </testcase>
      [...]
    See Also:
    Ant's format enhancement proposal (not yet implemented by Ant 1.8.2), Ant's XMLJUnitResultFormatter
    • Field Detail

      • reportsDirectory

        private final java.io.File reportsDirectory
      • reportNameSuffix

        private final java.lang.String reportNameSuffix
      • trimStackTrace

        private final boolean trimStackTrace
      • rerunFailingTestsCount

        private final int rerunFailingTestsCount
      • xsdSchemaLocation

        private final java.lang.String xsdSchemaLocation
      • xsdVersion

        private final java.lang.String xsdVersion
      • testClassMethodRunHistoryMap

        private final java.util.Map<java.lang.String,​java.util.Deque<WrappedReportEntry>> testClassMethodRunHistoryMap
      • phrasedFileName

        private final boolean phrasedFileName
      • phrasedSuiteName

        private final boolean phrasedSuiteName
      • phrasedClassName

        private final boolean phrasedClassName
      • phrasedMethodName

        private final boolean phrasedMethodName
    • Constructor Detail

      • StatelessXmlReporter

        public StatelessXmlReporter​(java.io.File reportsDirectory,
                                    java.lang.String reportNameSuffix,
                                    boolean trimStackTrace,
                                    int rerunFailingTestsCount,
                                    java.util.Map<java.lang.String,​java.util.Deque<WrappedReportEntry>> testClassMethodRunHistoryMap,
                                    java.lang.String xsdSchemaLocation,
                                    java.lang.String xsdVersion,
                                    boolean phrasedFileName,
                                    boolean phrasedSuiteName,
                                    boolean phrasedClassName,
                                    boolean phrasedMethodName)
    • Method Detail

      • serializeTestClass

        private void serializeTestClass​(java.io.OutputStream outputStream,
                                        java.io.OutputStreamWriter fw,
                                        org.apache.maven.shared.utils.xml.XMLWriter ppw,
                                        java.util.List<WrappedReportEntry> methodEntries)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeTestClassWithoutRerun

        private void serializeTestClassWithoutRerun​(java.io.OutputStream outputStream,
                                                    java.io.OutputStreamWriter fw,
                                                    org.apache.maven.shared.utils.xml.XMLWriter ppw,
                                                    java.util.List<WrappedReportEntry> methodEntries)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeTestClassWithRerun

        private void serializeTestClassWithRerun​(java.io.OutputStream outputStream,
                                                 java.io.OutputStreamWriter fw,
                                                 org.apache.maven.shared.utils.xml.XMLWriter ppw,
                                                 java.util.List<WrappedReportEntry> methodEntries)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • cleanTestHistoryMap

        public void cleanTestHistoryMap()
        Clean testClassMethodRunHistoryMap
      • getTestResultType

        private DefaultReporterFactory.TestResultType getTestResultType​(java.util.List<WrappedReportEntry> methodEntryList)
        Get the result of a test from a list of its runs in WrappedReportEntry
        Parameters:
        methodEntryList - the list of runs for a given test
        Returns:
        the TestResultType for the given test
      • getAddMethodRunHistoryMap

        private java.util.Deque<WrappedReportEntry> getAddMethodRunHistoryMap​(java.lang.String testClassName)
      • getOutputStream

        private java.io.OutputStream getOutputStream​(WrappedReportEntry testSetReportEntry)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • getWriter

        private static java.io.OutputStreamWriter getWriter​(java.io.OutputStream fos)
      • startTestElement

        private void startTestElement​(org.apache.maven.shared.utils.xml.XMLWriter ppw,
                                      WrappedReportEntry report)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • createTestSuiteElement

        private void createTestSuiteElement​(org.apache.maven.shared.utils.xml.XMLWriter ppw,
                                            WrappedReportEntry report,
                                            TestSetStats testSetStats)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • getTestProblems

        private static void getTestProblems​(java.io.OutputStreamWriter outputStreamWriter,
                                            org.apache.maven.shared.utils.xml.XMLWriter ppw,
                                            WrappedReportEntry report,
                                            boolean trimStackTrace,
                                            java.io.OutputStream fw,
                                            java.lang.String testErrorType,
                                            boolean createOutErrElementsInside)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • createOutErrElements

        private static void createOutErrElements​(java.io.OutputStreamWriter outputStreamWriter,
                                                 org.apache.maven.shared.utils.xml.XMLWriter ppw,
                                                 WrappedReportEntry report,
                                                 java.io.OutputStream fw)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • showProperties

        private static void showProperties​(org.apache.maven.shared.utils.xml.XMLWriter xmlWriter,
                                           java.util.Map<java.lang.String,​java.lang.String> systemProperties)
                                    throws java.io.IOException
        Adds system properties to the XML report.
        Parameters:
        xmlWriter - The test suite to report to
        Throws:
        java.io.IOException
      • extraEscapeAttribute

        private static java.lang.String extraEscapeAttribute​(java.lang.String message)
        Handle stuff that may pop up in java that is not legal in xml.
        Parameters:
        message - The string
        Returns:
        The escaped string or returns itself if all characters are legal
      • extraEscapeElementValue

        private static void extraEscapeElementValue​(java.lang.String message,
                                                    java.io.OutputStreamWriter outputStreamWriter,
                                                    org.apache.maven.shared.utils.xml.XMLWriter xmlWriter,
                                                    java.io.OutputStream fw)
                                             throws java.io.IOException
        Writes escaped string or the message within CDATA if all characters are legal.
        Parameters:
        message - The string
        Throws:
        java.io.IOException
      • addCommentElementTestCase

        private static void addCommentElementTestCase​(java.lang.String comment,
                                                      java.io.OutputStreamWriter outputStreamWriter,
                                                      org.apache.maven.shared.utils.xml.XMLWriter xmlWriter,
                                                      java.io.OutputStream fw)
                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • containsEscapesIllegalXml10

        private static boolean containsEscapesIllegalXml10​(java.lang.String message)
      • isIllegalEscape

        private static boolean isIllegalEscape​(char c)
      • isIllegalEscape

        private static boolean isIllegalEscape​(int c)
      • escapeXml

        private static java.lang.String escapeXml​(java.lang.String text,
                                                  boolean attribute)
        escape for XML 1.0
        Parameters:
        text - The string
        attribute - true if the escaped value is inside an attribute
        Returns:
        The escaped string