Standard JUnit TestCase subclass with dependency injection annotations
----------------------------------------------------------------------

                 Key: OPENEJB-728
                 URL: https://issues.apache.org/jira/browse/OPENEJB-728
             Project: OpenEJB
          Issue Type: New Feature
          Components: integration
    Affects Versions: 3.0.x
            Reporter: Jacek Laskowski


>From [EMAIL PROTECTED] mailing list:

What I was just typing up in another email is that we would like to
find some way to support what you were trying to do; a standard JUnit
TestCase subclass with dependency injection annotations.

An option I've suggested in the past would be something simple like
this.

public class EjbDiTest extends TestCase {

   @EJB private DataReaderLocal dataReaderLocal;
   @EJB private DataReaderRemote dataReaderRemote;

   private InitialContext initialContext;

   protected void setUp() throws Exception {
       Properties properties = new Properties();
       properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");

properties.setProperty("openejb.deployments.classpath.include",
".*injection.*");

       properties.put("openejb.inject", this);  // <------ you give
us a reference to your test case

       initialContext = new InitialContext(properties);
   }
}

Then we do the injection on your test case.

Internally, it's much trickier as we'd like to support not just @EJB
but also @Resource and the rules that make those two annotations work
can get pretty complex.  The way the code is written now, we'd
essentially have to treat the test case as an app client and run it
through deployment where all its references to ejbs and datasources,
etc. would get resolved.

That's one theory anyway.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to