Junit Test for jersey (RESTful) @POST html form
I开发者_如何学运维 am trying to write a junit test case for the method below:
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("writeStuff")
@Consumes("multipart/form-data")
public Response stuffToWrite(FormDataMultiPart formData) {
....
}
How do I simulate the html form? I am thinking
MultiPart multipart = new FormDataMultiPart();
But I don't know how to populate it with fields and data.
Thanks.
See Multipart-Webapp sample from Jersey workspace: https://maven.java.net/content/repositories/releases/com/sun/jersey/samples/multipart-webapp/1.9.1/multipart-webapp-1.9.1-gf-project.zip
There is a test class which does what you need: MultipartWebAppTest.java
精彩评论