Home > Development, Testing > How to test your OpenDJ plugin

How to test your OpenDJ plugin

A problem you might face while extending the OpenDJ functionality with a plugin is to develop proper unit tests. OpenDJ comes with a set of tools to facilitate the testing, but since they are tightly integrated within the build framework, you might find it difficult to execute your unit tests from outside of the framework. This article will try to give you short guidelines on how to integrate and execute your tests.

The test

OpenDJ inherited it’s framework from the OpenDS days which means the old documentation still provides valid guidelines and tips on how to get started with your own unit tests. It would help you get familiar with the utility classes you can use to make your test execution easier. The most relevant documents are:

Of course, if you are not already familiar with TestNG, it is the right moment to get to know it better.
Apart from the documentation mentioned above, you will find it very useful to examine some of the existing unit test classes:

The environment

Before you start working on your tests, you have to check out the OpenDJ source file tree. Say, you are developing a plugin for the 2.4 branch, so you would need the latest stable release:

mkdir opendj-dev
cd opendj-dev
svn co https://svn.forgerock.org/opendj/branches/b2.4/
cd b2.4

Now, your tests should go to:  ‘tests/unit-testing/src/server/<package>/<unit test Java class>’ where:

  • <package> is the package which your plugin belongs to, and
  • <unit test Java class> is the Java class that implements the unit test(s).

For example, let’s assume we have a plugin called ‘example plugin’ and we made put it in the ‘com.example.plugins’ package (‘com.example.pluginsExamplePlugin). The path would be, say: ‘tests/unit-testing/src/server/com/example/plugins/ExamplePluginTestCase.java’.

Given that your plugin is built separately from the OpenDJ sources, and that the execution of the unit test requires OpenDJ server to be running, you have to make your plugin available to the built-in test instance (and not just the plugin, but also all the libraries you plugin depends on, schema files, etc.). For that to work you need to do the following:

  • create a directory: ‘lib/extensions’;
  • copy your plugin JAR (and the dependencies) to the following locations: ‘lib’ and ‘lib/extensions’;
  • copy your schema file to: ‘resources/schema’.

You should be ready to execute your tests using:

./build.sh test -Dtest.classes=<your unit test>

If we take our ‘example plugin’, you would do the following:

# let’s assume you are located in opendj-dev/b2.4

mkdir lib/extensions

cp <path to>/example-plugin.jar lib

cp <path to>/example-plugin.jar lib/extensions

cp <path to>/99-example-plugin.ldif resources/schema

./build.sh test -Dtest.classes=com.example.plugins.ExamplePluginTestCase

Testing and Maven

As previously mentioned, the testing framework of OpenDJ is very tightly integrated with the build process and makes it unavailable to the other frameworks and tools such as Maven.  If you have chosen Maven to develop your plugin, you will not be able to execute unit tests using OpenDJ tools and the workaround is to follow the guide above 🙂

Advertisements
Categories: Development, Testing Tags: , , , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: