assertEquals("Content was received", "<p>hello</p>\n",
toString(content.getInputStream()));
assertEquals(200, content.getStatusCode());
Iterator cookiesIter = content.getCookies();
assertTrue(cookiesIter.hasNext());
final Cookie fooCookie = (Cookie) cookiesIter.next();
assertFalse(cookiesIter.hasNext());
assertEquals("foo", fooCookie.getName());
assertEquals("bar", fooCookie.getValue());
// second request should contain an If-None-Match validation header
// response will indicate that content is not modified
currentDate = RFC1123.format(new Date());
serverMock.addTransaction(new String[]{
"GET /blah.txt?foo HTTP/1.1",
"If-None-Match: \"aa\"",
UA_STRING,
"Host: " + serverMock.getServerAddress()},
new String[]{
"HTTP/1.0 304 Not Modified",
"Date: " + currentDate,
"Set-Cookie: hello=world",
""});
content = (HttpContent) manager.getURLContent(url, null, null);
assertEquals("Content was not modified, cached entry is returned",
"<p>hello</p>\n", toString(content.getInputStream()));
assertEquals(200, content.getStatusCode());
cookiesIter = content.getCookies();
assertTrue(cookiesIter.hasNext());
Cookie helloCookie = (Cookie) cookiesIter.next();
assertFalse(cookiesIter.hasNext());
assertEquals("hello", helloCookie.getName());
assertEquals("world", helloCookie.getValue());
// third request should contain an If-None-Match validation header
// response will indicate that content is not modified
currentDate = RFC1123.format(new Date());
serverMock.addTransaction(new String[]{
"GET /blah.txt?foo HTTP/1.1",
"If-None-Match: \"aa\"",
UA_STRING,
"Host: " + serverMock.getServerAddress()},
new String[]{
"HTTP/1.0 304 Not Modified",
"Date: " + currentDate,
""});
content = (HttpContent) manager.getURLContent(url, null, null);
assertEquals("Content was not modified, cached entry is returned",
"<p>hello</p>\n", toString(content.getInputStream()));
assertEquals(200, content.getStatusCode());
cookiesIter = content.getCookies();
assertTrue(cookiesIter.hasNext());
helloCookie = (Cookie) cookiesIter.next();
assertFalse(cookiesIter.hasNext());
assertEquals("hello", helloCookie.getName());
assertEquals("world", helloCookie.getValue());
assertFalse(serverMock.hasTransactions());
}