I want to pass my Date via parameter, and I dont exactly know how to do it. I have tried EncodeUrl.encode(), but it didnt work (it is possible that I did something wrong)
@Test
public void getUsageCountersParam2Test() throws Exception {
Date date = new Date(2017, 06, 23, 12, 39, 20);
MvcResult result = mockMvc.perform(get(getUri("/usages?apiConsumerId=[1,2]&serviceId=1&dateFrom=" + date)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
ObjectMapper mapper = new ObjectMapper();
List<UsageCounterDetailsDto> list = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference<List<UsageCounterDetailsDto>>() {
});
assertNotNull(list);
assertEquals(3, list.size());
}
I have an error such as:
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam java.util.Date] for value 'Mon Jul 23 12:39:20 CEST 3917'; nested exception is java.lang.IllegalArgumentException
Hope you could helped me.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…