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
- Download the following unit test project to a temporary directory: CatalogExtensions-UnitTests.zip.
- Import the CatalogExtensions-UnitTest project
into your workspace:
- Select one of the following paths:
- File > Import > Other > Project Interchange > Next.
- File > Import > General > Existing Projects into Workspace > Next.
- Browse for the file you downloaded to import it into
your project:
- Look for the From zip file label, click Browse and select the CatalogExtensions-UnitTest.zip
- Look for the Select archive file label, click Browse and select the CatalogExtensions-UnitTest.zip
- Click Open.
- Select the CatalogExtensions-UnitTest project.
- Click Finish.
- Select one of the following paths:
- Add the com.ibm.ws.webservices.thinclient_7.0.0.jar unit
test project to the Java Build Path for your Unit Test:
- In the Enterprise Explorer view, right-click CatalogExtension-UnitTests; select Properties.
- Select Java Build Path. Click the Libraries tab and select Add External JARs.
- Browse to SDP\runtimes\base_v7\runtimes where SDP is your Rational Application Developer installation directory.
- Select the com.ibm.ws.webservices.thinclient_7.0.0.jar unit test project. Click Open.
- Click OK to add the project to the Java Build Path for your Unit Test.
- In the Enterprise Explorer view, expand CatalogExtensions-UnitTest > src > com.mycompany.commerce.catalog.facade.client and open CatalogExtensionFacadeClientTest.java.
- 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.
- In the Server view, right-click the WebSphere Commerce Test Server and select Start.
- If the WC project is not already published
to the WebSphere Commerce Test Server, publish the WebSphere Commerce
project:
- On the Server page, right-click the WebSphere Commerce Test Server and select Add and Remove.
- Select the WC project.
- Click Add.
- Click Finish.
If the WC project is already published, right-click the WebSphere Commerce Test Server and select Publish.
- Set up a TCP/IP Monitor in WebSphere
Commerce Developer to observe the document requests to and from the
WebSphere Commerce service you created:
- Select Window > Preferences.
- From the Preferences page click Run/Debug > TCP/IP Monitor.
- Click Add.
- 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
- Click OK.
- Select the created TCP/IP Monitor.
- Click Start.
- Click OK.
- 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.
- 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.