*/
public void testGZIPResponse() throws Exception {
HTTPRequestOperationProcess process =
(HTTPRequestOperationProcess) createTestableProcess();
SAXHandler handler = new SAXHandler();
XMLProcess consumer = XMLHelpers.createSAXHandlerProcess(handler);
process.setNextProcess(consumer);
final String input =
"<html>" +
"<head>" +
"<title>The title<title>" +
"</head>" +
"<h2>A Heading<h2>" +
"<p>A paragraph<br>Link " +
"<a href=nothing1.html>Nothing 1 " +
"<a href=nested>nested anchor</a>" +
"<p>an anchored p" +
"</a>" +
"</html>";
// Create a compressed gzip response stream.
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(input.getBytes());
gzip.flush();
gzip.close();
InputStream responseStream = new ByteArrayInputStream(out.toByteArray());
process.processResponse(null, responseStream, 200, "text/html", "gzip");
assertEquals("Next process should match",
consumer, process.getNextProcess().getNextProcess());
XMLOutputter outputter = new XMLOutputter();
outputter.setTrimAllWhite(true);
outputter.setNewlines(false);
outputter.setLineSeparator("");
final String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<html>" +
"<head>" +
"<meta name=\"generator\" content=\"HTML Tidy, see www.w3.org\" />" +
"<title>The title</title>" +
"<title />" +
"</head>" +
"<body>" +
"<h2>A Heading</h2>" +
"<p>A paragraph<br />\nLink " +
"<a href=\"nothing1.html\">Nothing 1 nested anchor</a>" +
"</p>" +
"<p>an anchored p</p>" +
"</body>" +
"</html>";
String actual = outputter.outputString(handler.getDocument());
assertEquals("Response read should match original input\n",
expected, actual);
}