Hi Andrew,

Here is an example using OpenJPA/Entities/EJB3/EE. Specifically, an @Stateful, injected EntityManager with EXTENDED persistence context, and a JUnit TestCase.

  
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/injection-of-entitymanager/

This one is identical to the above but uses Hibernate instead of OpenJPA:

  http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/jpa-hibernate/

This example is similar to the above two but uses an EntityManager with TRANSACTION persistence context and shows how to run your test code in a container controlled transaction. Could easily be updated to use Hibernate instead (just switch the pom.xml with the above one and swap the persistence.xml files).

  
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/testing-transactions/

I'm not really a believer in fake environments, especially when you can get an equally lightweight, fast and easy to use EJB container that's actually been incorporated in a Java EE 5 certified platform.

Hope this helps!

-David


On Mar 4, 2008, at 4:41 PM, Andrew Hughes wrote:

Hi All,

This seems to be a hot topic at the moment, but there is very little
documentation and references I can find... and so I'm asking for your help.

*Background:*

One of Maven's most brilliant functions is it's lifecycle's ability to slip straight into agile+continuous integration development (kudo's to maven). It's a wonderful thing that when you write your code and its unit tests today, that maven in many future versions and with countless changes will ensure your tests still work! If they don't maven will fail the build (I could go on but I wont)! So, the reason I'm really on this mailing list is because I want to utilize this wonderful practice! Manually unit testing and
manually notifying people about error's is unreliable and so 2004!


*So what do I want to test:*

*Hibernate Entities:*

I have an Entity data model that is provided by Hibernate maven modules. Each modules entities need to be unit tested. From what I have read.. the options available to perform this are Easygloss/mock, ejb3unit, OpenJPA, and
TestNG.

What I found so far (and don't take this as definitive):

Easygloss/mock: This works a treat! Within my unit test's I can setup() an instance of a (Hibernate) entity manager and thus my Entities do persist. The unit tests are a little "cut and paste" the setup() into all of them,
but as a whole you can't complain too much if it works.

ebj3unit: This I found to be both brilliant and also non functional. I hope I am wrong, but I can't get this working with Hibernate. When I do run it against my entities I get all sorts of "Use of @OneToMany or @ManyToMany targeting an unmapped class" exceptions and problems with "@Embbeded" eta eta eta. Something which does not occur in easygloss, or when running the tests with ithin the JunitEE on the Application Server. What I can say is this is quite cool! The test classes you extent have some very neat default tests you should have run over your entity beans. Example would be, read a record x2 and see if both objects are .equals(). Other than the fact I can't get it working, it's greatest downfall is that I can't find a mailing list or irc channel or blog or wiki or anything to figure out what/if I am doing something wrong. From what I can see, it's brilliant... but I really need it
working.

OpenJPA: I am yet to use... but I can only assume this is pure JPA and not
hibernate? Don't take my word for it though.

TestNG : I am reading up on now, which looks good... but because Im greedy I do like the ejb3unit "default" tests and it will be hard to discard them.


*EJB3:*
As common moden architecture, you wrap your Entitie's with sensible "real world" operations on your data model (Entities). So lets say someone changes the @bean*, you want to make sure you don't effect anything else and you want to test it does persist and comes back out the other side. Now it gets a little complex, because not only do you need to mock the EJB* container for your session* beans. Because the beans depend on Entities, you will also need an entity manager. So... you need the out of container entitiy manager above to work at the same test phase as we have here to test your EJB3 @bean
's.

Because I have not solved the above adequately, I have not looked at this yet. In an ideal world, the ejb3unit would be working and I could build on this... or if I get TestNG working it should do both... or if OpenJPA does
support hibernate I should be able to use it with OpenEJB.


To cut a long story short, it will be excellent when this is all running and I will spread my knowledge if some smarter people than me read then and help
me out.

Cheers.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to