.
Showing posts with label main. Show all posts
Showing posts with label main. Show all posts

Sunday, January 17, 2016

Newbie Eclipselink/ADF: Testing Your JPA With a Runnable Class

Testing your entities with a runnable class isn't really a problem at all, there are just somethings that can be missed depending on your JPA vendor. In our case, it is Eclipselink.

Assuming we have experience here in making JPA-enabled projects, here is a sample persistence.xml unit:

To test with a main class, we use a RESOURCE_LOCAL transaction type, with the required javax.persistence.jdbc... properties, as seen above. In addition I also included some eclipselink parameters that define logging and performance profiling to help, if not enable at all, testing and debugging efforts.

Oh, make sure to import the Oracle JDBC library (ADF) or another library where it exists if you are to use oracle.jdbc.OracleDriver as your driver.

And then, to make sure that my entities are woven (since we can't make use of dynamic weaving in this context), I open the project properties of where the test class would be placed, and configure its Run/Debug options:


For the Java Options(as encircled above), I add the option -javaagent:, and append the path to my eclipselink.jar. In my case, the resulting option is -javaagent:C:\Oracle\Middleware\Oracle_Home\oracle_common\modules\oracle.toplink_12.1.3\eclipselink.jar.

Now we have added weaving. This enables change tracking, fetch groups, indirection, and some other Eclipselink magic that wouldn't be available otherwise.

After that, we are ready to create our class for (unit) testing!

Here's a sample class that runs a main method, along with some formal transaction demarcation:

An that's it for this post. Hope this helped!