Validating the catalog customization with JUnit

In this lesson, you test your customization with a JUnit validation.

About this task

The JUnit test that is used in this lesson assumes that your store is a starter store with a store ID of 10101 and a catalog ID of 10101. If the ID values for your store are different, ensure that you update the values in the unit test project before you run the unit test.

Procedure

  1. Download the following unit test project to a temporary directory: CatalogExtensions-UnitTests.zip.
  2. Import the downloaded CatalogExtensions-UnitTest project into your workspace.
    1. In IBM WebSphere Commerce Developer, click File > Import.
    2. In the Import wizard, expand General.
    3. Select Existing Projects into Workspace and click Next.
    4. Select the Select archive file option and browse for the CatalogExtensions-UnitTest.zip project that you downloaded.
    5. Select the project and click Open.
    6. In the Import wizard, select the CatalogExtensions-UnitTest project and click Finish.
  3. Add the unit test project JAR file to the Java Build Path for your Unit Test:
    1. In the Enterprise Explorer view, right-click the CatalogExtension-UnitTests project and select Properties.
    2. Select Java Build Path. Click the Libraries tab and select Add External JARs.
    3. Add the following external JAR file projects:
      • WAS_installdir\runtimes\com.ibm.ws.webservices.thinclient_8.5.0.jar
      • WAS_installdir\plugins\org.eclipse.emf.commonj.sdo.jar
      • WAS_installdir\plugins\org.eclipse.emf.ecore.change.jar
      • WAS_installdir\plugins\org.eclipse.emf.ecore.sdo.jar
    4. Click OK to add the projects to the Java Build Path for your Unit Test.
  4. Expand CatalogExtensions-UnitTest > src > com.mycompany.commerce.catalog.facade.client.
  5. Open the CatalogExtensionFacadeClientTest.java file for editing.
  6. Replace the following constants with your environment-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.
  7. Save your changes.
  8. Start the WebSphere Commerce Test Server.
  9. 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.

  10. Set up a TCP/IP Monitor in WebSphere Commerce Developer to observe the document requests to and from the WebSphere Commerce service that you created:
    1. Select Window > Preferences.
    2. From the Preferences page expand Run/Debug. Click 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 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.
  11. 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.

  12. 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.