tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laird Nelson <>
Subject Making use of the injection facility?
Date Wed, 06 May 2009 16:40:43 GMT
Hello; I'm writing a JUnit test runner that I would like to perform
EJB-compliant dependency injection.

That is, if I have a test class like this:

public class SomeTest {
  protected ArgleBargle bean;

...then I want the test runner to, using the local server of OpenEJB,
inject, if possible, an instance of type ArgleBargle into the bean field.

I've already checked out the DI example by Jonathan Gallimore (,
but this seems to kind of hack "just enough" DI in there to make it work.

And I've already overridden the createTest() method of
BlockJUnit4ClassRunner to create a new InitialContext with the proper
LocalServer properties.

That means that in my hands I have the raw materials to make a set of
org.apache.openejb.Injections: I have a test class, from which I can get
annotated fields.  And I have an InitialContext all set up with an ENC (at
least I think there should be one; maybe not), as created by

If I can get my hands on the Injections, built properly, then I should be
able to call InjectionProcessor.construct(), right?

My overall question is: is this the most efficient way to do this, or is
there some sort of all-in-one munger buried in the OpenEJB codebase
somewhere that will do this for me?

I do recognize that I am violating the specification: a test class is
neither a web module, an ejb module nor an application client module, and so
hence strictly speaking cannot have dependency injection performed on it.
However, it seems to me that OpenEJB is flexible enough in its innards that
if you supply all the right raw materials there must be some decoupled class
somewhere that will scan an *arbitrary* class and attempt to perform
injection on it.  Is that the case?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message