mercredi 20 février 2019

Spring MVC 4.2 : How to Unit Test Controller with @RequestPart Params

I have a requestMapping of the form:

@RequestMapping(
    value = "/submitCase",
    consumes =  MediaType.MULTIPART_FORM_DATA_VALUE,
    produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
    method = RequestMethod.POST
)
public Object submitCase(
    @RequestPart(name = "attachment[0]", required = false) MultipartFile attachment1,
    @RequestPart(name = "attachment[1]", required = false) MultipartFile attachment2,
    @RequestPart(name = "attachment[2]", required = false) MultipartFile attachment3,
    @RequestPart(name = "attachment[3]", required = false) MultipartFile attachment4,
    @RequestPart(name = "attachment[4]", required = false) MultipartFile attachment5,
    @RequestPart(name = "caseDetails") CaseDetails caseDetails) {}

Now I want to write a test for this with MockMvcBuilders. However I am unable to do so.

The challenge here is that the request handler consumes multipart/form-data, which consists of 4 Multipart Files, and 1 Json data.

Any ideas on how to solve this? Please bear in mind i am constrained to use Spring 4.3.

Please let me know if you require any more information.

Aucun commentaire:

Enregistrer un commentaire