Deploying and validating the TutorialStore Web service module with JUnit
In this step, you use the generated JUnit test class, TutorialStoreFacadeClientTest, to validate your TutorialStore Web service module.
Procedure
- Add a JUnit Test:
- Go to SOITutorialStore-UnitTests/src/com.mycompany.commerce.soitutorialstore.facade .
- Open the SOITutorialStoreFacadeClientTest class.
- Replace the method testGetTutorialStore() with the
following JUnit test method. Replace user and password
with your WebSphere Commerce administrator ID and password. This method
assumes that a WebSphere Commerce store with storeID of 10001 exists
and is currently open. If this is not the case, replace "10001" with
your WebSphere Commerce storeID.
public void testGetTutorialStore() { // Create the query expression using an XPath statement and access profile. String storeID = "10001"; SelectionCriteriaHelper selectionCriteriaHelper = new SelectionCriteriaHelper( "/TutorialStore/TutorialStoreIdentifier[(UniqueID=" + storeID + ")]"); selectionCriteriaHelper.addAccessProfile("MyCompany_Summary"); ExpressionType queryExpression = selectionCriteriaHelper.getSelectionCriteriaExpression(); // Create the Get BOD from query expression and send it to the server. try { ShowTutorialStoreDataAreaType result = iClient.getTutorialStore(iClient.createGetVerb(queryExpression)); TutorialStoreType tutorialStore = (TutorialStoreType) result.getTutorialStore().get(0); assertEquals(storeID, tutorialStore.getStoreIdentifier().getUniqueID()); } catch (TutorialStoreException e) { e.printStackTrace(); fail(e.toString()); } }
public void testTutorialStore() { String[] storeID = { "10001" }; BusinessContextType businessContext = CommerceFoundationFactory.eINSTANCE.createBusinessContextType(); // Change username and password to match the server. javax.security.auth.callback.CallbackHandler callbackHandler = new SampleCallbackHandlerImpl( "user", "password"); // Create the client facade. SOITutorialStoreFacadeClient client = new SOITutorialStoreFacadeClient( businessContext, callbackHandler); // Verify that the store is open. try { ShowTutorialStoreDataAreaType result = client.findStoreById(storeID, SOITutorialStoreFacadeConstants.ACCESS_PROFILE_DETAILS_INFORMATION); TutorialStoreType tutorialStore = (TutorialStoreType) result.getTutorialStore().get(0); assertEquals("Open", tutorialStore.getStoreState().getName()); } catch (TutorialStoreException e) { e.printStackTrace(); fail(e.toString()); } }
- Save your changes and close the file.
- Organize the imports for the SOITutorialStore-UnitTests
project:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the SOITutorialStore-UnitTests\src folder.
- Select Source > Organize Imports .
- Reminder to build all projects before deploying. Start the test server: On the Server page, 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 Projects .
- Select the WC project.
- Click Add and 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.
You will use this TCP/IP monitor to observe the request and response
documents going to and from the WebSphere Commerce service you created.
To create a TCP/IP Monitor to forward requests to WebSphere Commerce:
- Select Window > Preferences .
- From the Preferences panel select 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 SOITutorialStore service is running.
- Port: 80 for WebSphere Commerce Developer, 8007 for production.
- Click OK .
- Select the created TCP/IP monitor.
- Click Start .
- Click OK .
- Configure the TutorialStore Unit Test to use the TCP/IP
monitor:
- Go to SOITutorialStore-UnitTests\src\config\com.mycompany.commerce.soitutorialstore
- Open wc-component-client.xml in a text editor.
- Change the value of the url property from localhost:8007 to localhost:81 .
- Save the file.
- Run the JUnit test:
- Go to SOITutorialStore-UnitTests/src/com.mycompany.commerce.soitutorialstore.facade
- Right-click the SOITutorialStoreFacadeClientTest.java class and select Run as > JUnit Test . 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, a green bar is displayed on the JUnit view.
- From the TCP/IP Monitor, you can review the Get message
sent by the client library, and the Show response replied by the component
facade.The following BODs are present:
- Get BOD.
- Show BOD.