// Load the page's modification date
String requestUrl = UrlUtils.concat(serverUrl, "system/weblounge/pages", modificationTestPageId);
HttpGet getPageRequest = new HttpGet(requestUrl);
HttpClient httpClient = new DefaultHttpClient();
Page page = null;
logger.info("Requesting the page's modification date at {}", requestUrl);
try {
HttpResponse response = TestUtils.request(httpClient, getPageRequest, null);
assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
PageReader reader = new PageReader();
page = reader.read(response.getEntity().getContent(), site);
} finally {
httpClient.getConnectionManager().shutdown();
}
DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
df.setTimeZone(TimeZone.getTimeZone("GMT"));
// Regularly load the page
requestUrl = UrlUtils.concat(serverUrl, modificationTestPage);
logger.info("Sending request to {}", requestUrl);
HttpGet request = new HttpGet(requestUrl);
request.addHeader("X-Cache-Debug", "yes");
String[][] params = new String[][] { {} };
// Send and the request and examine the response. Keep the modification
// date.
httpClient = new DefaultHttpClient();
try {
HttpResponse response = TestUtils.request(httpClient, request, params);
int statusCode = response.getStatusLine().getStatusCode();
boolean okOrNotModified = statusCode == HttpServletResponse.SC_OK || statusCode == HttpServletResponse.SC_NOT_MODIFIED;
assertTrue(okOrNotModified);
// Get the Modified header
assertNotNull(response.getHeaders("Last-Modified"));
assertEquals(1, response.getHeaders("Last-Modified").length);
Date hostModified = df.parse(response.getHeaders("Last-Modified")[0].getValue());
response.getEntity().consumeContent();
// Make sure the page is advertised as being more recent than the page's
// modification date
assertTrue(hostModified.after(page.getModificationDate()));
} finally {
httpClient.getConnectionManager().shutdown();
}
}