Extreme Java When vanilla Java is not enough

22Mar/100

Unit Testing EJBs 3.1 with Glassfish Embedded

Pretty simple, indeed. You need the "glassfish-embedded-all-3.0-b74b.jar", and use the new EJBContainer like this:

MyBean ejb = (MyBean) EJBContainer
    .createEJBContainer()
    .getContext()
    .lookup("java:global/classes/MyBean");
assertEquals(3, ejb.add(1, 2));

And remember that you can use a deployment descriptor on your test classpath to customize both transaction and datasource for your unit testing.

If you are using maven, use this dependency instead of javaee-api:

<dependency>
   <groupId>org.glassfish.extras</groupId>
   <artifactId>glassfish-embedded-all</artifactId>
   <version>3.0-b74b</version>
   <scope>provided</scope>
</dependency>

If you put "javaee-api" as "provided" and GF as "test", you will receive nasty "Abscent Code" errors.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)


*

No trackbacks yet.