users@jersey.java.net

[Jersey] Re: Unit Test Resources individually?

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Thu, 07 Apr 2011 16:39:17 +0200

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