Skip to main content

Question on testing JPA in GlassFish

2 replies [Last post]
ols
Offline
Joined: 2007-05-26

Hi all,

I am using GlassFish and NetBeans to create a JSF app that access a MySQL DB via JPA/Toplink.
I have created a Web App project, create entities from the DB. Everything is Ok, except that I have problems to unit test my entites and my business logic with JUnit. These problems seem related to JNDI stuff. (Test is outside the container).

I create a new java project, recreate entities and business logic. Within this project I succeed to do unit testing.

Do you think it is reasonable to put all my entities and business logic inside a jar file, and use this jar file inside the JSF web app ?

Do you have other ideas ?

Thanks for your help

ols

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nuffsaidx
Offline
Joined: 2008-12-18

[b]Question: Do you think it is reasonable to put all my entities and business logic inside a jar file, and use this jar file inside the JSF web app?[/b]

Answer: Here is my ten cents:

A. One java project for your jpa (i.e., pojo, persistence.xml, orm.xml) stuff
B. One java project for business logic interface
C. One ejb project for implementation of the business logic (i.e., session beans, @webservice)
D. One web project for your web stuff
E. One ear

Also, I use separate package for data access stuff (reading, writing, updating, finding entities) using EntityManager in database and another package for business logic (aka use cases). Both will have interfaces and implementation using session beans but interface will go into B and implementation to C.

In D
add A and B as projects
add third-party web specific jars to D lib directory

Packaging EAR (E)
C.jar
D.war
third-party jars
lib/A.jar
lib/B.jar

Testing

1. Use Junit to test C classes i,e business logic, use cases (i.e., session beans, webservice) etc.

2. If you are using JSF try “jboss-jsfunit” and also facestrace. Both are very easy to configure and use in testing face-config, web.xml, jsf pages etc. You may also want to try cactus.

Some useful links:
JBoss-jsfUnit
http://ttlnews.blogspot.com/search/label/configuration
http://www.jboss.org/jsfunit

FacesTrace
http://www.prime.com.tr/facestrace

ols
Offline
Joined: 2007-05-26

Thanks very much for your answer !
Olivier