1 Reply Latest reply on Mar 3, 2006 10:56 AM by bill.burke

    injecting mocked dependencies

    tom_goring

      Hi All,

      I would like advise on testing an EJB3 Session Bean.
      I Have a few session beans and I?m currently successfully testing them in junit using the embedded EJB container and a in memory database.

      In the case where 1 session bean has another injected I?d like to override this and inject my own mocked out session bean. I.e. I?d like to override the annotated configuration with an alternative bean to inject.

      Does this seem an OK approach and how would I go about doing this ?
      Does anyone have an example of this.

      Thanks

        • 1. Re: injecting mocked dependencies
          bill.burke

          I think it can be done.

          Write your mock. Register it within JNDI.

          Create an ejb-jar.xml file for your deployment. Override the @EJB annotation with an

          <ejb-local-ref> or <ejb-ref>
          ...
          <mapped-name>THe global jndi name</mapped-name>
          


          Are you following me? I'd go try it out myself, but i'm very swamped at the moment.