Note that I very closely reflect the example given here .
In fact, my situation is somewhat simpler, because I do not even test with a unit of persistence at the moment. My test project provides a simple MDB and bean session; both the MDB and the bean session load as usual and can be successfully tested (limited) without injection.
The proposed injection with the @LocalClient annotation on my unit tests fails with a known error:
javax.naming.NamingException: Unable to find injection meta-data for [your-class]. Ensure that class was annotated with @org.apache.openejb.api.LocalClient and was successfully discovered and deployed. See http://openejb.apache.org/3.0/local-client-injection.html
When I visit this page, he informs me that I may need to add an additional property to the context setting of the test case. So now it looks like this:
@Override public void setUp() throws Exception { initializeContext(); }
public void initializeContext() { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
But he still fails. I really like this idiom, and I would be very happy if I could successfully use it in my projects.
A few other notes:
- I provide the "empty" ejb-jar.xml (in src / main / resources) and the application-client.xml (in src / test / resources) proposed by Apache to tell OpenEJB about scanning the class path [UPDATE: as it turned out, I did it wrong. See My answer below for a suggestion that worked for me.]
- Test cases annotated with
@LocalClient are not identified by the OpenEJB engine, since they are actually received and handled properly (for example, my MDBs)
Thanks in advance for your help or guidance.
source share