◂ Back to Profiq blog

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:

http://sources.forgerock.org/browse/opendj/trunk/opends/tests/unit-tests-testng/src/server/org/opends/server/plugins

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 :)

Nemanja Lukic

Written by

Nemanja Lukic

Comments

Leave a Reply

Online comments are not active during the static migration phase.
AI Function Blog Image

Is The Most Valuable AI Function Asking Better Questions?

How the "Grill Me" method became a key part of Project Weaver's approach to AI-assisted software development. We've shared some of the thinking behind Project Weaver—the internal engineering framework we've developed at profiq to help our teams and AI work together more effectively. Rather than treating AI as a magic code generator, Weaver is built around a simple idea: the better the structure, context, and engineering discipline, the better the outcomes.

Posted 4 weeks ago by Anke Corbin

Weaver Prototype Image

From Vibe-Coded Prototype to Production-Ready App Using Weaver

There's an important distinction between a prototype that demonstrates an idea and a system that can support a real business. Recently, we had the opportunity to explore that distinction firsthand while working with Ginger & Nash on an application called c.h.i.p. using profiq Weaver as an AI assistant.

Posted 5 weeks ago by Anke Corbin

Project Weaver Recap

Quick Recap: Project Weaver Engineering Series

We wanted to do another quick recap of the Weaver journey so far for those of you who are just learning about the project, from the first idea through the latest automation and workflow experiments.

Posted 2 months ago by Anke Corbin

Read the Blog