tribal
tribal

Reputation: 51

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.

Upvotes: 3

Views: 3255

Answers (1)

Pavel Bucek
Pavel Bucek

Reputation: 5324

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

Upvotes: 4

Related Questions