Skip to content

Allow setting up a MockMVC form submission using an instance of the form-backing object #29728

Open
@odrotbohm

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 Strings, 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 Strings 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)status: pending-design-workNeeds design work before any code can be developedtype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions