Tutorials > Program model > Web services > Create a new WebSphere Commerce BOD service module
Deploy and validating the TutorialStore service module with JUnit
After applying the WebSphere Commerce service module pattern, a BODTutorialStore-UnitTests project is created as a place to put JUnit tests for services created.
Within the generated unit test project, one single Test class, BODTutorialStoreFacadeClientTest, is also created. This test class 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.
In this section of the tutorial, you are going to use the provided JUnit test class, BODTutorialStoreFacadeClientTest, to validate the TutorialStore service module. This case will perform the following actions:
- Closes store 10001.
- Finds a store using store ID 10001 and the MyCompany_Summary access profile.
- Verifies that store 10001 is closed.
- Opens store 10001.
- Finds a store using store ID 10001 and the MyCompany_Summary access profile.
- Verifies that store 10001 is open.
- Changes store 10001 description to This is the updated store description.
- Finds a store using the store's name and the MyCompany_Details access profile.
- Verifies that the store's description has changed.
The following diagram shows how using JUnit to drive testing through the client library fits into the overall customization process:
Procedure
- Import the provided BODTutorialStoreFacadeClientTest JUnit Test:
- In the Enterprise Explorer view, right-click the BODTutorialStore- UnitTest/src/com.mycompany.commerce.tutorialstore.facade.client package.
- Select Import > FileSystem. Click Next.
- Browse to the temporary location where you unzipped TutorialStore.zip.
- Browse to the BODTutorialStore-UnitTest\src\com.mycompany.commerce.tutorialstore.facade.client folder.
- Select BODTutorialStoreFacadeClientTest.java.
- Click Finish. Click Yes to All to overwrite the existing file.
- Inside the testTutorialStore method, look for the comment // TODO Change the username and password to match the server. Update the WebSphere Commerce Administrator user name and password in the class to match the server.
- Save the changes.
- Organize the imports for the BODTutorialStore-UnitTests project:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the BODTutorialStore-UnitTests\src folder and select Source.
- Select Organize Imports.
- Save all of the opened files if you have not already done so. From the pull down menu, select File > Save All.
- Start the test server: On the Server page, right-click the WebSphere Commerce Test Server and select Start.
- If the WC project is not already published to the WebSphere Commerce Test Server, publish the WebSphere Commerce project:
- On the Server page, right-click the WebSphere Commerce Test Server and select Add and Remove Projects.
- Select the WC project.
- Click Add. Click Finish.
If the WC project is already published, right-click the WebSphere Commerce Test Server and select Publish.
- Set up a TCP/IP monitor in WebSphere Commerce Developer. You will use this TCP/IP monitor to observe the request and response documents going to and from the WebSphere Commerce service you created. To create a TCP/IP Monitor to forward requests to WebSphere Commerce:
- Select Window > Preferences.
- From the Preferences panel select Run/Debug > TCP/IP Monitor.
- Click Add.
- Type the following information:
- Local monitoring port:81.
- Hostname: The hostname of the WebSphere Commerce Server where the TutorialStore service is running.
- Port:80 for WebSphere Commerce Developer, 8007 for production
- Click OK.
- Select the created TCP/IP monitor.
- Click Start.
- Click OK.
- Run the JUnit test:
- Right-click the BODTutorialStoreFacadeClientTest.java class and select Run.
- Select JUnit Test. You should see the request and response XML documents transmitted between the client and server on the TCP/IP monitor.
- If the validation is successful, we will see a green bar on the JUnit view.
If you receive an error message, ensure that you set the JNDI - CMP Connection Factory Binding property of the BODTutorialStore-Server module (ejb-jar.xml).
From the TCP/IP Monitor, you can review the request and response BOD messages sent between the client and server as part of the test.