Pregunta

I would like to test the controller method below. Is there any way to add a Profile object the
mock request?

MockHttpServletRequest request = new MockHttpServletRequest();
//request.add(myProfile);

@RequestMapping(value = "/", method = RequestMethod.POST)
public View postUser(ModelMap data, @Valid Profile profile) {}
¿Fue útil?

Solución

Your profile object should be bound based on what is submitted as request parameters, so just set the relevant request parameters, say for eg, if you have a field in Profile as name, set that request. request.addParameter("name", "val")

A very good way of testing the Spring MVC stack is using Spring-test-mvc

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top