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"

m (Testing Browser)
m (Running JPA tests against Application Servers (e.g. WebLogic Server, Websphere, Glassfish))
Line 47: Line 47:
 
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.
 
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 (e.g. WebLogic Server, Websphere, Glassfish) =
+
== Running JPA tests against Application Servers (e.g. WebLogic Server, Websphere, Glassfish) ==
  
 
**** WARNING: this doc is currently under construction - Sept 8/2009*****
 
**** WARNING: this doc is currently under construction - Sept 8/2009*****
Line 55: Line 55:
 
The JPA tests can be run on any JEE EJB 3 compatible server. Currently you can run JPA tests on BEA Weblogic Server, IBM Websphere, Oracle OC4J, JBoss, and GlassFish using the QA test scripts.&nbsp; Ant is used to build, deploy, and run the tests.<br>
 
The JPA tests can be run on any JEE EJB 3 compatible server. Currently you can run JPA tests on BEA Weblogic Server, IBM Websphere, Oracle OC4J, JBoss, and GlassFish using the QA test scripts.&nbsp; Ant is used to build, deploy, and run the tests.<br>
  
== Pre-requisites ==
+
=== Pre-requisites ===
  
 
Please make sure your environment is set up with the following before starting:
 
Please make sure your environment is set up with the following before starting:

Revision as of 09:58, 9 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 (e.g. WebLogic Server, Websphere, Glassfish)

        • WARNING: this doc is currently under construction - Sept 8/2009*****


The JPA tests can be run on any JEE EJB 3 compatible server. Currently you can run JPA tests on BEA Weblogic Server, IBM Websphere, Oracle OC4J, JBoss, and GlassFish using the QA test scripts.  Ant is used to build, deploy, and run the tests.

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 OC4J and Websphere below). 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.


Property Files

Each server specific install, setup, start, deploy, undeploy, reset, stop targets are defined in server specific xml file named as server name along with .xml like weblogic.xml… under <trunk>/jpa/eclipselink.jpa.test; each server specific properties are stated in properties file named as server name along with .properties like weblogic.properties…under <trunk>/jpa/eclipselink.jpa.test; build.xml under <trunk>/jpa/eclipselink.jpa.test will call above these sepcifc targets depends on server name when running test.


Configuration

To run JPA tests on a server, make sure you have junit.jar and database drivers other than oracle in extension.lib.external if you want to use databases other than oracle, or oracle jdbc driver under extension.oracle.lib.external same as you do other eclipselink testing, these two dirs are parallel to trunk, then you need to do the following:

1. Install your JEE server. (note: see oc4j and websphere special instructions)

The default location for your server would be paralle to your trunk, if you want to use existing install, you need to change server properties file to reflect that

2. Edit your test.properties under your home dir or eclipselink.jpa.test dir

  • Set the "server.name" to your server, you can choose weblogic, websphere, oc4j, jboss and glassfish
  • Fill in database information like jdbc.driver.jar, db.driver, db.url, db.user, db.pwd and db.platform

3. Edit server specific properties file like weblogic.properties:

  • Have right server user name and password
  • Have right server install location
  • Have right server url


Test Execution

4. ant server-install (server-install will do neccesary config to server)

5. ant server-start

6. ant server-setup (setup datasource on server)

7. ant server-test-lrg

You can call following ant test targets to run JPA tests in 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

8. ant server-reset (remove configured datasource)

9. ant server-stop

Note: special instructions for oc4j and websphere install

OC4J:

  • 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:

  • 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

Back to the top