users@jersey.java.net

[Jersey] Re: Jersey test framework with JNDI resources

From: Ryan Stewart <zzantozz_at_gmail.com>
Date: Tue, 18 Jan 2011 20:54:16 -0600

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.

On Tue, Jan 18, 2011 at 9:21 AM, Mike Key <mikey_at_zenbitz.com> wrote:

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