f-lopes / spring-mvc-test-utils

Test library aimed to ease Spring MVC form validation tests. Easily post an entire form to a given url.
MIT License
19 stars 8 forks source link

Support for multipart requests #242

Closed SimonStefan closed 10 months ago

SimonStefan commented 10 months ago

Hi @f-lopes , it is very common to send files together with a form. It would be nice to add full support for multipart requests or at least set some methods to public so that the main functionality can be accessed.

Kind regards, Stefan

SimonStefan commented 10 months ago

After a fork I realized a method to allow multipart requests with the current version. I'd like to share it for others as a reference:

    MockHttpServletRequestBuilder multipart = MockMvcRequestBuilders.multipart("/path")
        .file(multipartFile)
        .with(MockMvcRequestBuilderUtils.form(form));
f-lopes commented 10 months ago

Hi @SimonStefan,

I am glad you found a solution, and thank you for sharing it!