users@jersey.java.net

Re: [Jersey] Unit testing resources

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 24 Jun 2008 11:34:45 +0200

On Jun 23, 2008, at 11:32 AM, Martin Probst wrote:

> You mean that the field "info" is null? Jersey should be setting
> that field for you.
>
> Are you using your own ComponentProvider for testing?
>
> The problem is that I don't have any idea how to obtain a properly
> injected instance of my FooResource class in the first place. I'd
> rather not re-implement my own ComponentProvider and injection, is
> there a way to obtain one from Jersey?
>

Unfortunately the only way to properly test the resource class is to
deploy it in a container and make an HTTP request to it, sorry :-(

Some people have experimented with proxies of resource classes that
hide the HTTP invocation but there are certain restrictions in that
approach as the method signatures of the resource class don't always
correspond to well to direct invocation. In general i am not sure
this is a good idea to try and hide the network and make it look like
a local call, which is one of the issues with RPC-based Web services.

Paul.