...
Once you have downloaded and built OpenJPA (see Building), you can run individual tests using the "test" goal to maven. For example:
Code Block |
---|
mvn test -DfailIfNoTests=false -Dtest=TestPersistence |
Note | |||||||
---|---|---|---|---|---|---|---|
By default Maven will fail if there are no testcases found in any module you build. The examples solve this by specifying -DfailIfNoTests=false but you can also change your personal default by adding the following to ${user.home}/.m2/settings.xml :
|
To get more debugging information (e.g., to see the SQL that is being executed against the database), you can enable trace-level logging from the command line using the "openjpa.Log" system property. For example:
Code Block |
---|
$ mvn test -DfailIfNoTests=false -Dtest=TestPersistence -Dopenjpa.Log=DefaultLevel=TRACE
[INFO] Scanning for projects...
[INFO] Reactor build order:
...
690 test TRACE [main] openjpa.jdbc.SQL - <t 4261185, conn 3061987> executing prepstmnt 12659709
INSERT INTO AllFieldTypes (id, arrayOfStrings, booleanField, byteField, charField, dateField,
doubleField, floatField, intField, longField, shortField, stringField)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(long) 601, (null) null, (int) 0, (byte) 0,
(int) 0, (null) null, (double) 0.0, (float) 0.0, (int) 0, (long) 0, (short) 0, (null) null]
701 test TRACE [main] openjpa.jdbc.SQL - <t 4261185, conn 3061987> [11 ms] spent
701 test TRACE [main] openjpa.jdbc.JDBC - <t 4261185, conn 3061987> [0 ms] commit
702 test TRACE [main] openjpa.jdbc.JDBC - <t 4261185, conn 0> [0 ms] close
...
$
|
...
Log levels specify the minimum log message that is output. All log messages with a level higher than the log level set for a logger are output. So if INFO is specified, log messages of level INFO, WARN, ERROR, and SEVERE are output.
- TRACE
- INFO
- WARN
- ERROR
- SEVEREFATAL
For example, to avoid enhancement warnings, get detailed SQL information, and write the log data to a file:
...
By default, OpenJPA uses the Derby database for testing. The openjpa-persistence-jdbc/pom.xml
POM declares various pre-defined databases against which tests can be executed. For example, to test against the stand-alone HSQLDB database, you can run with the "test-hsqldb" profile:
Code Block |
---|
mvn test -DfailIfNoTests=false -Dtest=TestPersistence -Ptest-hsqldb |
For databases that are not in the pre-defined list, you can manually specify connection parameters to use for testing under the "test-custom" profile. You will need to manually provide the driver class and specify all of the connection parameters. For example, to test against Oracle, you might run:
Code Block |
---|
mvn test -DfailIfNoTests=false -Dtest=TestPersistence -Ptest-custom \
-Dopenjpa.custom.driverjar=$(pwd)/drivers/jdbc-oracle-10_2_0_1_0.jar \
-Dopenjpa.custom.driverclass=oracle.jdbc.driver.OracleDriver \
-Dopenjpa.custom.url=jdbc:oracle:thin:@HOST:PORT:DBNAME \
-Dopenjpa.custom.username=USERNAME \
-Dopenjpa.custom.password=PASSWORD
|
...
This profile can then be executed by running:
Code Block |
---|
mvn test -DfailIfNoTests=false -Dtest=TestPersistence -Ptest-custom,test-oracle |
Running JUnits in Eclipse
You'll probably want to setup a Debug Configuration in Eclipse for running the JUnit testcases.
- Run --> Debug Configurations... Create a new JUnit configuration
- For the Test tab - Give the configuration a Name, select a Project and Test class, and you'll probably want to select the "Keep JUnit running..." option.
- For the Arguments tab - Press the Variables... button. This will allow us to define variables that can be shared across other Release/Debug Configurations within this workspace.
- For the Select Variable window - Press the Edit Variables... button.
- For the Preferences windows - Press New... to add two variables.
Code Block Name = openjpa.trace Value = -Dopenjpa.Log=DefaultLevel=TRACE Description = Set OpenJPA logging to TRACE
Code Block Name = connect.derby Value = -Dopenjpa.ConnectionDriverName=org.apache.derby.jdbc.EmbeddedDriver -Dopenjpa.ConnectionURL=jdbc:derby:target/database/openjpa-derby-database;create=true Description = Connection properties for Derby
- After the above are created and saved, add the new variables as VM Arguments.
Code Block ${openjpa.trace} ${connect.derby}