Develop > Persistence layer > Work with WebSphere Commerce services


Test a WebSphere Commerce service

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

Within the generated unit test project, one single Test class is also created. This test case extends from the JUnit TestCase class and contains test methods for every service that the service module will support. These test methods build empty service request objects and use the generated client library class to issue 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 executing 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 validates the deployment of the generated projects. The only precondition before running the unit test is to generate the Service Data Objects, which must be done in order to compile the generated pattern assets.

Each unit test project contains a sample configuration in order to talk with the service module remotely or locally. By default, the configuration 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 demonstrating the deployment configuration to local communication and Web service communication 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 the purpose of unit testing, a CallbackHandler implementation has been 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 located in the WC 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 the application authentication mechanism. Alternately, you can use the generated Web services proxy binding.


Before you begin

To test a WebSphere Commerce service, it is recommended that you create unit test code.

To do so:


Procedure

  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 additional validation and when testing services remotely, you can use the TCP monitor within WebSphere Commerce Developer to monitor the SOAP messages exchanged between the unit test and the component facade implementation.


Related concepts

WebSphere Commerce service module

Service Data Objects (SDO)

Client library for WebSphere Commerce services

Component facade interfaces


Related tasks

Create a WebSphere Commerce service module

Generate code from an SDO genmodel file


+

Search Tips   |   Advanced Search