Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB 3.1 Embedded API - Unit test EJB + JPA entities

Has anyone done this or attempted to do this for a preexisting project?
It seems there are two options to go with here, either using the embedded EJB API basically the following class

javax.ejb.embeddable.EJBContainer

Which expects a configured glassfish v3 install to be available (application scoped resources will make this easier).

The alternative is using the embedded glassfish jar files and the embedded glassfish API

I am looking for feedback from someone who has or who is in the process of doing this, links to blogs etc with a simple EJB & test case are dime a dozen.

If you've done this with any other EJB 3.1 container feel free to share.

  1. Did you use any particular test framework for reasons other than it been your preferred tool?
  2. Which JPA 2.0 implementation did you use, and was there a particular reason for doing so?
  3. If you used glassfish which of the above strategies did you use? If not then which EJB 3.1 container did you use?
  4. If you successfully did this, was it worth the effort and would you do this again for another existing project?
like image 584
Justin Avatar asked May 05 '10 15:05

Justin


2 Answers

It seems there are two options to go with here, either using the embedded EJB API (...) which expects a configured glassfish v3 install to be available.

No, you can also use a minimal domain inside your project.

I am looking for feedback from someone who has or who is in the process of doing this, links to blogs etc with a simple EJB & test case are dime a dozen.

I've done integration testing of EJB 3.1 and JPA on my pet project (under Maven), inspired by Unit Testing EJBs and JPA with Embeddable GlassFish. Reading it is definitely worth it.

Did you use any particular test framework for reasons other than it been your preferred tool?

Nope.

Which JPA 2.0 implementation did you use, and was there a particular reason for doing so?

I used EclipseLink (because it was available at that time).

If you used glassfish which of the above strategies did you use? If not then which EJB 3.1 container did you use?

I used the Embedded EJB API, I was planning to run my code on other Java EE 6 containers when they'll be available.

If you successfully did this, was it worth the effort and would you do this again for another existing project?

Well, I think that integration / functional testing have value and find that the Embedded EJB API is really nice for that. It was not a pain to use it even if I don't consider my sample as a real life project.

For more complex scenarios, I keep an eye on the maven-embedded-glassfish-plugin (see also this answer).

like image 182
Pascal Thivent Avatar answered Sep 24 '22 15:09

Pascal Thivent


I have written a small tutorial on my blog for using embedded glassfish 3.1 for unit-testing EJBs using javax.ejb.embeddable.EJBContainer. There are some pitfalls to it, which I got around by modifying the default embedded glassfish domain and putting some properties to createEJBContainer() call.

like image 29
Paul Schyska Avatar answered Sep 23 '22 15:09

Paul Schyska