开发者

Junit Test for jersey (RESTful) @POST html form

开发者 https://www.devze.com 2023-04-05 09:27 出处:网络
I开发者_如何学运维 am trying to write a junit test case for the method below: @POST @Produces(MediaType.APPLICATION_JSON)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消