Quantcast
Viewing all articles
Browse latest Browse all 5

EJBContainer testing

Recently I have tried to optimize my integration tests for my Java EE 7 application.  Previously I had used Cargo to run the server for my integration testing seeing as the team was accepting my patches to get it working for what I needed.  I also used EclipseLink to do my JPA testing.I have also tried Maven embedded GlassFish plugin, but that was a pain and a half to use and didn’t work in the end.  Not to mention it hasn’t been updated since 2011-03-06.

Though it was noted to me that starting up a container and deploying the code can be a bit slow for developers to run locally.   Something I would agree on, but what alternatives are out there?

Java EE 6 actually added EJBContainer.createEJBContainer() method to the standard.  Honestly, this is a pretty nifty thing to use… if it worked.

For simple applications which involve JPA and Stateless Session beans this embedded container will work well.   So much so that tests run in seconds, compared to GlassFish which can take over half a minute.

Unforunately, my Java EE 7 application is not simple anymore.  I added the use of JMS, JavaMail and authentication.  To make EJBContainer.createEJBContainer() work would involve delving into the configuration files and make specific changes to the domain.  Which honestly would be fine except I hit an issue with the keystore not being correct (and I was unable to change it either).

The more I delved into it, the more frustrated I got and realized that if I am going to make this much changes to the domain.xml file and still not get it working, that this may really be a bad idea.  So I have given up on that notion.

However, the exercise did bear some fruit.  I had previously defined derby and eclipselink dependencies for my tests, which works well to run tests for JPA.  However, GlassFish 4.0 is a reference implementation and it provides reference implementations of Java EE 7 libraries.  So I have reduced my dependency to just:

<dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>4.0</version>
    <scope>test</scope>
</dependency>

And my existing test cases still worked.  So a few more lines reduced.


Viewing all articles
Browse latest Browse all 5

Trending Articles