Validating the catalog customization with JUnit

This step demonstrates how to test your customization with JUnit. This test assumes a starter store with a store ID of 10101 and a catalog ID of 10101 is published to your WebSphere Commerce Development environment.

Procedure

  1. Download the following unit test project to a temporary directory: CatalogExtensions-UnitTests.zip.
  2. Import the CatalogExtensions-UnitTest project into your workspace:
    1. Select one of the following paths:
      • Feature Pack 4Feature Pack 2Feature Pack 5Feature Pack 3Feature Pack 1File > Import > Other > Project Interchange > Next.
      • Feature Pack 6 or laterFile > Import > General > Existing Projects into Workspace > Next.
    2. Browse for the file you downloaded to import it into your project:
      • Feature Pack 4Feature Pack 2Feature Pack 5Feature Pack 3Feature Pack 1Look for the From zip file label, click Browse and select the CatalogExtensions-UnitTest.zip
      • Feature Pack 6 or laterLook for the Select archive file label, click Browse and select the CatalogExtensions-UnitTest.zip
    3. Click Open.
    4. Select the CatalogExtensions-UnitTest project.
    5. Click Finish.
  3. Add the com.ibm.ws.webservices.thinclient_7.0.0.jar unit test project to the Java Build Path for your Unit Test:
    1. In the Enterprise Explorer view, right-click CatalogExtension-UnitTests; select Properties.
    2. Select Java Build Path. Click the Libraries tab and select Add External JARs.
    3. Browse to SDP\runtimes\base_v7\runtimes where SDP is your Rational Application Developer installation directory.
    4. Select the com.ibm.ws.webservices.thinclient_7.0.0.jar unit test project. Click Open.
    5. Click OK to add the project to the Java Build Path for your Unit Test.
  4. In the Enterprise Explorer view, expand CatalogExtensions-UnitTest > src > com.mycompany.commerce.catalog.facade.client and open CatalogExtensionFacadeClientTest.java.
  5. Replace the following constants with their machine-specific values:
    • USER_ID = An administrator user ID on your WebSphere Commerce server.
    • PASSWORD = The password to the administrator ID.
    • STORE_ID = The store ID of the published starter store.
    • CATALOG_ID = The catalog ID of the published starter store.
    • catEntryId = The catalog entry ID of a catalog entry in your published starter store that you identified in earlier lessons.
    Save your changes and close the file.
  6. In the Server view, right-click the WebSphere Commerce Test Server and select Start.
  7. If the WC project is not already published to the WebSphere Commerce Test Server, publish the WebSphere Commerce project:
    1. On the Server page, right-click the WebSphere Commerce Test Server and select Add and Remove.
    2. Select the WC project.
    3. Click Add.
    4. Click Finish.

    If the WC project is already published, right-click the WebSphere Commerce Test Server and select Publish.

  8. Set up a TCP/IP Monitor in WebSphere Commerce Developer to observe the document requests to and from the WebSphere Commerce service you created:
    1. Select Window > Preferences.
    2. From the Preferences page click 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 TutorialStore service is running.
      Port
      80 for WebSphere Commerce Developer
    5. Click OK.
    6. Select the created TCP/IP Monitor.
    7. Click Start.
    8. Click OK.
  9. Right-click the CatalogExtensionFacadeClientTest.java class and select Run As > JUnit Test.
    Note: Running the JUnit test multiple times causes it to fail on the second run because the test updates the row it retrieves. The warterm = 30 assertion fails.

    You can observe the request and response XML documents that are transmitted between the client and server on the TCP/IP Monitor.

  10. Verify the results:
    • This test performs a Get request to retrieve a CatalogEntry noun that includes the warranty and care instruction data.
    • The Get request uses the XPath key of /CatalogEntry[CatalogEntryIdentifier[(UniqueID=)]] and the MyCompany_All access profile that is defined in step 3.
    • The data service layer uses the XPath key and access profile to identify the SQL query template to run against the database and populate physical data objects with the results.
    • The business object mediator transforms the physical data objects into logical nouns. This process populates warranty information into the CatalogEntry noun UserData element and populates care instructions into the Catalog description noun part's attributes element.