Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/Testing/JPA"

Line 131: Line 131:
 
=== Test Execution  ===
 
=== Test Execution  ===
  
4. ant server-install (server-install will do neccesary config to server)  
+
Once the setup is done, configuring and executing the tests is pretty straight-forward. Server configuration and test execution is controlled by ant targets in the &lt;jpa_test_home&gt;/build.xml file. You can execute the entire set of tests (lrg's - large regression) or individual suites. Browse the build.xml for a list of suites. To execute these targets simply run the command 'ant &lt;target_name&gt;' in the &lt;jpa_test_home&gt; directory. The following sequence of targets need to be executed to run the JPA tests:<br>
  
5. ant server-start
+
'''1'''. '''server-install''' : this actually does not install the server, but does some additional configuration to the app server prior to the server being started.<br>
  
6. ant server-setup (setup datasource on server)
+
'''2'''. '''server-start''' :&nbsp; starts the application server administration server. Note that your choice of JAVA_HOME may affect the stability of this target -- for example, WebLogic Server tends to run better if their JRockit JVM is used instead of Sun JDK. Alternatively, you can also start the application server yourself using the application server's provided start scripts.<br>
  
7. ant server-test-lrg
+
'''3'''. server-setup :&nbsp; performs additional setup and configuration after the server has started. For example, the datasources are created and configured on the server.<br>
  
You can call following ant test targets to run JPA tests in build.xml:
+
'''4'''. server-test-{test suite name} : runs a JPA test suite. The following are common test targets. All the test suite names can be found by browsing the ''server-test-lrg'' target in &lt;jpa_test_home&gt;/build.xml.<br>
  
 
       server-test:              run all JPA LRG tests on server
 
       server-test:              run all JPA LRG tests on server
Line 145: Line 145:
 
       server-test-{model name}: run individual test model only on server, you will find the model name in “server-test-lrg” target
 
       server-test-{model name}: run individual test model only on server, you will find the model name in “server-test-lrg” target
  
8. ant server-reset (remove configured datasource)
+
5. '''server-reset''' : cleans up the server after testing. For example, the datasources created earlier are removed.<br>
  
9. ant server-stop  
+
6. '''server-stop ''':&nbsp; stops the server
  
 
=== '''Additional Application Server Install Steps'''  ===
 
=== '''Additional Application Server Install Steps'''  ===

Revision as of 13:07, 11 September 2009

Running the JPA tests

The JPA tests can be run in J2SE and JEE, using several ways. Following section 1.1, 1.2 and 1.3 demonstrate how to run J2SE tests with following three different ways, section 1.4 "Server testing" demonstrates how to run JPA tests in JEE with ANT.

  • Ant (1.7 or greater)
  • Eclipse JUnit
  • Testing Browser

See here for how to setup repository to get EclipseLink source

Ant

The eclipselink.jpa.test/build.xml contains several ant targets for testing. The "test" target will run the JPA LRG. Ensure that the eclipselink.jpa.test/test.properties file has been configured for your database and environment. You may overwrite this file in {user.home}/test.properties.

 ant test

This will run the JPA LRG, the results will be output into the eclipselink.jpa.test/report directory as html.

The following ant test targets are defined:

  • test (runs FullRegressionTestSuite using agent)
  • test-no-weave (runs FullRegressionTestSuite without any weaving)
  • test-static-weave (runs FullRegressionTestSuite with static weaving)

Eclipse JUnit

The JPA test suite is written using JUnit. It consists of a set of jars that contain various persistence units and a number of tests. The JPA tests are contained in the eclipselink.jpa.test project

  1. Ensure you have an eclipselink jar available on your classpath. This jar is checked in to the foundation component in the SVN repository and can be created by running the ant build located in the eclipselink.core project.
  2. Run the build.xml in base directory of eclipselink.jpa.test. This will create a set of jar files containing the persistence units.
  3. Edit eclipselink.jpa.test/test.properties to include information necessary to connect to your database
  4. Use the JUnit run target provided, or create your own:
    1. The project will be: eclipselink.jpa.test
    2. The test class will be: org.eclipse.persistence.testing.tests.jpa.FullRegressionTestSuite
    3. Add the JVM argument "-javaagent:<eclipselink-jar-location>/eclipselink.jar" - This will allow the test models to run with weaving enabled
    4. Add to your classpath the following:
      1. Your JDBC driver
      2. A library that includes all the jar files generated by the build.xml in jpa.test you ran earlier
  5. Run the run/debug target you created

Testing Browser

The JPA tests can also be run through the foundation Testing Browser. This provides additional debugging capabilities so is sometimes desired. There are some JPA tests that extend the foundation test framework, which are not run through the normal JUnit test target. The "JPA Tests" in the Testing Browser include these tests.

Note: Before testing in Eclipse using the Testing Browser - you will need to a full root build of EclipseLink in 'trunk>ant' so that the test jars eclipse*model.jar get created and placed on the root of jpa/eclipselink.jpa.test. Please refresh your eclipselink.jpa.test project to pick these up before running the Testing Browser eclipse launch target.

The eclipselink.jpa.test Eclipse project contains a launch file for running the testing browser. The database login information and logging level can be configured. If you have previously run the JPA tests on the same database the "Fast" checkbox can be used to avoid recreating the database.

Running JPA tests against Application Servers Using Ant

The JPA tests can be run on any JEE EJB 3 compatible server. Currently you can run JPA tests on the following application servers, using the provided Ant targets:

  • BEA Weblogic Server 9.x, 10.x
  • IBM Websphere 6.x, 7.x
  • Oracle OC4J 10.1.3.x
  • JBoss
  • GlassFish

It may be helpful for you to review the following documentation before continuing with these instructions. The links below will introduce you to the EclipseLink build and test system, and how to integrate EclipseLink with various application servers:

Pre-requisites

Please make sure your environment is set up with the following before starting:

  1. Java VM 1.6+  is installed on your local environment.
  2. ANT 1.7+ is installed on your local environment.
  3. EclipseLink source tree (/trunk) is available in local folder. See this link for information on how to acquire the EclipseLink source. You can use TortoiseSVN to check out and manage the source code.
  4. Target application server is installed (Please note additional configuration steps for different app servers). You typically do not need to perform any additional server configuration post-install. Take note of the install location as you will need to provide this information later.
  5. You have user access to a relational database, and JDBC driver files are available.

Files and Directories

  • <trunk> : the root of the EclipseLink source tree.
  • <trunk>/build.xml : top-level Ant build file for EclipseLink product. You will need to re-build EclipseLink before running the tests by executing 'ant' in this directory
  • <trunk>/eclipselink.jar : the product bits in which the JPA tests run against.
  • <trunk>/../extension.lib.external : This is a directory that you must create and it resides at the same level as <trunk>. You will need to put build dependent JAR files in this directory.
  • <trunk>/../extension.oracle.lib : Similar to extension.lib.external, but used for Oracle specific dependent jars.
  • <trunk>/jpa/eclipselink.jpa.test : JPA test root. All the relevant Ant build files and property files reside here along with the JPA test source code. We will refer to this as <jpa_test_root> for short.
  • <jpa_test_root>/build.xml : top-level Ant build file for building, deploying, and executing JPA tests on application servers.
  • <jpa_test_root>/build.properties : Ant properties file for build.xml. You typically do not need to modify this file.
  • <jpa_test_root>/test.properties : Additional Ant properties file read by build.xml. It contains test-related properties for customizing the test run, such as the database connection info, desired logging level, etc... You will have to modify this file.
  • <jpa_test_root>/{appserver}.xml : Server-specific Ant build files for each supported application server.  Example: weblogic.xml, websphere.xml.  The build files contain targets for server specific actions such as setup, start, deploy, undeploy, reset, and stop. They are called from <jpa_test_root>/build.xml
  • <jpa_test_root>/{appserver}.properties : Ant properties file for corresponding {appserver}.xml. You will need to modify this file, typically with the application server install directory.
  • <jpa_test_root>/setenv.cmd [.sh] : Convenience script for setting environment variables before executing the tests, such as JAVA_HOME, ANT_HOME, and PATH. You will need to modify this file and execute it in your shell window, or set the environment variables manually in your shell.
  • <user_home> : User's home directory. On Linux, this should be defined by the $HOME env variable. On Windows, this is typically mapped to c:\Documents and Settings\{login name}.

Configuration

1. Verify proper installation of pre-requisite applications - Ant, Java VM, and the target application server. Note that there are additional install instructions for some application servers at the end of this document. Take note the install locations for each of these applications.

2. Create the following directories: <trunk>/../extension.lib.external and <trunk>/../extension.oracle.lib. For example, if your <trunk> directory is c:\eclipselink\src\trunk, then create directories c:\eclipselink\src\extension.lib.external and c:\eclipselink\src\extension.oracle.lib.

3. Copy your JUnit jar file to <trunk>/../extension.lib.external/junit.jar. Note that you must rename this jar to junit.jar to align with our test scripts.

4. Copy your non-Oracle database JDBC driver jar files to <trunk>/../extension.lib.external. If you are using an Oracle database, copy the corresponding driver to <trunk>/../extension.oracle.lib. These files will be picked and added to the server classpath at runtime. Please choose the version of your JDBC driver carefully; some databases such as DB2 do not work well with older versions of their driver.

5. Copy test.properties and {appserver}.properties files from <jpa_test_root>  to your <user_home> directory. You will modify these working copies in <user_home> in the next few steps. Note: the test build.xml loads these property files from <user_home> first and also from <jpa_test_root> -- this means you can also choose not to copy these files over to <user_home> and edit them from <jpa_test_root>. The former approach may prevent the property files from being overwritten when the source is refreshed to the tip.

6. Edit the following properties in <user_home>/test.properties.

  • server.name : your target application server. Valid values are:  weblogic, websphere, oc4j, jboss and glassfish
  • jdbc.driver.jar : location of the JDBC driver jar file on file system
  • db.driver : fully qualified JDBC class name (see samples included in property file)
  • db.url : connection URL
  • db.user, db.pwd : db user and password
  • db.platform :  fully qualified database platform class in  (see samples included in property file).

7. Edit the properties in <user_home>/{appserver}.properties. Each application server has its own set of properties - the comments provided in the property files should explain how to set each required property. The following shows an example of properties required in the weblogic.properties and websphere.properties.

WebLogic Server (WLS)
  • weblogic.installdir : the location on the file system where WLS was installed
  • server.user, server.pwd : the admin user and password
  • weblogic.host : WLS admin server host name
  • weblogic.port : WLS admin server port
  • weblogic.domain : location where the tests will create the WLS domain. You need to specify this location, preferably an empty folder.
Websphere (WAS)
  • server.user, server.pwd : the admin user and password
  • was.jython.scripts.dir
  • instance.host
  • was.home
  • server.url
  • server.depend

Test Execution

Once the setup is done, configuring and executing the tests is pretty straight-forward. Server configuration and test execution is controlled by ant targets in the <jpa_test_home>/build.xml file. You can execute the entire set of tests (lrg's - large regression) or individual suites. Browse the build.xml for a list of suites. To execute these targets simply run the command 'ant <target_name>' in the <jpa_test_home> directory. The following sequence of targets need to be executed to run the JPA tests:

1. server-install : this actually does not install the server, but does some additional configuration to the app server prior to the server being started.

2. server-start :  starts the application server administration server. Note that your choice of JAVA_HOME may affect the stability of this target -- for example, WebLogic Server tends to run better if their JRockit JVM is used instead of Sun JDK. Alternatively, you can also start the application server yourself using the application server's provided start scripts.

3. server-setup :  performs additional setup and configuration after the server has started. For example, the datasources are created and configured on the server.

4. server-test-{test suite name} : runs a JPA test suite. The following are common test targets. All the test suite names can be found by browsing the server-test-lrg target in <jpa_test_home>/build.xml.

     server-test:              run all JPA LRG tests on server
     server-test-lrg:          run all JPA LRG tests on server
     server-test-{model name}: run individual test model only on server, you will find the model name in “server-test-lrg” target

5. server-reset : cleans up the server after testing. For example, the datasources created earlier are removed.

6. server-stop :  stops the server

Additional Application Server Install Steps

OC4J:

OC4J Eclipse EAR Application Tutorial

  • If you want to do fresh install, put oc4j_extended.zip under extension.oracle.lib.external. Later when you call “server-install”, “oc4j-install” will unzip and config user/password as defined in oc4j.properties
  • If you have oc4j installed already, put the right location, user name and password to oc4j.properties, remove everything from “oc4j-install” except four <copy> tasks.
WebSphere:

WebSphere Eclipse EAR Application Tutorial

  • Install the product
  • Create following .py files as described below and copy to extension.lib.external, following contents is originally from WebSphere samples, later I modified that to comply eclipselink testing. These scripts will be used in websphere-install, websphere-deploy and websphere-undeploy targets during the testing.
installApps.py
     # If the application is currently installed, uninstall it
     try:
     AdminApp.uninstall('%%appName%%')
     except:
     print '%%appName%% was not previously installed'
     AdminConfig.save()
     # Set the options for the install
     attrs = ['-appname', '%%appName%%']
     # Install the application
     AdminApp.install('%%ear%%', attrs)
     AdminConfig.save()
     # Associate shared library
     deployment = AdminConfig.getid('/Deployment:%%appName%%/')
     print deployment
     appDeploy = AdminConfig.showAttribute(deployment, 'deployedObject')
     print appDeploy
     classLoad1 = AdminConfig.showAttribute(appDeploy, 'classloader')
     print classLoad1
     print AdminConfig.create('LibraryRef', classLoad1, [['libraryName', 'eclipselinkjpa'],  ['sharedClassloader', 'true']])
     AdminConfig.save()
     # Start the application
     appManager = AdminControl.queryNames('type=ApplicationManager,*')
     AdminControl.invoke(appManager, 'startApplication', '%%appName%%')
unInstallApps.py
     # If the application is currently installed, uninstall it
     try:
     AdminApp.uninstall('%%appName%%')
     except:
     print '%%appName%% was not previously installed'
     AdminConfig.save()
configWebSphere.py
     # Create JDBC Driver
     try:
     AdminConfig.remove(AdminConfig.getid('/Node:%%hostName%%Node01/Server:server1/JDBCProvider:OracleJDBCProvider/'))
     except:
     print 'OracleJDBCProvider was not previously installed'
     AdminConfig.save()
     n1 = ['name', 'OracleJDBCProvider']
     implCN = ['implementationClassName', 'oracle.jdbc.pool.OracleConnectionPoolDataSource']
     jdbcAttrs = [n1,  implCN, ['classpath', '%%oracleDriver%%']]
     print jdbcAttrs
     node = AdminConfig.getid('/Node:%%hostName%%Node01/Server:server1/')
     newJDBC = AdminConfig.create('JDBCProvider', node, jdbcAttrs)
     AdminConfig.save()
     print newJDBC
     # Create DataSource
     name = ['name', 'EclipseLinkDS']
     dsAttrs = [name, ['jndiName', 'jdbc/EclipseLinkDS']]
     newds = AdminConfig.create('DataSource', newJDBC, dsAttrs)
     AdminConfig.save()
     print newds
     # Create DataSource Custom Properties
     newds = AdminConfig.getid('/Node:%%hostName%%Node01/Server:server1/JDBCProvider:OracleJDBCProvider/DataSource:EclipseLinkDS/')
     print newds
     newpropset = AdminConfig.create('J2EEResourcePropertySet',newds,[])
     AdminConfig.create('J2EEResourceProperty', newpropset, [['name', 'URL'], ['value', '%%dbURL%%']])
     AdminConfig.create('J2EEResourceProperty', newpropset, [['name', 'user'], ['value', '%%dbUser%%']])
     AdminConfig.create('J2EEResourceProperty', newpropset, [['name', 'password'], ['value', '%%dbPassword%%']])
     AdminConfig.save()
     print '-> Done!'
     # Create Shared Library
     try:
     AdminConfig.remove(AdminConfig.getid('/Node:%%hostName%%Node01/Server:server1/Library:eclipselinkjpa'))
     except:
     print 'eclipselinkjpa was not previously installed'
     AdminConfig.save()
     n1 = AdminConfig.getid('/Node:%%hostName%%Node01/Server:server1/')
     print n1
     library = AdminConfig.create('Library', n1, [['name', 'eclipselinkjpa'], 
     ['classPath', '%%eclipselinkLibDir%%/eclipselink.jar']])
     print library
     AdminConfig.save()

Debugging an EclipseLink JPA EAR in WebSphere 7 from Eclipse


How To

References

Back to the top