Skip to content

Commit 7f8a0cc

Browse files
committed
#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.
1 parent 8037e4d commit 7f8a0cc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

rest/headers/src/test/java/example/orders/WebIntegrationTests.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package example.orders;
1717

18+
import static org.hamcrest.CoreMatchers.*;
1819
import static org.springframework.http.HttpHeaders.*;
1920
import static org.springframework.restdocs.RestDocumentation.*;
2021
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
21-
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
2222
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
2323

2424
import java.net.URI;
@@ -66,19 +66,25 @@ public void executeConditionalGetRequests() throws Exception {
6666
URI uri = new UriTemplate("/customers/{id}").expand(customer.getId());
6767

6868
MockHttpServletResponse response = mvc.perform(get(uri)).//
69-
andDo(print()).//
69+
andExpect(header().string(ETAG, is(notNullValue()))).//
70+
andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).//
7071
andReturn().getResponse();
7172

7273
// ETag-based
7374

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))).//
7576
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();
7781

7882
// Last-modified-based
7983

8084
mvc.perform(get(uri).header(IF_MODIFIED_SINCE, response.getHeader(LAST_MODIFIED))).//
8185
andExpect(status().isNotModified()).//
86+
andExpect(header().string(ETAG, is(notNullValue()))).//
87+
andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).//
8288
andDo(document("if-modified-since"));
8389
}
8490
}

0 commit comments

Comments
 (0)