I have a SpringBoot application with the following Restful method
Controller:
@GetMapping(path = "/getVersion/{version}", produces = "application/json;charset=utf-8")
public ResponseEntity getSpecific(@PathVariable("version") String version) throws Exception{
// return ResponseEntity();
}
And here is the corresponding junit method.
@Test
public void testGetSpecific() throws Exception{
// Version - timestamp in Zulu format
String path = "/getVersion/" + DateTimeFormatter.ISO_INSTANT.format(Instant.now());
MvcResult result = mockMvc.perform(get(url + path).secure(false).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();
}
Problem: The value of version sent during testing is not same at the controller end.
Eg: If we send 2019-05-21T20:18:08.157Z in test method, we would receive 2019-05-21T20:18:08 at controller. And thus, we would miss the part .157Z.
I tried the solutions described in the following links, but no luck.
spring 4.1.1, mockmvc and do not want url encoding of HTTP GET request
RestTemplate to NOT escape url
Could anyone point to whats happening behind the scenes and how to resolve it? Thanks.