// 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);
}
catch (ParsingException e)
{
String url = this.configuration.getRedirectorURL(theRequest);
throw new ChainedRuntimeException("Failed to get the test "
+ "results at [" + url + "]", 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 or ComparisonFailure
// 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.
// Note: We have to test the exceptions by string name as the JUnit
// AssertionFailedError class is unfortunately not serializable...
if ((result.getExceptionClassName().equals(
"junit.framework.AssertionFailedError"))
|| (result.getExceptionClassName().equals(
"junit.framework.ComparisonFailure")))
{
throw new AssertionFailedErrorWrapper(
result.getExceptionMessage(),
result.getExceptionClassName(),
result.getExceptionStackTrace());
}
else
{
throw new ServletExceptionWrapper(
result.getExceptionMessage(),
result.getExceptionClassName(),
result.getExceptionStackTrace());
}
}
return connection;
}