users@jersey.java.net

[Jersey] Re: Jersey test framework with JNDI resources

From: Mike Key <mikey_at_zenbitz.com>
Date: Tue, 18 Jan 2011 21:53:55 -0700

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.

Thanks again for the ideas.

Mike

> ------------------------------------------------------------------------
>
> Ryan Stewart <mailto:zzantozz_at_gmail.com>
> 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 <mailto:mikey_at_zenbitz.com>
> 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 <mailto: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