Search in sources :

Example 1 with DateBuilder

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");
}
Also used : Response(io.restassured.response.Response) DateBuilder(io.vertigo.util.DateBuilder) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Response (io.restassured.response.Response)1 DateBuilder (io.vertigo.util.DateBuilder)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Test (org.junit.Test)1