// This method overrides the getTestResult of the super class.
public TestResult getTestResult(HttpURLConnection connection)
throws Exception {
TestResult testResult = new TestResult();
//handle HTTP codes here
int code = connection.getResponseCode();
if (this.useCookie == true)
saveCookies(connection);
String message = connection.getResponseMessage();
//http response in 400s signifies Client Request Incomplete/Doc Not found
//http response in 500s signifies servlet error
if (code >= 400) {
testResult.setStatus(false);
testResult.setMessage(message);
}
else { //assume request was OK
// Get the "actual" result from the socket stream.
BufferedReader in = new
BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer result = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null ) {
// Tokenize the line
StringTokenizer tok = new StringTokenizer(line);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
result.append(" " + token);
}
}
// Get the expected result from the "golden" file.
StringBuffer expResult = getExpectedResult (getGoldenFileName());
// Compare the results and set the status
String diff = null;
boolean status = compare(result.toString(), expResult.toString(), diff);
testResult.setStatus(status);
// Set the message (Check with SCheck.
testResult.setMessage(diff);
// Now free the connection.
connection.disconnect();
} //end else