// 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 = null;
try {
result = callGetResult(theRequest.getAuthentication());
} catch (ParsingException e) {
throw new ChainedRuntimeException("Failed to get the test "
+ "results. This is probably due to an error that happened on "
+ "the server side when trying to execute the tests. Here is "
+ "what was returned by the server : ["
+ new WebResponse(theRequest, connection).getText() + "]", e);
}
// 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());
}
}