|
15 | 15 | */
|
16 | 16 | package example.orders;
|
17 | 17 |
|
| 18 | +import static org.hamcrest.CoreMatchers.*; |
18 | 19 | import static org.springframework.http.HttpHeaders.*;
|
19 | 20 | import static org.springframework.restdocs.RestDocumentation.*;
|
20 | 21 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
21 |
| -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; |
22 | 22 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
23 | 23 |
|
24 | 24 | import java.net.URI;
|
@@ -66,19 +66,25 @@ public void executeConditionalGetRequests() throws Exception {
|
66 | 66 | URI uri = new UriTemplate("/customers/{id}").expand(customer.getId());
|
67 | 67 |
|
68 | 68 | MockHttpServletResponse response = mvc.perform(get(uri)).//
|
69 |
| - andDo(print()).// |
| 69 | + andExpect(header().string(ETAG, is(notNullValue()))).// |
| 70 | + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// |
70 | 71 | andReturn().getResponse();
|
71 | 72 |
|
72 | 73 | // ETag-based
|
73 | 74 |
|
74 |
| - mvc.perform(get(uri).header(IF_NONE_MATCH, response.getHeader(ETAG))).// |
| 75 | + response = mvc.perform(get(uri).header(IF_NONE_MATCH, response.getHeader(ETAG))).// |
75 | 76 | andExpect(status().isNotModified()).//
|
76 |
| - andDo(document("if-none-match")); |
| 77 | + andExpect(header().string(ETAG, is(notNullValue()))).// |
| 78 | + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// |
| 79 | + andDo(document("if-none-match")).// |
| 80 | + andReturn().getResponse(); |
77 | 81 |
|
78 | 82 | // Last-modified-based
|
79 | 83 |
|
80 | 84 | mvc.perform(get(uri).header(IF_MODIFIED_SINCE, response.getHeader(LAST_MODIFIED))).//
|
81 | 85 | andExpect(status().isNotModified()).//
|
| 86 | + andExpect(header().string(ETAG, is(notNullValue()))).// |
| 87 | + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// |
82 | 88 | andDo(document("if-modified-since"));
|
83 | 89 | }
|
84 | 90 | }
|
0 commit comments