I have a controller method with a PUT method that gets multipart / form-data:
@RequestMapping(value = "/putIn", method = RequestMethod.PUT) public Foo updateFoo(HttpServletRequest request, @RequestBody Foo foo, @RequestParam("foo_icon") MultipartFile file) { ... }
and I want to test it using MockMvc . Unfortunately, MockMvcRequestBuilders.fileUpload creates an instance of MockMultipartHttpServletRequestBuilder that has a POST method:
super(HttpMethod.POST, urlTemplate, urlVariables)
EDIT: I ca nβt create my own implementation of MockHttpServletRequestBuilder , say
public MockPutMultipartHttpServletRequestBuilder(String urlTemplate, Object... urlVariables) { super(HttpMethod.PUT, urlTemplate, urlVariables); super.contentType(MediaType.MULTIPART_FORM_DATA); }
because MockHttpServletRequestBuilder has a package-local constructor.
But I wonder if this is more convenient . Is it possible to do this, maybe I missed some existing class or method for this?
source share