users@jersey.java.net

[Jersey] Re: Unit Testing a Resource method that has QueryParam

From: Suneel Marthi <suneel_marthi_at_yahoo.com>
Date: Wed, 17 Sep 2014 22:54:45 -0700

Isn't this working in ur JerseyTest?

target("resource").queryParam("q","test").request().get();




On Thursday, September 18, 2014 1:50 AM, Sathyakumar <sathyakumar.s_at_gmail.com> wrote:
 


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).