Tutorials > Program model > Web services > Create a WebSphere Commerce service module (SOI) > Creating the Get 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. Add a JUnit Test:

    1. Open the SOITutorialStore-UnitTests/src/com.mycompany.commerce.soitutorialstore.facade.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 = "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();
              }
          }
      
          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(
                      "myWCAdminID", "myWCAdminPassword");
      
              // Create the client facade.
              SOITutorialStoreFacadeClient client = new SOITutorialStoreFacadeClient(
                      businessContext, callbackHandler);
      
              // Verify that the store is open.
              ShowTutorialStoreDataAreaType result = client
                      .findStoreById(
                              storeID,                         SOITutorialStoreFacadeConstants.ACCESS_PROFILE_DETAILS_INFORMATION);
              TutorialStoreType tutorialStore = (TutorialStoreType) result
                      .getTutorialStore().get(0);
              assertEquals("Open", tutorialStore.getStoreState().getName());
      
          }
      

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

  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:

    • Get BOD.

    • Show BOD.

< Previous | Next >


+

Search Tips   |   Advanced Search