JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.1 | Preparation | O/R Mapping | Runtime | Extensions | Developer
Development
Testing
JPOX Design : Unit Tests

JPOX uses JUnit for unit testing. JPOX uses 2 types of unit tests. The first type are traditional component tests (for individual classes). The second type are more like end-to-end tests where we are persisting objects to a datastore and performing real JDO operations. For this second type, and because JDO has many aspects, we use a "scenario" testing strategy. By this we mean that we separate our unit tests into what they test. When developing anything, the unit tests should be the guiding light as to whether you should be checking anything in to CVS. If your change breaks things, you shouldn't check things in.

Test Scenarios

There are currently 3 scenarios

  • General - generic tests, like MetaData, or internationalisation.
  • Datastore - testing of datastore identity functionality.
  • Application - testing of application identity functionality.

Because the last 2 scenarios are very similar in nature, we often use the same classes for testing, but specify different MetaData, meaning that the class is persisted in different ways. The way this is done is by providing jdoa (application id) and jdod (datastore id) MetaData files. These are standard MetaData files, but with a different suffix to define which applies where. This is then interpreted by the testing process and copied across to the testing area with suffix jdo.

Some things to bear in mind :-

  • The tests to run in each scenario are defined in the file test.properties
  • Not all unit tests currently pass. This is because we adopt the policy of adding unit tests for functionality that is not yet supported. Yes, we know some people dont share the same policy, but then these are JPOX rules and are defined here.
  • The unit test results on the website are, unless otherwise stated, for HSQLDB 1.8 using the most recent JPOX 1.1 version. If in doubt check the date on the results in CVS.


Testing with Maven

The "persistence" unit tests are run via a Maven jpoxtest plugin. You need to install the "jpoxtest" Maven plugin before running the tests. Go to the "Plugins/JPOXTest" project and build/install the plugin. Read the README.tests file in the JPOX/Core directory for other dependences and troubleshooting in general for using Maven for JPOX. When preparing to run you need to familiarise yourself with the contents of project.properties (which specifies the RDBMS to run, and the JDBC jar to use), and the "TestFramework" project which has RDBMS config files under "src/conf".

To run the "persistence" unit tests with Maven you use the following goals, each representing a test scenario respectively

maven jpoxtest-general

maven jpoxtest-datastore

maven jpoxtest-application
                

The results of the tests are stored under target/test-reports-{scenario name}.

The testing process with Maven operates in 2 ways. The first is for the component based unit tests that are run via the "test" plugin. The persistence unit tests are run via the "jpoxtest" plugin. This provides the functionality necessary for a persistence scenario to be tested. It operates as follows

  1. Copy all test classes across to the scenarios work area.
  2. Copy all MetaData files with suffix jdo across to the scenarios work area.
  3. Copy all MetaData files with the specified suffix (e.g jdod across to the scenarios work area with suffix jdo.
  4. Copy the jpox-{rdbms}.{number}.properties files across to the scenarios work area from "src/conf"
  5. Run the enhancer on the classes and JDO files in the scenarios work area.
  6. Run JUnit on all tests specified as input to the scenario test.
  7. Convert the JUnit output into a single page for use on the website.
Testing with Ant

The Ant process operates similarly to Maven, using Ant scripts. To run Ant, you need to use the following Ant targets : test.general, test.datastore, test.application, test.Enhancer to run the different test scenarios. The results of the tests are stored under tests/results/.

 ant test.general ant test.datastore ant 
                    test.application ant test.schema ant test.Enhancer 

In addition, you can run the Ant target test to run all test scenarios : general, schema, datastore, application and Enhancer.

 ant test 

If you want run independent tests cases with Ant, use the following command :

ant test.case -Dtest.suite.case=Test -Dtest.suite.case.identity=scenario
                    
e.g. for the org.jpox.RelationshipTest using datastore identity
ant test.case -Dtest.suite.case=**/RelationshipTest.class -Dtest.suite.case.identity=datastore
                    
e.g. for the org.jpox.RelationshipTest using application identity
ant test.case -Dtest.suite.case=**/RelationshipTest.class -Dtest.suite.case.identity=application
                    

Adding Unit Tests

Where you feel that our unit tests do not adequately cover functionality, you should add a test. Please follow the following process

  1. Write your unit test, extending one of the common base classes in src/test/org/jpox, for example PersistenceTestCase.
  2. Decide which test scenario your test fits into. It may fit in to more than 1 if necessary. You add the test to the test.properties file.
  3. Run your test.
SCO Unit Tests

The SCO collection unit tests sit in their own area (org.jpox.sco) and are all related, in the same way as all java Collections are related. Each collection type has its own subdirectory containing helper classes and elements to be persisted. In addition there is one test class for each SCO collection class. The test class tests Normal and Inverse operation of the collection class.

Debugging Tests in Eclipse

Debugging JPOX unit tests might be very boring, but there is a way of reducing the pain in Eclipse using the JPOX Eclipse Plugin. Follow the next steps to make this easier:

  1. Install the JPOX Eclipse Plugin.
  2. Add enhancement to the JPOX project. Right Click on the project > JPOX > Enhance with JPOX 1.1.

  3. Setup the enhancement. Right Click on the project > JPOX > Enhance setup. If you are going to run the test in General or Datastore Scenario use "jdo,jdod" as suffix for jdo files and for Application Scenario use "jdo,jdoa".

  4. Run a JUNIT test in DEBUG mode, but first, you must setup some configuration to run the tests







    Don't forget to set the jdo file suffix for the Scenario you are going to run.

Debugging Enhancer in Eclipse

To debug the JPOX enhancement, follow the next steps:

  1. Create a new Java application for run or debug. In Eclipse, click on the menu Run and Run... or Debug....
  2. Click on the Java Application and New
  3. Set up the configuration as presented on the next screenshots.



  4. Input all of the jdo (jdo,jdod,jdoa) files with space to separate each file.



  5. Make sure the classpath is correct.



  6. That's all. Now run it in debug mode.

Databases Notes

This section has notes about running the JPOX unit tests with certain databases.

Oracle 10.2.0.1

If you face the issue ORA-12519, TNS:no appropriate service handler, try increasing the parameters sessions and processes to 300 and open_cursors to 1000 in the file initXE.ora or init.ora.

*.processes=300
*.sessions=300
*.open_cursors=1000

If you face the issue ORA-01000: maximum open cursors exceeded, try increasing the parameter open_cursors to 1000 in the file initXE.ora or init.ora.

*.open_cursors=1000

If you face OutOfMemory errors, increase the Xms and Xmx JVM args for running the junit tests.