Description
To bind data submitted through HTML forms, a form-backing object is used as parameter of MVC controller methods.
@Controller
class MyController {
@PostMapping
String submit(@Valid @ModelAttribute MyForm form, Errors errors) {
}
}
class MyForm {
// properties go here
}
In a MockMVC integration test, to issue a request submitting that form, currently one would have to use the ….param(…)
methods to populate the request body as plain String
s, also making sure that e.g. the same formatting ruled are used as are for binding and form value rendering. Also, one has to replicate property names as String
s for the keys handed into the ….param(…)
method, which is not refactoring-friendly.
I would appreciate it, if instead, one could just call post(…).form(myFormBackingInstance)
so that one could just populate the object and get the values added as requests parameters in matching format and also get the content type configured accordingly.
Activity