> -----Original Message-----
> From: KARR, DAVID
> Sent: Friday, September 02, 2011 3:34 PM
> To: [email protected]
> Subject: Problems with initializing context in integration test of CXF
> app
> 
> I'm having trouble with an integration test (I hate calling them "unit
> tests" if they really aren't) of my CXF app.  My problem is probably
> only with Spring, but perhaps people here have run into this.
> 
> I define some JNDI references in my Spring context to datasources.
> This will work fine when I deploy the WAR to my appserver, where I'll
> define the datasources, but in my integration test I have to manually
> create those datasources.

If anyone's paying attention, I've managed to get this working.  I describe the 
basic solution at 
<http://forum.springsource.org/showthread.php?115434-Would-it-be-useful-if-SpringJUnit4ClassRunner-had-a-quot-pre-quot-context&p=382183#post382183>.

> 
> The code in my test class looks something like this:
> 
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration({"/applicationContext.xml"})
> public class MyIntTest {
>     @BeforeClass
>     public static void init() {
>         SimpleNamingContextBuilder builder = new
> SimpleNamingContextBuilder();
>         DataSource  someds  =
>                 new
> DriverManagerDataSource(System.getProperty("test.some.url"),
> 
> System.getProperty("test.some.userName"),
> 
> System.getProperty("test.some.password"));
>         builder.bind("jdbc/someds", someds);
>     }
> 
> The reference in the context looks like this:
> 
>     <jee:jndi-lookup jndi-name="jdbc/someds" id="someDataSource"/>
> 
> The problem (or at least one of the problems) is that this "init()"
> method will not get executed until after the context is finished
> initializing.  At a minimum, I need to be able to execute this method
> before the appcontext is initialized.
> 
> It's starting to look like I can't use the Spring runner, and will have
> to initialize Spring manually after I bind the datasource.

Reply via email to