users@jersey.java.net

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

From: Sathyakumar <sathyakumar.s_at_gmail.com>
Date: Fri, 19 Sep 2014 16:01:11 +0530

Jersey team, Is this a bug that needs to be open ?

On Fri, Sep 19, 2014 at 10:29 AM, Sathyakumar <sathyakumar.s_at_gmail.com>
wrote:

> I tested it like target("resource/somepath").
> queryParam("q","test").request().get();
> And it didn't work, I got the path variable value (inside the get method)
> as test?q=test and query variable value as null.
> The same however works when I deploy this as a war file
>
> On Thu, Sep 18, 2014 at 11:24 AM, Suneel Marthi <suneel_marthi_at_yahoo.com>
> wrote:
>
>> 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).
>>
>>
>>
>>
>>
>