【发布时间】:2015-06-23 07:12:14
【问题描述】:
我有启用 http 缓存的 springboot 应用程序。我正在使用webRequest.checkModifiedSince,如here 中所述。在浏览器中运行我的应用程序时,我得到正确的结果,200 第一次点击状态码和304 下一次点击。但是当我对我的应用程序运行 maven 测试时,webRequest.checkModifiedSince 似乎总是返回 false。
这是我的测试用例:
@Test
public void checkCache() throws Exception {
MvcResult res = this.mockMvc.perform(get("/resource/to/cache.jpg"))
.andExpect(status().isOk())
.andReturn();
String date = res.getResponse().getHeader("Last-Modified");
HttpHeaders headers = new HttpHeaders();
headers.setIfModifiedSince(Long.parseLong(date));
headers.setCacheControl("max-age=0");
this.mockMvc.perform(get("same/resource/as/above.jpg")
.headers(headers))
.andExpect(status().isNotModified());
}
我在这里做错了吗?
【问题讨论】:
标签: spring testing http-caching