Reputation: 1852
I have just implement some entities and some backing beans. However, I would like to know if there is someway to test the domain model, or entities, on the application server which in this case is Glassfish.
For example when I have added a new entity, I would like to test that the persistence is correct by writing and reading the entity and maybe do some operations.
I have used JUnit for standard applications, but now on a web application which is deployed on the application server makes me confused.
What is the standard way to deal with this. I have heard something about JSFUnit but I didn't see any example for Glassfish (maybe it doesnt matter?)
PS. My project involve EJB's, which I assume require either testing under an embedded application server or hosting server?
Can you please help me to understand what is the best practice to deal with this kind of stuff?
Best regards
Upvotes: 0
Views: 182
Reputation: 4524
Preferably you want out of container testing, which is very possible since JPA works outside of container. Just set up a new persistence.xml designed for testing, configured as if you were using Java SE only, and you can test your entities. You will have to set the entitymanager instance yourself thought, since you are not inside your container. Either let your test classes inherit from the EJB you are testing and set the protected EntityManager instance to an instance from your EntityManagerFactory, or add a setter to your EntityManager in each of your DAO EJBs. Then you should be ready to go. You will have to handle your transactions manually though, which should be possible to in the same way for most calls since you will probably want to rollback changes from each test.
Upvotes: 1