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.
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>