Issue
I'm testing my MVC service with spring-test-mvc
I used something like:
MockMvc mockMvc = standaloneSetup(controller).build();
mockMvc.perform(get("<my-url>")).andExpect(content().bytes(expectedBytes)).andExpect(content().type("image/png"))
.andExpect(header().string("cache-control", "max-age=3600"));
Which worked fine.
Now I changed the cache image to be random in a specific range. For example, instead of 3600
it could be 3500-3700
. I'm trying to figure out how I can get the header value and do some tests on it instead of using this pattern of andExpect
.
Solution
Perhaps you mean something like this.
MvcResult mvcResult = mvc.perform(get("/")).andReturn();
String headerValue = mvcResult.getResponse().getHeader("headerName");
Answered By - Admit