From the spring tutorial ..
MvcResult mvcResult =
mockMvc.perform(post("/person")).andExpect(status().isOk()).andReturn();
Which is fine and good, but if my controller has the signature
@RequestMapping(value = "/person", method = RequestMethod.POST)
public String postPerson(Person person) {}
Where person is a simple DTO normally populated via a spring form in the jsp(with for example two String fields and getter/setters); how to submit that data in the test ?
Let's say that class Person
has attributes name
and age
.
When building your request, you can do this :
post("/person")
.param("name", "John")
.param("age", "45")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.