Reputation: 73
Embedding OpenEJB in a TestCase using javax.ejb.embeddable.EJBContainer.
EJBContainer container = EJBContainer.createEJBContainer();
always returns "null".
How to instantiate the EJBContainer and get the context for looking up EJB 3.0 local stateless session Bean for unit testing?
I would like to get the context from the created container rather than from initial context, how it can be done?
Upvotes: 1
Views: 1776
Reputation: 73
In OpenEJB, the OpenEJB 4.0.0 -beta is found to be supporting java ee embeddable API and with this we can embed the container in our testcase like,
EJBContainer ejbContainer = EJBContainer.createEJBContainer();
In previous versions of OpenEJB we can't do like this and hence we use "LocalInitialContextFactory" to create the context.
Upvotes: 1
Reputation: 3701
How to instantiate the EJBContainer and get the context for looking up EJB 3.0 local stateless session Bean for unit testing?
(I think you intended to ask about EJB 3.1. The javax.ejb.embeddable.EJBContainer
was added in EJB 3.1) You could do that like this:
EJBContainer ejbContainer = EJBContainer.createEJBContainer();
Object object = ejbContainer.getContext().lookup("java:global/simple-stateless/CalculatorBean");
Have a look at the Simple Stateless example.
Upvotes: 2