You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

You can configure data sources from within your test case (avoiding the need for an openejb.xml entirely) like so:

Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");

p.put("myDataSource", "new://Resource?type=DataSource");
p.put("myDataSource.JdbcDriver", "org.apache.derby.jdbc.EmbeddedDriver");
p.put("myDataSource.JdbcUrl", "jdbc:derby:derbyDB;create=true");

Context context = new InitialContext(p);

Note, this only works when using the LocalInitialContextFactory to embed OpenEJB into the vm. Once embedded, further configuration properties are ignored.

Containers can also be declared. The most useful is to declare a Stateful SessionBean container so that it's guaranteed to passivate and activate on each call to the bean, allowing you to test your callbacks behave as you need them to.

Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");

p.put("myStatefulContainer", "new://Container?type=STATELESS");
p.put("myStatefulContainer.PoolSize", "0");
p.put("myStatefulContainer.BulkPassivate", "1");

Context context = new InitialContext(p);
  • No labels