Cayenne provides a comprehensive suite of unit tests. To execute unit tests you must first get Cayenne from SVN, install JDK 1.5 and obtain the latest Maven.

Prerequisites

On some systems (e.g. Ubuntu 8.x) the following line needs to be placed in "~/.mavenrc" or otherwise there will be test failures in the unit tests relying on JGroups. This is a workaround of a known JVM bug:

MAVEN_OPTS="-Djava.net.preferIPv4Stack=true"

Running Against Embedded HSQLDB

No extra setup is required. Just run Maven:

$ cd cayenne
$ mvn install

or

$ cd cayenne
$ mvn clean test

Running Against a Specific Database

Step 1. Install JDBC Driver Jars in a Local Maven Repo

Most commercial drivers are not present in the public Maven repositories. So they have to be installed by the tester locally. The group and artifact ids are arbitrarily assigned in the main Cayenne POM, so users must follow the POM or the examples below.

FrontBase:

$ mvn install:install-file -Dfile=frontbasejdbc.jar -DgroupId=com.frontbase \
       -DartifactId=frontbase-driver -Dversion=4.1 -Dpackaging=jar -DgeneratePom=true

OpenBase:

$ mvn install:install-file -Dfile=OpenBaseJDBC.jar -DgroupId=com.openbase \
       -DartifactId=openbase-driver -Dversion=9 -Dpackaging=jar -DgeneratePom=true

Oracle:

$ mvn install:install-file -Dfile=ojdbc5.jar -DgroupId=com.oracle \
       -DartifactId=oracle-driver -Dversion=11 -Dpackaging=jar -DgeneratePom=true

SQLite:

$ mvn install:install-file -Dfile=sqlitejdbc-v056.jar -DgroupId=org.sqlite \
       -DartifactId=sqlite-driver -Dversion=0.56 -Dpackaging=jar -DgeneratePom=true

SQLServer:

$ mvn install:install-file -Dfile=sqljdbc.jar -DgroupId=com.microsoft \
       -DartifactId=sqlserver-driver -Dversion=2.0 -Dpackaging=jar -DgeneratePom=true

Sybase:

$ mvn install:install-file -Dfile=jconn3.jar -DgroupId=com.sybase \
       -DartifactId=sybase-driver -Dversion=12 -Dpackaging=jar -DgeneratePom=true

Step 2. Run Tests Against Configured Data Source

Database type and connection information can be specified either on the command line or via a configuration file. First let's look at the command line options:

$ mvn test -DcayenneTestConnection=<profile_name> \
   -DcayenneAdapter=org.apache.cayenne.dba.mysql.MySQLAdapter \
   -DcayenneJdbcUsername=myuser \
   -DcayenneJdbcPassword=mypassword \
   -DcayenneJdbcUrl=jdbc:mysql://localhost/cayenne \
   -DcayenneJdbcDriver=com.mysql.jdbc.Driver

cayenneTestConnection is a property activating a DB-specific Maven profile. <profile_name> can be one of:

  • derby
  • h2
  • frontbase
  • mysql
  • openbase
  • oracle
  • postgres
  • sqlite
  • sqlserver
  • sybase

Another way to store this information permanently for each profile is to create a directory $HOME/.cayenne/ and place a file called connection.properties in this directory. File contents should be similar to this example:

mysql.cayenne.adapter = org.apache.cayenne.dba.mysql.MySQLAdapter
mysql.jdbc.username = someuser
mysql.jdbc.password = somepasswd
mysql.jdbc.url = jdbc:someurl1
mysql.jdbc.driver = com.xyz.MyDriverClass

oracle.cayenne.adapter = org.apache.cayenne.dba.oracle.OracleAdapter
oracle.jdbc.username = someuser
oracle.jdbc.password = somepasswd
oracle.jdbc.url = jdbc:someurl2
oracle.jdbc.driver = com.xyz.MyDriverClass

Each property starts with the Maven profile name ("mysql" and "oracle" in the example above). Note that in this case you should still use cayenneTestConnection. E.g.:

$ mvn test -DcayenneTestConnection=derby
If you are testing Cayenne 3.0, use -Dcayenne.test.connection instead of -DcayenneTestConnection. Also it is only possible to pass the DB properties via "connection.properties" file, and not possible to pass them on command line

Look at test results

To look for failed tests, grep the output files.

$ grep FAIL framework/cayenne-jdk1.5-unpublished/target/surefire-reports/*.txt