Validating the Project service module with JUnit

After you apply the HCL 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.

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 HCL 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 Build Project if Build Automatically is not selected.
  2. Organize the imports for the Project-UnitTests project:
    1. Open the Java perspective in HCL Commerce Developer.
    2. Expand Project-UnitTests. Right-click src and select Source > Organize Imports.
    3. Save all of the opened files. Select File > Save All.
  3. Update the JAR dependencies for the HCL Commerce applications and Eclipse Modeling Framework to the build path for the unit test project.
    1. Right-click Project-UnitTests.
    2. Select Build Path > Configure Build Path.
    3. On the Libraries tab, within the list of JARs and class folders on the build path, select the WebSphere Application Server v8.5 [HCL Commerce Runtime]. Then, click Remove.
    4. Click Add JARs.
    5. In the JAR selection list, select the following JAR files. Then, click OK.
      • Search-eardir/lib/commons-logging-1.2.jar
      • WC/lib/commons-logging.jar
    6. Click Add External JARs.
    7. Browse to the WAS_installdir\runtimes directory and select the com.ibm.ws.webservices.thinclient_9.0.jar JAR file.
    8. Click Open to add the JAR to the build path.
    9. Repeat steps 3.f to 3.h to add the following JAR files that are within the WAS_installdir\plugins\ directory to the project build path.
      • org.eclipse.emf.common.jar
      • org.eclipse.emf.commonj.sdo.jar
      • org.eclipse.emf.ecore.change.jar
      • org.eclipse.emf.ecore.jar
      • org.eclipse.emf.ecore.sdo.jar
      • org.eclipse.emf.ecore.xmi.jar
      Note: You can use multi-select to add multiple JAR files to the library rather than adding the files individually.
    10. On the Libraries tab, click OK.
  4. Start or restart the HCL Commerce Test Server.
  5. Right-click the HCL Commerce Test Server and select Publish.
  6. Set up a TCP/IP Monitor in HCL Commerce Developer. Use this TCP/IP Monitor to observe the request and response documents that travel to and from the HCL Commerce service you created.
    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 HCL Commerce Server where the Project service is running.
      • Port:80 for HCL Commerce Developer, 8007 for production
    5. Click OK.
    6. Select the created TCP/IP Monitor.
    7. Click Start.
    8. Click OK.
  7. Insert the test data into the HCL Commerce database:
    1. Navigate to the temporary location where you extracted the RecipeServices.zip file, and in the RecipeServices/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 input text box in your browser window.
    5. Click Submit Query.
  8. In the Enterprise Explorer view, verify that your projects have no compilation errors.
  9. 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. Review the JUnit test view and TCP/IP Monitor.
      • In the TCP/IP Monitor, the request and response BOD XML documents that are transmitted between the client and server display if the test is successful.
      • In the JUnit test view, a green bar displays when the test is successful.
      You can also click the Console tab to view a message that indicates that the test case passed.