users@jersey.java.net

[Jersey] Re: Jersey test framework with JNDI resources

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 19 Jan 2011 10:21:11 +0100

On Jan 19, 2011, at 5:53 AM, Mike Key wrote:

> Thanks Ryan, I did consider both of these ideas and they are good
> ones. I was trying to get an environment as close to a real
> deployment would be for these tests, which the use of grizzly should
> have initially flagged as already missing my own point. I have
> headed down this path now, but am still curious if it is/will ever
> be possible to do so with the Jersey Test Framework.
>

It's is not possible using Grizzly because it does not support the
JNDI semantics of a EE web container. Jetty might. In such cases using
war deployment (exploded or otherwise) might be the best option. The
test framework with external deployment where maven starts/stops Jetty
could work for you.

Paul.


> Thanks again for the ideas.
>
> Mike
>
>>
>> Ryan Stewart
>> January 18, 2011 7:54 PM
>>
>> I'm not sure about getting a real JNDI registry into the test
>> framework, but here's a couple of ideas to get around needing it:
>> 1) Move your JNDI lookup into a separate spring context file and
>> substitute a different file defining a bean with the same id for
>> tests. In other words, in src/main/resources you have your
>> "main.xml" which includes the JAX-RS resource beans and all
>> supporting beans plus a "jndi.xml" containing your <jee:jndi-lookup
>> id="connectionFactory" .../>. Then in src/main/tests, you have a
>> jndi-test.xml with <bean id="connectionFactory" .../> which just
>> defines some real or mock connection factory suitable for your
>> tests. So in your test class, use main.xml and jndi-test.xml and
>> leave out the JNDI lookup entirely.
>> 2) I'm not sure about the jee:jndi-lookup convenience call, but the
>> JndiObjectFactoryBean which backs it has a setDefaultObject method,
>> which sets the object to be returned if the JNDI lookup fails.
>> Perhaps you could use this somehow to inject something suitable for
>> your tests.
>>
>>
>>
>> Mike Key
>> January 18, 2011 8:21 AM
>>
>> Based on lack of response from such a good community I am assuming
>> nobody has done/tried this with Jersey Test Framework. Can anyone
>> tell me if it at least *should* be possible to use JNDI resources
>> when loading a webapp into the Jersey Test Framework? I am using a
>> simple configuration which leverages the Grizzly server. The test
>> bootstraps properly but then fails as it cannot find the JNDI
>> resource it is looking for (see below for Spring section it is
>> looking for).
>>
>> Thanks for any direction.
>>
>> Mike Key
>>
>>
>> Mike Key
>> January 16, 2011 4:48 PM
>>
>> I am trying to use the Jersey test framework with a web application
>> that includes some JMS resources normally looked up through JNDI.
>> For example I have the following in my spring config:
>>
>> <jee:jndi-lookup id="connectionFactory"
>> jndi-name="jms/connectionFactory"
>> resource-ref="true"/>
>>
>> I am struggling to figure out how to add a JNDI configuration to
>> the grizzly configuration. Can someone point me to or lead me in
>> the right direction on how to setup JNDI resources in a Jersey test
>> framework setup?
>>
>> Thanks in advance.
>>
>> Mike Key