use of io.vertigo.util.DateBuilder in project vertigo by KleeGroup.
the class WebServiceManagerTest method testDownloadNotModifiedFile.
@Test
public void testDownloadNotModifiedFile() throws ParseException {
final DateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
// Sans préciser le if-Modified-Since, le serveur retourne le fichier
final Response response = loggedAndExpect(given().queryParam("id", 10)).header("Content-Type", Matchers.equalToIgnoringCase("image/png")).header("Content-Disposition", Matchers.equalToIgnoringCase("attachment;filename=\"image10.png\";filename*=UTF-8''image10.png")).header("Content-Length", Matchers.equalTo("27039")).statusCode(HttpStatus.SC_OK).when().get("/test/downloadNotModifiedFile");
final String lastModified = response.getHeader("Last-Modified");
final Date lastModifiedDate = httpDateFormat.parse(lastModified);
final String now = httpDateFormat.format(new Date());
// On test avec le if-Modified-Since now : le server test mais ne retourne pas le fichier
loggedAndExpect(given().queryParam("id", 10).header("if-Modified-Since", now)).statusCode(HttpStatus.SC_NOT_MODIFIED).when().get("/test/downloadNotModifiedFile");
// On test avec le if-Modified-Since 10 min avant le lastModified : le server test et retourne le fichier
final String beforeLastModified = httpDateFormat.format(new DateBuilder(lastModifiedDate).addMinutes(-10).build());
loggedAndExpect(given().queryParam("id", 10).header("if-Modified-Since", beforeLastModified)).header("Content-Type", Matchers.equalToIgnoringCase("image/png")).header("Content-Disposition", Matchers.equalToIgnoringCase("attachment;filename=\"image10.png\";filename*=UTF-8''image10.png")).header("Content-Length", Matchers.equalTo("27039")).statusCode(HttpStatus.SC_OK).when().get("/test/downloadNotModifiedFile");
}
Aggregations