users@jersey.java.net

[Jersey] Unit Testing a Resource method that has QueryParam

From: Sathyakumar <sathyakumar.s_at_gmail.com>
Date: Thu, 18 Sep 2014 11:09:11 +0530

Am having trouble unit testing a Resource which has QueryParam (and also a
path param) in it.
I am extending JerseyTest class in my unit test. The QueryParam in my
resource class's method is always null and the PathParam instead gets the
query string appended to it,

For e.g,
...
@Path("resource")
...
@GET
public void get(@PathParam("path") String path, @QueryParam("q") String
query)
..

When I test the above resource with say /resource?q=test, I always get
query value as null and path value as "resource?q=test". The same works if
I just build and deploy the war, but wont work when unit tested by
extending JerseyTest. (Am using version 2.12).