Tutorials > Program model > Web services > Create a WebSphere Commerce service module (SOI) > Creating the Process TutorialStore service

< Previous | Next >


Deploy and validating the TutorialStore service module with JUnit

In this step, you are going to use the generated JUnit test class, TutorialStoreFacadeClientTest, to validate the TutorialStore service module.


Procedure

  1. Update the JUnit test client:

    1. Open the SOITutorialStore-UnitTests/src/com.mycompany.commerce.soitutorialstore.facade.client.SOITutorialStoreFacadeClientTest class.

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

      public void testGetTutorialStore() {
      
      // Create the query expression using an XPath statement and access
      // profile.
      String storeID = "10851";
      
      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();
      }
      }
      
      public void testProcessTutorialStore() {
      
      String[] storeID = { "10851" };
      SOITutorialStoreFactory iFactory = SOITutorialStoreFactory.eINSTANCE;
      
      // Construct the request BOD.
      ProcessTutorialStoreType processTutorialStore = iFactory
      .createProcessTutorialStoreType();
      processTutorialStore.setDataArea(iFactory
      .createProcessTutorialStoreDataAreaType());
      
      // Construct the TutorialStore noun and add it to the request.
      java.util.List TutorialStoreList = processTutorialStore.getDataArea()
      .getTutorialStore();
      TutorialStoreType tutorialstore = iFactory.createTutorialStoreType();
      StoreIdentifierType storeIdentifier = CommerceFoundationFactory.eINSTANCE
      .createStoreIdentifierType();
      storeIdentifier.setUniqueID(storeID[0]);
      tutorialstore.setStoreIdentifier(storeIdentifier);
      TutorialStoreList.add(tutorialstore);
      
      // Verify that the store is open.
      ShowTutorialStoreDataAreaType result = iClient
      .findStoreById(
      storeID, SOITutorialStoreFacadeConstants.ACCESS_PROFILE_DETAILS_INFORMATION);
      TutorialStoreType tutorialStore = (TutorialStoreType) result
      .getTutorialStore().get(0);
      assertEquals(StoreStateType.OPEN, tutorialStore.getStoreState()
      .getValue());
      
      // Construct the open action expression.
      java.util.List actions = new java.util.ArrayList();
      actions.add(AbstractBusinessObjectDocumentFacadeClient
      .createActionExpression(
      SOITutorialStoreFacadeConstants.PROCESS_ACTION_CLOSE, SelectionCriteriaHelper.STR_XPATH_LANG, SOITutorialStoreFacadeConstants.XPATH_STORE));
      com.ibm.commerce.oagis9.datatypes.ProcessType processVerb = AbstractBusinessObjectDocumentFacadeClient
      .createProcessVerb(actions);
      processTutorialStore.getDataArea().setProcess(processVerb);
      
      // send the request BOD and get back the response
      AcknowledgeTutorialStoreType acknowledgeTutorialStore = iClient
      .processTutorialStore(processTutorialStore);
      
      // Pause while the store registry refreshes.
      try {
      Thread.sleep(5000);
      } catch (Exception e) {
      e.printStackTrace();
      }
      
      // Verify that the store is closed.
      result = iClient
      .findStoreById(
      storeID, SOITutorialStoreFacadeConstants.ACCESS_PROFILE_DETAILS_INFORMATION);
      tutorialStore = (TutorialStoreType) result.getTutorialStore().get(0);
      assertEquals(StoreStateType.CLOSED, tutorialStore.getStoreState()
      .getValue());
      
      // Construct the close action expression.
      actions.clear();
      actions.add(AbstractBusinessObjectDocumentFacadeClient
      .createActionExpression(
      SOITutorialStoreFacadeConstants.PROCESS_ACTION_OPEN, SelectionCriteriaHelper.STR_XPATH_LANG, SOITutorialStoreFacadeConstants.XPATH_STORE));
      processVerb = AbstractBusinessObjectDocumentFacadeClient
      .createProcessVerb(actions);
      processTutorialStore.getDataArea().setProcess(processVerb);
      
      // send the request BOD and get back the response
      acknowledgeTutorialStore = iClient
      .processTutorialStore(processTutorialStore);
      
      // Pause while the store registry refreshes.
      try {
      Thread.sleep(5000);
      } catch (Exception e) {
      e.printStackTrace();
      }
      
      // Verify that the store is open.
      result = iClient
      .findStoreById(
      storeID, SOITutorialStoreFacadeConstants.ACCESS_PROFILE_DETAILS_INFORMATION);
      tutorialStore = (TutorialStoreType) result.getTutorialStore().get(0);
      assertEquals(StoreStateType.OPEN, tutorialStore.getStoreState()
      .getValue());
      }
      

    3. Save the SOITutorialStoreFacadeClientTest class.

  2. Organize the imports for the SOITutorialStore-UnitTests project:

    1. Open the Java perspective in WebSphere Commerce Developer.

    2. Right-click the SOITutorialStore-UnitTests\src folder and select Source.

    3. Select Organize Imports.

  3. Start the test server: On the Server page, right-click the WebSphere Commerce Test Server and select Start.

  4. 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 Projects.

    2. Select the WC project.

    3. Click Add and click Finish.

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

  5. 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:

    1. Select Window > Preferences.

    2. From the Preferences panel select 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 SOITutorialStore service is running.

      • Port: 80 for WebSphere Commerce Developer, 8007 for production.

    5. Click OK.

    6. Select the created TCP/IP monitor.

    7. Click Start.

    8. Click OK.

  6. Configure the TutorialStore Unit Test to use the TCP/IP monitor:

    1. Open TutorialStore-UnitTests\src\config\com.mycompany.commerce.tutorialstore\wc-component-client.xml in a text editor.

    2. Change the value of the url property from localhost:8007 to localhost:81.

    3. Save the file.

  7. Run the JUnit test:

    1. Right-click the SOITutorialStoreFacadeClientTest.java class and select Run.

    2. Select JUnit Test. You should see the request and response XML documents transmitted between the client and server on the TCP/IP monitor.

    3. If the validation is successful, a green bar is displayed on the JUnit view.

  8. 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:

    • Process BOD.

    • Acknowledge BOD.

< Previous | Next >


+

Search Tips   |   Advanced Search