Uploaded image for project: 'OpenEJB'
  1. OpenEJB
  2. OPENEJB-728

Standard JUnit TestCase subclass with dependency injection annotations

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.1.x
    • None
    • integration
    • None

    Description

      From user@openejb 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jlaskowski Jacek Laskowski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: