Mule 4 MUnit multipart/form-data Payload
The following article gives an example of posting multipart/form-data payload in MUnit.
Join the DZone community and get the full member experience.Join For Free
The following article gives an example of posting a multipart/form-data payload in MUnit.
- Mule version: 4.2.2
- MUnit version: 2.2.2
This article assumes that you have already built a RAML and have a POST method accepting multipart/form-data content and asserting it can be done as per your requirements.
The POST method in this article expects the following:
- JSON - JSON file as a part
- Multiple binary files as part
When the request is made to this POST method from Postman or ARC, the content type is selected as multipart/form-data, and files are selected using the select/choose file button. But to make the same request in MUnit where the mock request needs to be sent to the POST method, use the following example.
You might also want to read: File Attachment Handling in Mule 4 (Use of multipart/form-data)
Under src/test/resources in your application, create folder files/request.
Under files/request folder, copy the mock request files for multipart.
From the src/test/munit folder, open the test suite file and drop Set Event under Behavior from Palette -> MUnit.
Go to Set Event properties under the General tab and update the payload Media type to multipart/form-data and the value.
Note: Remember to include #[ ] to make it an expression since the button is not available here.
Here is the complete payload value with #[ ]
Thanks for reading!
Opinions expressed by DZone contributors are their own.