Embedding OpenEJB in a TestCase using javax.ejb.embeddable.EJBContainer

1.7k Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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.

1
On

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.