I would like to have a JUnit (or other) system where the enterprise beans can be tested in a mock environment so that all resources/beans and so on are injected locally. The enterprise beans should not have to accomplish this. All kinds of injection should be supported.
- I would like to have a maven plugin for this so that the tests can be run from a maven build.
- Transactions are not necessary during the unit tests,this would require a complete container.
Do you know of such a maven plugin or test framework? Experiences with it?
Not necessarily the easiest way, but I managed to get this working using JBoss’s embeddable EJB3.0 container, with major assistance from Java Persistence with Hibernate
For a start, I don’t know of maven plugins/dependencies for this, so I had to install my own locally:
(1) Download
jboss-EJB-3.0_Embeddable_ALPHA_9.zipfrom downloads(2) This zipfile contains two important JARs:
jboss-ejb3-all.jarthirdparty-all.jar(3) Install these JARs into your local repository (use your own initials instead of
nkl):(4) If all has gone well, you should now have two directories in your local repository.
(5) Now add the following dependencies to your
pom.xml(6) I also needed to add dependencies for HSQLDB, and SLF4J
(7) You need to copy some files from the
confdirectory of the zipfile to thesrc/main/resourcesdirectory of your project:default.persistence.propertiesejb3-interceptors-aop.xmlembedded-jboss-beans.xmljndi.properties(8) I created my own
beans.xmlandpersistence.xmlfiles insrc/main/resources/META-INF:(9) I created a unit test like the following, using additional infomation from here.
(10) This uses a simple SLSB like:
(11) And a Message entity class like:
Lets just say there are a number of stumbling blocks along the way in this approach.
Notably to do with the order of dependencies.
Good luck!!