提交 49dd707b 编写于 作者: A Arjen Poutsma

Test for SPR-5822 - Extend @CookieValue mapping to support user-defined types

上级 c1a1becd
......@@ -974,14 +974,25 @@ public class ServletAnnotationControllerTests {
}
@Test
public void bindingCookieValue() throws ServletException, IOException {
initServlet(BindingCookieValueController.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test");
request.setCookies(new Cookie("date", "2008-11-18"));
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("test-1226962800000", response.getContentAsString());
}
@Test
public void ambiguousParams() throws ServletException, IOException {
initServlet(AmbiguousParamsController.class);
MockHttpServletRequest request;// = new MockHttpServletRequest("GET", "/test");
MockHttpServletResponse response;// = new MockHttpServletResponse();
// servlet.service(request, response);
// assertEquals("noParams", response.getContentAsString());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("noParams", response.getContentAsString());
request = new MockHttpServletRequest("GET", "/test");
request.addParameter("myParam", "42");
......@@ -1679,5 +1690,27 @@ public class ServletAnnotationControllerTests {
}
@Controller
@RequestMapping("/test*")
public static class BindingCookieValueController {
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.initBeanPropertyAccess();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
@RequestMapping(method = RequestMethod.GET)
public void handle(@CookieValue("date") Date date, Writer writer)
throws IOException {
assertEquals("Invalid path variable value", new Date(108, 10, 18), date);
writer.write("test-" + date.getTime());
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册