Spring 3.2 mvc testing post request

From the spring tutorial.

MvcResult mvcResult = 
mockMvc.perform(post("/person")).andExpect(status().isOk()).andReturn();

      

This is good and good, but if my controller has a signature

@RequestMapping(value = "/person", method = RequestMethod.POST)
public String postPerson(Person person) {}

      

If the person is a simple DTO, usually filled with a spring form in jsp (for example, for two fields String and getter / setters); how to send this data to the test?

+3


source to share


1 answer


Let's say the class Person

has attributes name

and age

.

When creating a request, you can do this:



post("/person")
  .param("name", "John")
  .param("age", "45")

      

+4


source







All Articles