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
- Import
the provided ProjectFacadeClientTest JUnit Test:
- In the Enterprise Explorer view, expand Project-UnitTests/src right-click the com.mycompany.commerce.project.facade package.
- Click Import. Expand General and select File System. Click Next.
- Browse to the temporary location where you extracted the RecipeServices.zip.
- Browse to the com.mycompany.commerce.Project.facade folder.
- Select ProjectFacadeClientTest.java.
- Click Finish. Click Yes to All to overwrite the existing file.
- Open ProjectFacadeClientTest.java for editing.
- 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. - Search for the comment
// TODO: modify the test storeID
. Replace the number 11301 with the storeId of your store. - Save your changes.
- From the Project menu, select Clean, if Build Automatically is not selected, then select Build Project.
- Organize the imports for the Project-UnitTests
project:
- Open the Java perspective in WebSphere Commerce Developer.
- Expand Project-UnitTests; right-click src and select .
- Save all of the opened files if you have not already done so. From the pull down menu, select
- Start or restart the WebSphere Commerce Test Server.
- Right-click the WebSphere Commerce Test Server and select Publish.
- 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:
- Insert the test data into the
WebSphere Commerce database:
- 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.
- Replace the number 11301 with the storeId you are using.
- Open a new browser window and enter the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp.
- Paste the contents of your text editor into the text box in your browser window.
- Click Submit Query.
- In the Enterprise Explorer view, verify that there are no compilation errors in all projects.
- Run
the JUnit test:
- Expand Project-UnitTests/src/com.mycompany.commerce.project.facade.
- Right-click the ProjectFacadeClientTest.java class and select .
- 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.
- 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.