users@jersey.java.net

[Jersey] Re: InMemoryTestContainer and injecting dependencies

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Tue, 8 Feb 2011 12:57:37 +0100

On Feb 8, 2011, at 12:20 PM, Pavel Bucek wrote:

> Hello Jim,
>
> depends on what you are injecting - some objects are not available
> when using in-memory container, for example servlet related ones
> (ServletContext, HttpServletRequest, ServletConfig, ..) but you
> should be able to inject all jersey objects (UriInfo, HttpHeaders,
> HttpContext, ..).
>

Also, your milage may vary w.r.t. the performance gain. Depends if
Jetty is restarted for every test. The test framework will initiate
Jersey for each test. You can change this behavior by writing your own
TestContainerFactory e.g. copy the code for
InMemoryTestContainerFactory.

Jersey startup time can almost certainly be improved, and we don't
currently have an easy way to mock tests in a restricted environment.

Paul.


> Pavel
>
> On 02/07/2011 10:31 PM, Jim Webber wrote:
>> Hi folks,
>>
>> Up until now I've just been bringing up my Jersey app atop Jetty
>> for functional testing, but those tests are taking a while to run
>> now (minutes). I'd like to transition to the InMemoryTestContainer
>> instead, on the assumption that'll be much faster.
>>
>> I do have some dependencies injected into my resource classes (via
>> @Context), how would I go about setting those up if I use the
>> InMemoryTestContainer?
>>
>> Thanks for your ideas,
>>
>> Jim
>>
>>
>>
>