// Open the first connection to the redirector to execute the test on
// the server side
HttpURLConnection connection = callRunTest(theRequest);
// Open the second connection to get the test results
WebTestResult result = callGetResult(theRequest.getAuthentication());
// Check if the returned result object returned contains an error or
// not. If yes, we need to raise an exception so that the JUnit
// framework can catch it
if (result.hasException()) {
// Wrap the exception message and stack trace into a fake
// exception class with overloaded <code>printStackTrace()</code>
// methods so that when JUnit calls this method it will print the
// stack trace that was set on the server side.
// If the error was an AssertionFailedError then we use an instance
// of AssertionFailedErrorWrapper (so that JUnit recognize it is
// an AssertionFailedError exception and print it differently in
// it's runner console). Otherwise we use an instance of
// ServletExceptionWrapper.
if (result.getExceptionClassName().
equals("junit.framework.AssertionFailedError")) {
throw new AssertionFailedErrorWrapper(
result.getExceptionMessage(),
result.getExceptionClassName(),
result.getExceptionStackTrace());
} else {
throw new ServletExceptionWrapper(
result.getExceptionMessage(),
result.getExceptionClassName(),
result.getExceptionStackTrace());
}
}