users@jersey.java.net

[Jersey] Re: Unit Test Resources individually?

From: Mark Engel <mark.c.engel_at_gmail.com>
Date: Thu, 7 Apr 2011 16:53:20 +0200

Thank you for your quick reply.
Boilerplate here we come :)

How do I start ResTestResource within a JerseyTest without configuring
its whole package?
(So I could define the Wrapper Class inside the Test)

Mark

On Thu, Apr 7, 2011 at 4:39 PM, Pavel Bucek <pavel.bucek_at_oracle.com> wrote:
> Hello,
>
> it is not possible, jersey test framework always needs to start jersey and
> if you define just this class as only resource, it won't start because there
> is no root resource present.
>
> What you can do is create something like ResTestResource, which could look
> like:
>
> @Path("/")
> public class ResTestResource extends Res {
>    public ResTestResource() {
>        super("injected value");
>    }
> }
>
> and run your test(s) against it..
>
>
> Pavel
>
> On 04/07/2011 04:29 PM, Mark Engel wrote:
>>
>> How is it possible to unit test just one resource at a time?
>>
>> For example I have this resource
>>
>> class Res {
>>   private final String injected;
>>   public Res(String injected) { this.injected = injected; }
>>   @GET public String get() { return injected; }
>> }
>>
>> and want to unit test this resource with a custom stub (configured via
>> setUp()) against real http calls from Client.
>> I would expect that if I only test one resource it would be in the
>> root of the server.
>>
>> Is this possible with Jersey? I only found options to configure a
>> whole package of resource.
>>
>
>