From 7f8a0cc9dc973cdf12a6d476719af51801502640 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 26 Jun 2015 06:45:57 +0200 Subject: [PATCH] #111 - Stricter tests cases for conditional headers in REST sample. We now explicitly check for the presence of ETag and Last-Modified headers for all requests. --- .../java/example/orders/WebIntegrationTests.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rest/headers/src/test/java/example/orders/WebIntegrationTests.java b/rest/headers/src/test/java/example/orders/WebIntegrationTests.java index ae2ee74f..e78c131e 100644 --- a/rest/headers/src/test/java/example/orders/WebIntegrationTests.java +++ b/rest/headers/src/test/java/example/orders/WebIntegrationTests.java @@ -15,10 +15,10 @@ */ package example.orders; +import static org.hamcrest.CoreMatchers.*; import static org.springframework.http.HttpHeaders.*; import static org.springframework.restdocs.RestDocumentation.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import java.net.URI; @@ -66,19 +66,25 @@ public class WebIntegrationTests { URI uri = new UriTemplate("/customers/{id}").expand(customer.getId()); MockHttpServletResponse response = mvc.perform(get(uri)).// - andDo(print()).// + andExpect(header().string(ETAG, is(notNullValue()))).// + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// andReturn().getResponse(); // ETag-based - mvc.perform(get(uri).header(IF_NONE_MATCH, response.getHeader(ETAG))).// + response = mvc.perform(get(uri).header(IF_NONE_MATCH, response.getHeader(ETAG))).// andExpect(status().isNotModified()).// - andDo(document("if-none-match")); + andExpect(header().string(ETAG, is(notNullValue()))).// + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// + andDo(document("if-none-match")).// + andReturn().getResponse(); // Last-modified-based mvc.perform(get(uri).header(IF_MODIFIED_SINCE, response.getHeader(LAST_MODIFIED))).// andExpect(status().isNotModified()).// + andExpect(header().string(ETAG, is(notNullValue()))).// + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// andDo(document("if-modified-since")); } }