HttpSession session = request.getSession();
final FullTestResult testResult = (FullTestResult) session.getAttribute(TestConstants.ATTRIBUTE_TEST_RESULT);
DOMDocument report = new DOMDocument();
DOMElement testsuite = new DOMElement("testsuite");
report.setRootElement(testsuite);
if (testResult == null)
{
// No JUnit test results generated.
}
else
{
List passedTests = testResult.getPassedTests();
List failedTests = testResult.getFailedTests();
List errorTests = testResult.getErrorTests();
final int runCount = testResult.runCount() ;
final int errorCount = testResult.errorCount() ;
final int failureCount = testResult.failureCount() ;
testsuite.addAttribute("name", "com.jboss.transaction.txinterop.interop.InteropTestSuite");
testsuite.addAttribute("errors", Integer.toString(errorCount));
testsuite.addAttribute("failures", Integer.toString(failureCount));
testsuite.addAttribute("hostname", request.getServerName());
testsuite.addAttribute("tests", Integer.toString(runCount));
testsuite.addAttribute("timestamp", new Date().toString());
DOMElement properties = new DOMElement("properties");
testsuite.add(properties);
DOMElement status = newPropertyDOMElement("status");
properties.add(status);
status.addAttribute("value", "finished");
long totalDuration = 0;
if (! passedTests.isEmpty())
{
Iterator passedTestsIterator = passedTests.iterator();
while (passedTestsIterator.hasNext())
{
FullTestResult.PassedTest passedTest = (FullTestResult.PassedTest) passedTestsIterator.next();
totalDuration += passedTest.duration;
final String name = passedTest.test.toString();
final String description = (String)TestConstants.DESCRIPTIONS.get(name) ;
testsuite.add(newTestcase(
passedTest.test.getClass().getName(), name + ": " + description, passedTest.duration));
}
}
if (! failedTests.isEmpty())
{
Iterator failedTestsIterator = failedTests.iterator();
while (failedTestsIterator.hasNext())
{
FullTestResult.FailedTest failedTest = (FullTestResult.FailedTest) failedTestsIterator.next();
totalDuration += failedTest.duration;
final String name = failedTest.test.toString();
final String description = (String)TestConstants.DESCRIPTIONS.get(name) ;
CharArrayWriter charArrayWriter = new CharArrayWriter();
PrintWriter printWriter = new PrintWriter(charArrayWriter, true);
failedTest.assertionFailedError.printStackTrace(printWriter);
printWriter.close();
charArrayWriter.close();
testsuite.add(newFailedTestcase(
failedTest.test.getClass().getName(), name + ": " + description, failedTest.duration,
failedTest.assertionFailedError.getMessage(), charArrayWriter.toString()));
}
}
if (! errorTests.isEmpty())
{
Iterator errorTestsIterator = errorTests.iterator();
while (errorTestsIterator.hasNext())
{
FullTestResult.ErrorTest errorTest = (FullTestResult.ErrorTest) errorTestsIterator.next();
totalDuration += errorTest.duration;
final String name = errorTest.test.toString();
final String description = (String)TestConstants.DESCRIPTIONS.get(name) ;
CharArrayWriter charArrayWriter = new CharArrayWriter();
PrintWriter printWriter = new PrintWriter(charArrayWriter, true);
errorTest.throwable.printStackTrace(printWriter);
printWriter.close();
charArrayWriter.close();
System.out.println("charArrayWriter.toString()=" + charArrayWriter.toString());
testsuite.add(newErrorTestcase(
errorTest.test.getClass().getName(), name + ": " + description, errorTest.duration,
errorTest.throwable.getMessage(), charArrayWriter.toString()));
}
}
// total time of all tests
testsuite.addAttribute("time", Float.toString(totalDuration / 1000f));
}
String logContent = null;
final String logName = (String)session.getAttribute(TestConstants.ATTRIBUTE_LOG_NAME) ;
if (logName != null)
{
try
{
logContent = TestLogController.readLog(logName) ;
}
catch (final Throwable th)
{
log("Error reading log file", th) ;
}
}
testsuite.add(new DOMElement("system-out").addCDATA((logContent != null) ? logContent : ""));
testsuite.add(new DOMElement("system-err").addCDATA(""));
XMLWriter outputter = new XMLWriter(response.getWriter(), OutputFormat.createPrettyPrint());
try {
outputter.write(testsuite);
outputter.close();