Java Reference
In-Depth Information
It might seem that CDI should be used for all Java EE injections, but it currently has a lim-
itation. Although CDI can retrieve an EJB by type, it doesn't work with remote EJBs. EJB
injection ( @EJB ) will recognize whether an EJB is local or remote and return the appropri-
ate type. You should use CDI for injection when possible.
1.5.6. Testable POJO components
Because all EJBs are simply POJOs, you can easily unit test them in JUnit for basic com-
ponent functionality. You can even use CDI to inject EJBs directly into unit tests, wire
mock objects, and so on. Thanks to embedded containers, you can even perform full integ-
ration testing of EJB components from JUnit. Projects like Arquillian focus specifically on
integrating JUnit with embedded containers. The following listing shows how Arquillian
allows you to inject EJBs into JUnit tests.
Search WWH ::




Custom Search