public void doStatus(PrintWriter writer, HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
DOMDocument report = new DOMDocument();
DOMElement testsuite = new DOMElement("testsuite");
report.setRootElement(testsuite);
testsuite.addAttribute("name", _testSuiteClassName);
testsuite.addAttribute("errors", Integer.toString(_errorTests.size()));
testsuite.addAttribute("failures", Integer.toString(_failedTests.size()));
testsuite.addAttribute("hostname", request.getServerName());
testsuite.addAttribute("tests", Integer.toString((_testResult != null) ? _testResult.runCount() : 0));
testsuite.addAttribute("timestamp", new Date().toString());
DOMElement properties = new DOMElement("properties");
testsuite.add(properties);
DOMElement status = newPropertyDOMElement("status");
properties.add(status);
if ((_runnerThread == null) || (! _runnerThread.isAlive()))
{
if (_passedTests.isEmpty() && _failedTests.isEmpty() && _errorTests.isEmpty())
{
status.addAttribute("value", "stopped");
}
else
{
status.addAttribute("value", "finished");
}
}
else if (_currentTest != null)
{
status.addAttribute("value", "running");
properties.add(newPropertyDOMElement("current-test", _currentTest.toString()));
}
long totalDuration = 0;
if (! _passedTests.isEmpty())
{
Iterator passedTestsIterator = _passedTests.iterator();
while (passedTestsIterator.hasNext())
{
PassedTest passedTest = (PassedTest) passedTestsIterator.next();
totalDuration += passedTest.duration;
testsuite.add(newTestcase(
passedTest.test.getClass().getName(), passedTest.test.toString(), passedTest.duration));
}
}
if (! _failedTests.isEmpty())
{
Iterator failedTestsIterator = _failedTests.iterator();
while (failedTestsIterator.hasNext())
{
FailedTest failedTest = (FailedTest) failedTestsIterator.next();
totalDuration += failedTest.duration;
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(), failedTest.test.toString(), failedTest.duration,
failedTest.assertionFailedError.getMessage(), charArrayWriter.toString()));
}
}
if (! _errorTests.isEmpty())
{
Iterator errorTestsIterator = _errorTests.iterator();
while (errorTestsIterator.hasNext())
{
ErrorTest errorTest = (ErrorTest) errorTestsIterator.next();
totalDuration += errorTest.duration;
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(), errorTest.test.toString(), errorTest.duration,
errorTest.throwable.getMessage(), charArrayWriter.toString()));
}
}
testsuite.add(new DOMElement("system-out").addCDATA(""));
testsuite.add(new DOMElement("system-err").addCDATA(""));
// total time of all tests
testsuite.addAttribute("time", Float.toString(totalDuration / 1000f));
XMLWriter outputter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
try {