Externalize db access data for junit-testing

2008-08-12 Thread Newgro

Hi *,

first thanks to the openejb team for this great product. It helps alot for
ejb3. Wiki pages and forum support are great.

I start to implement some tests for my beans. The datasource will be
configured by using the initial context properties. So far all works fine.

But i would like to externalize these parameters to an xml or properties
file.
Is there a way to put my datasources to a place where openejb is come along
automatically? My tries to add them to openejb.xml failed. Documentation
point would help to (If this is already in the wiki - didn't found a paper).

Thanks
Per
-- 
View this message in context: 
http://www.nabble.com/Externalize-db-access-data-for-junit-testing-tp18940819p18940819.html
Sent from the OpenEJB User mailing list archive at Nabble.com.



Re: Externalize db access data for junit-testing

2008-08-12 Thread David Blevins

Hi Per,

On Aug 12, 2008, at 2:38 AM, Newgro wrote:

first thanks to the openejb team for this great product. It helps  
alot for

ejb3. Wiki pages and forum support are great.


Thanks!  A very large percent of the docs come straight from the list,  
so a big thanks to all the people with questions/requests.  It's very  
appreciated.


But i would like to externalize these parameters to an xml or  
properties

file.
Is there a way to put my datasources to a place where openejb is  
come along
automatically? My tries to add them to openejb.xml failed.  
Documentation
point would help to (If this is already in the wiki - didn't found a  
paper).


Sure, try this.  Create an openejb.xml file in any directory that gets  
added to your test classpath. For maven, something that winds up  
directly under target/classes/ or target/test-classes/ will work  
just fine.  Then in your test case do this:


protected void setUp() throws Exception {
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,  
org.apache.openejb.client.LocalInitialContextFactory);


URL config =  
this.getClass().getClassLoader().getResource(openejb.xml);
properties.setProperty(openejb.configuration,  
config.toExternalForm());


initialContext = new InitialContext(properties);
}

The file itself doesn't have to be called openejb.xml, you could  
have a few different files like that for different testing scenarios  
each with a name that describes the basic setup.


-David



Re: Externalize db access data for junit-testing

2008-08-12 Thread Karan Malhi

  Documentation
 point would help to (If this is already in the wiki - didn't found a
 paper).


Some documentation for configuring DataSources can be found here
http://openejb.apache.org/3.0/configuring-datasources.html
Easiest way to find documentation about something on the wiki would be to
search it using our search (on the top right of every page)


-- 
Karan Singh Malhi