org.apache.tuscany.sca.host.webapp.junit
Class XMLFormatter

java.lang.Object
  extended by org.apache.tuscany.sca.host.webapp.junit.XMLFormatter

public class XMLFormatter
extends java.lang.Object

Format the test results in XML.


Field Summary
static java.lang.String ATTR_ERRORS
          Errors attribute for TestSuite elements
static java.lang.String ATTR_FAILURES
          Failures attribute for TestSuite elements
static java.lang.String ATTR_MESSAGE
          Message attribute for failure elements (message of the exception)
static java.lang.String ATTR_NAME
          Name attribute for property, TestCase and TestSuite elements
static java.lang.String ATTR_TESTS
          Tests attribute for TestSuite elements (number of tests executed)
static java.lang.String ATTR_TIME
          Time attribute for TestCase and TestSuite elements
static java.lang.String ATTR_TYPE
          Type attribute for failure and error elements
static java.lang.String ERROR
          The error element (for a test case)
static java.lang.String FAILURE
          The failure element (for a test case)
static java.lang.String TESTCASE
          A single TestCase element
static java.lang.String TESTSUITE
          A single test suite results.
 
Constructor Summary
XMLFormatter()
           
 
Method Summary
static java.lang.String escape(java.lang.String theString)
          Escapes reserved XML characters.
static java.lang.String exceptionToString(java.lang.Throwable theThrowable)
          Returns the stack trace of an exception as String.
static java.lang.String exceptionToString(java.lang.Throwable theThrowable, java.lang.String[] theFilterPatterns)
          Returns the stack trace of an exception as String, optionally filtering out line from the stack trace
static boolean filterLine(java.lang.String theLine, java.lang.String[] theFilterPatterns)
           
static java.lang.String getDurationAsString(long theDuration)
          Convert a duration expressed as a long into a string.
static java.lang.String toXML(Failure failure)
           
static java.lang.String toXML(Result result, java.lang.Class<?> cls)
          Formats the test result as an XML string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTR_ERRORS

public static final java.lang.String ATTR_ERRORS
Errors attribute for TestSuite elements

See Also:
Constant Field Values

ATTR_FAILURES

public static final java.lang.String ATTR_FAILURES
Failures attribute for TestSuite elements

See Also:
Constant Field Values

ATTR_MESSAGE

public static final java.lang.String ATTR_MESSAGE
Message attribute for failure elements (message of the exception)

See Also:
Constant Field Values

ATTR_NAME

public static final java.lang.String ATTR_NAME
Name attribute for property, TestCase and TestSuite elements

See Also:
Constant Field Values

ATTR_TESTS

public static final java.lang.String ATTR_TESTS
Tests attribute for TestSuite elements (number of tests executed)

See Also:
Constant Field Values

ATTR_TIME

public static final java.lang.String ATTR_TIME
Time attribute for TestCase and TestSuite elements

See Also:
Constant Field Values

ATTR_TYPE

public static final java.lang.String ATTR_TYPE
Type attribute for failure and error elements

See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
The error element (for a test case)

See Also:
Constant Field Values

FAILURE

public static final java.lang.String FAILURE
The failure element (for a test case)

See Also:
Constant Field Values

TESTCASE

public static final java.lang.String TESTCASE
A single TestCase element

See Also:
Constant Field Values

TESTSUITE

public static final java.lang.String TESTSUITE
A single test suite results.

See Also:
Constant Field Values
Constructor Detail

XMLFormatter

public XMLFormatter()
Method Detail

escape

public static java.lang.String escape(java.lang.String theString)
Escapes reserved XML characters.

Parameters:
theString - the string to escape
Returns:
the escaped string

exceptionToString

public static java.lang.String exceptionToString(java.lang.Throwable theThrowable)
Returns the stack trace of an exception as String.

Parameters:
theThrowable - the exception from which to extract the stack trace as a String
Returns:
the exception stack trace as a String

exceptionToString

public static java.lang.String exceptionToString(java.lang.Throwable theThrowable,
                                                 java.lang.String[] theFilterPatterns)
Returns the stack trace of an exception as String, optionally filtering out line from the stack trace

Parameters:
theThrowable - the exception from which to extract the stack trace as a String
theFilterPatterns - Array containing a list of patterns to filter out from the stack trace
Returns:
the exception stack trace as a String

filterLine

public static boolean filterLine(java.lang.String theLine,
                                 java.lang.String[] theFilterPatterns)
Parameters:
theLine - The line to check
theFilterPatterns - The patterns to filter out
Returns:
boolean Whether the specified line should be filtered from the stack trace

getDurationAsString

public static java.lang.String getDurationAsString(long theDuration)
Convert a duration expressed as a long into a string.

Parameters:
theDuration - the duration to convert to string
Returns:
the total duration as a string

toXML

public static java.lang.String toXML(Failure failure)

toXML

public static java.lang.String toXML(Result result,
                                     java.lang.Class<?> cls)
Formats the test result as an XML string.

Parameters:
result - the test result object
Returns:
the XML string representation of the test results