Validating the Project service module with JUnit

After applying the WebSphere Commerce service module pattern, a Project-UnitTests project is created as a place to put JUnit tests for the services that you created.

About this task

Within the generated unit test project, one single Test class, ProjectFacadeClientTest, is also created. This test class 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 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, ProjectFacadeClientTest, to validate your Project service module.

Procedure

  1. Import the provided ProjectFacadeClientTest JUnit Test:
    1. In the Enterprise Explorer view, expand Project-UnitTests/src right-click the com.mycompany.commerce.project.facade package.
    2. Click Import. Expand General and select File System. Click Next.
    3. Browse to the temporary location where you extracted the RecipeServices.zip.
    4. Browse to the com.mycompany.commerce.Project.facade folder.
    5. Select ProjectFacadeClientTest.java.
    6. Click Finish. Click Yes to All to overwrite the existing file.
    7. Open ProjectFacadeClientTest.java for editing.
    8. Search for the comment // TODO Change the username and password to match the server. Update the WebSphere Commerce Site Administrator user name and password in the class to match your server.
    9. Search for the comment // TODO: modify the test storeID. Replace the number 11301 with the storeId of your store.
    10. Save your changes.
    11. From the Project menu, select Clean, if Build Automatically is not selected, then select Build Project.
  2. Organize the imports for the Project-UnitTests project:
    1. Open the Java perspective in WebSphere Commerce Developer.
    2. Expand Project-UnitTests; right-click src and select Source > Organize Imports.
    3. Save all of the opened files if you have not already done so. From the pull down menu, select File > Save All.
  3. Start or restart the WebSphere Commerce Test Server.
  4. Right-click the WebSphere Commerce Test Server and select Publish.
  5. Set up a TCP/IP Monitor in WebSphere Commerce Developer. You use this TCP/IP Monitor to observe the request and response documents traveling to and from the WebSphere Commerce service you created. To create a TCP/IP Monitor to forward requests to WebSphere Commerce:
    1. Select Window > Preferences.
    2. From the Preferences panel, expand Run/Debug > TCP/IP Monitor.
    3. Click Add.
    4. Type the following information:
      • Local monitoring port:81.
      • Hostname: The hostname of the WebSphere Commerce Server where the Project service is running.
      • Port:80 for WebSphere Commerce Developer, 8007 for production
    5. Click OK.
    6. Select the created TCP/IP Monitor.
    7. Click Start.
    8. Click OK.
  6. Insert the test data into the WebSphere Commerce database:
    1. Navigate to the temporary location where you extracted the RecipeServices.zip file, and in the data folder, open the data.txt file in a text editor.
    2. Replace the number 11301 with the storeId you are using.
    3. Open a new browser window and enter the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp.
    4. Paste the contents of your text editor into the text box in your browser window.
    5. Click Submit Query.
  7. In the Enterprise Explorer view, verify that there are no compilation errors in all projects.
  8. Run the JUnit test:
    1. Expand Project-UnitTests/src/com.mycompany.commerce.project.facade.
    2. Right-click the ProjectFacadeClientTest.java class and select Run As > JUnit Test.
    3. The JUnit Test is running. You should see the request and response XML documents transmitted between the client and server on the TCP/IP Monitor.
    4. If the validation is successful, you will see a green bar on the JUnit view. You can also click the Console tab where a message indicates that the test case has passed.

Results

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.