I've been trying to set my application up so that I can unit test it's EJBs all day but I can't seem to get past what seems like a really simple problem.
I have a standard Maven web application set up in NetBeans 6.9. I've automatically generated a unit test for one of the EJBs but whenever I go to run it I get the error message:
Testcase: initializationError(com.example.ExampleTest): Caused an ERROR
Absent Code attribute in method that is not native or abstract in class file javax/ejb/embeddable/EJBContainer
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ejb/embeddable/EJBContainer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
I've researched this one to death and I'm pretty sure the problem is that my pom currently points to a jar which contains only the API
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
Not and implementation that can be used for running the tests. I'm pretty sure the test is failing in the method marked with @BeforeClass when it tries to execute
container = EJBContainer.createEJBContainer();
The standard recommended solution is to add the glassfish-embedded-all artifact as the first project dependency with test scope
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
I can find a Maven package for this artifact here: http://download.java.net/maven/glassfish/ but Nexus doesn't recognize this directory or any of the subdirectories as Maven 2 repositories. I suppose I could download the jar and manually install it into Nexus but that seems to defeat the who point of installing Nexus.
So, is there a Maven repository that Nexus will be able to index to give me the glassfish-embedded-all artifact? A couple of posts I read mentioned that the correct artifact to now be using is javax.ejb but I've had no more luck finding this.
As you've probably guessed I'm completely new to unit testing and fairly new to JEE6 in general; is this even the correct way to go about unit testing EJBs?