Tutorial: Creating a WebSphere Commerce service module > < Previous | Next >
Deploying and validating the TutorialStore service module with JUnit
This section refers to deploying and validating the TutorialStore service module with JUnit.
- Add the TutorialStore component to the WCproject:
- Expand Enterprise Applications > WC and double click Deployment Descriptor.
- Select the Module tab.
- Under Modules, click Add, select the TutorialStore-Server, and click Finish.
- Under Modules, click Add, select the TutorialStoreServicesHTTPInterface, and click Finish.
- Refresh the context root for TutorialStoreServicesHTTPInterface by selecting the module in the Modules display and clicking Refresh. The context root should now change to /webapp/wcs/component/tutorialstore.
- Under Project Utility Jars, click Add, select TutorialStore-Client, click Finish.
- Repeat step f for TutorialStore-DataObjects.
- Add a JUnit Test:
- Open the TutorialStore-UnitTests/src/com.mycompany.commerce.tutorialstore.facade.client.TutorialStoreFacadeClientTest class.
- Comment out the testGetTutorialStore() and testProcessTutorialStore() methods.
- Copy and paste the following JUnit test method, replacing myWCAdminID and myWCAdminPassword 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. This method performs the following actions against the TutorialStore service:
- Closes the store.
- Gets the store information.
- Verifies that the store is closed.
- Opens the store.
- Gets the store information.
- Verifies that the store is open.
public void testTutorialStore() { String[] storeID = {"10001"}; ShowTutorialStoreDataAreaType result; TutorialStoreType tutorialStore; BusinessContextType businessContext = CommerceFoundationFactory.eINSTANCE.createBusinessContextType(); // Change username and password to match the server. javax.security.auth.callback.CallbackHandler callbackHandler = new SampleCallbackHandlerImpl(" myWCAdminID", " myWCAdminPassword"); // Create the client facade. TutorialStoreFacadeClient client = new TutorialStoreFacadeClient(businessContext, callbackHandler); // Close the store. client.closeStore(storeID[0]); // Pause while the store registry refreshes. try { Thread.sleep(5000); } catch (Exception e) { } // Verify that the store has been closed by retrieving its current state. result = client.findStoreById(storeID, TutorialStoreFacadeConstants.ACCESS_PROFILE_DETAIL_INFOMATION); tutorialStore = (TutorialStoreType) result.getTutorialStore().get(0); assertEquals("Closed",tutorialStore.getStoreState().getName()); // Open the store. client.openStore(storeID[0]); // Pause while the store registry refreshes. try { Thread.sleep(5000); } catch (Exception e) { } // Verify that the store has been opened by retrieving its current state. result = client.findStoreById(storeID, TutorialStoreFacadeConstants.ACCESS_PROFILE_DETAIL_INFOMATION); tutorialStore = (TutorialStoreType) result.getTutorialStore().get(0); assertEquals("Open", tutorialStore.getStoreState().getName()); }
- Update the TutorialStore-UnitTests build path:
- Right-click the TutorialStore-UnitTests project and select Properties.
- Select Java Build Path.
- Select Add External Jars.
- Add Foundation-Samples.jar from workspace_dir\WC.
- Click OK.
- Organize the imports for the TutorialStore-UnitTests project:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the TutorialStore-UnitTests\src folder and select Source.
- Select Organize Imports.
- 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. 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 Internet > 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, 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:
- Open TutorialStore-UnitTests\src\config\com.mycompany.commerce.tutorialstore\wc-component-client.xml in any text editor.
- Change the value of the url property from "localhost:8007" to "localhost:81".
- Save the file.
- Run the JUnit test:
- Right-click the TutorialStoreFacadeClientTest.java class and select Run.
- Select JUnit Test. You should see the request and response XML documents transmitted between the client and server on the TCP/IP monitor.