Testing an HCL Commerce service with a unit test case

After you apply the HCL Commerce service module pattern, a MyServiceModule-UnitTest project is created as a place to put JUnit tests for the created services. JUnit is a simple and commonly used Java testing framework for unit tests. For more information about JUnit, see http://www.junit.org.

Before you begin

About this task

Within the generated unit test project, a single test class is created. This test case extends from the JUnit TestCase class and contains test methods for every service that the service module supports. These test methods build empty service request objects and use the generated client library class to send the web service request and receive the service response.

The purpose of these generated test methods is to help validate the deployment of the generated pattern assets. By running the test class without any modifications of the existing service logic, the test case should send and receive empty service messages. When the test runs successfully, this unit test validates the deployment of the generated projects. The only precondition before you run the unit test is that you generate the Service Data Objects, which you must do to compile the generated pattern assets.

Each unit test project contains a sample configuration to communicate with the service module remotely or locally. By default, the configuration that is used by the test case is a web service in a J2SE environment, on the same machine where the test case is run. In the same directory, there is another sample configuration for demonstrating the deployment configuration to local communication and web service communication by using the generated JAX-RPC mapping code.

The main goal of unit testing is to individually test the service messages to ensure that the request is processed as designed. Unit tests should test only particular service request messages and do not need to test a functional flow of messages. Test cases should be created to test individual service requests.

For unit testing, a CallbackHandler implementation is created where the user identity and password can be specified so the service is invoked under that identity. This CallbackHandler can be found in the Foundation-Samples.jar in the HCL Commerce project. This JAR file is only part of the development environment and is only intended for unit test purposes. The class is com.ibm.commerce.foundation.client.samples.security.auth.callback.SampleCallbackHandlerImpl. The constructor accepts the user ID and password of the identity under which to run the service.

In production, create a CallbackHandler implementation that supports your application authentication mechanism. Alternately, you can use the generated web services proxy binding.


  1. Open the MyServiceModule-UnitTests project.
  2. Inside the project is a template JUnit test case class. Edit this class to create new test methods to unit test the component facade implementation.
  3. Optional: For extra validation when testing services, you can use the TCP/IP Monitor within HCL Commerce Developer. You can use the TCP/IP Monitor to monitor the SOAP messages that are exchanged between the unit test and the component facade implementation.


For a tutorial that includes an example of how to test an HCL Commerce service module with both a JUnit test case and the TCP/IP Monitor in HCL Commerce Developer, see ../../tutorials/concepts/cwvstoresoitree.html.