INTEGRATION TEST WITH REMOTE GLASSFISH 2.1
Prepare Glassfish 2.1 for JumpStart
- We assume you have a normal working Glassfish 2.1 installation...
- To get it, go to Glassfish Downloads, locate Glassfish Server v2.1 and choose the Download link. Download the binary build jar for your platform.
- Move it to a suitable location (eg. /devel/), then follow the instructions they gave to unbundle and configure Glassfish.
- Add Hibernate to Glassfish:
- Modify the add.hibernate.to.dir property in the JumpStart project's data_util.properties file.
- Run the add-hibernate-to-a-server target of the JumpStart project's data_tuil.xml Ant file.
- Check the server's lib now has the Hibernate jars, eg. hibernate-core-3.3.1.GA.jar.
- Tell Hibernate to drop and create the database tables at restart:
Caution: DO NOT DO THIS STEP IN A PRODUCTION ENVIRONMENT as all existing data will be lost.
Add the following system property to the server config (eg. domains/domain1/config/domain.xml). The property is explained here: hibernate.<jvm-options>-Dhibernate.hbm2ddl.auto=create-drop</jvm-options>
- Start Glassfish and Derby, eg. from the command line like this:
- asadmin start-domain domain1
- asadmin start-database
- Check the system properties are correct in the JVM Options:
- Go to the admin console web page, eg. http://localhost:4848/. Log in as admin.
- Choose Application Server > JVM Settings > JVM Options and inspect them.
- Add the data source jdbc/JumpStartDS.
- Go to the admin console web page, eg. http://localhost:4848/. Log in as admin.
- Choose Resources > JDBC > JDBC Resources
- Add new resource jdbc/JumpStartDS using the Derby Pool.
The name of this resource is crucial - it has to match jta-data-source in persistence.xml. When JumpStart builds an EAR for Glassfish/Derby, it gets the persistence.xml from business/src/main/resources/persistence-descriptor/glassfish-hibernate-derby-persistence.xml.
- Add log4j.
- Copy log4j.jar from business/src/test/lib-test/ to the server's lib, eg. domains/domain1/lib/.
- Copy log4j.properties from business/src/test/conf-glassfish-remote/ to the server's conf, eg. domains/domain1/config/.
- Go to the admin console web page, eg. http://localhost:4848/. Log in as admin.
- Choose Application Server > JVM Settings > Path Settings.
- Add the log4j.jar and the config directory to the System Classpath, eg.
/devel/glassfish/domains/domain1/lib/log4j.jar
/devel/glassfish/domains/domain1/config
- Restart Glassfish, eg. from the command line like this:
- asadmin stop-domain domain1
- asadmin start-domain domain1
Prepare the build
- In the project's build.properties file, edit the value of these properties:
- deployment.server.type
- deployment.persistence.descriptor
- deployment.web.descriptor
- integration.test.server.dir.
Either build and run the tests from Ant...
Ant will compile, package and deploy jumpstart.ear to the server, wait for it to load,
then run the integration test suite which will test through the session beans running in the server.
- Run the Ant target clean-compile-test-package-integrationtest in the project's build.xml file.
- If you get an error about JAVA_HOME, read this. Use a JDK 1.5 tools.jar.
...or build with Ant and run/debug the tests from Eclipse
First, use Ant to compile, package and deploy jumpstart.ear to the server and wait for it to load:
- Run the Ant target clean-compile-test-package-preintegrationtest in the project's build.xml file.
- If you get an error about JAVA_HOME, read this. Use a JDK 1.5 tools.jar.
- In Eclipse, choose Window > Preferences > Java > Build Path > User Libraries (or in OS X, choose Eclipse > Preferences > Java > Build Path > User Libraries), and
- create a new user library called glassfish-client-lib, then
- add these JARs from Glassfish's lib/ to the new user library:
- appserv-deployment-client.jar
- appserv-ext.jar
- appserv-rt.jar
- Choose Run > Open Run Dialog.... The Run window will appear.
- Right-click on JUnit and choose New.
|
- Click on the Classpath tab.
- Click Run.
- Watch the results in the JUnit View panel. In the Console View you might see lots of exceptions but that's normal. The JUnit View will tell you quickly whether the tests succeeded or not.
Problems? Eclipse might not be ready for junit - see Could not create task or type of type: junit.