Tutorials > Program model > Web services > Customize Web services and WebSphere Portal to support a new search

< Previous | Next >


Test the new fetch command

There are many ways to consume the new fetch command. In this step it is tested as part of a JUnit test in the Rational Application Developer environment.


Procedure

  1. Create a project called SampleTest:

    1. Click File > New Project

    2. Select Java > Java Project

    3. Click Next.

    4. In the Project Name field type SampleTest.

    5. Under Project layout, select Create seperate source and output folders.

    6. Click Finish.

  2. Open the SampleTest project.

  3. Right-click the src folder.

  4. Select New > Package.

  5. In the Package Name field type com.ibm.commerce.catalog.facade.client.

  6. Click Finish.

  7. Right-click the src folder.

  8. Select New > Package. In the Package name field type config.

  9. Click Finish.

  10. The SampleTest.java class contains the code which runs the JUnit test to execute the new fetch command. Create the unit test case:

    1. Right-click the com.ibm.commerce.catalog.facade.client package.

    2. Select New > Class. In the Class Name field type SampleTest. Click Finish.

    3. Add the following to the development environment and replace "username" and "password" in the code with WebSphere Commerce Administrator user name and password. Also, "desk" is specified as the search criteria. If the catalog does not contain desks, replace "desk" with another search term. Replace the contents with the following code:

      package com.ibm.commerce.catalog.facade.client;
      
      /*
       *-------------------------------------------------------------------
       * Licensed Materials - Property of IBM
       *
       * WebSphere Commerce  *
       * (c) Copyright International Business Machines Corporation.
       *     2006
       *     All rights reserved.
       *
       * US Government Users Restricted Rights - Use, duplication or
       * disclosure restricted by GSA ADP Schedule Contract with IBM
      Corp.
       *-------------------------------------------------------------------
       */
      
       /*---------------------------------------------------------------------
       * The sample contained herein is provided to you "AS IS".
       *
       * It is furnished by IBM as a simple example and has not been  
       * thoroughly tested under all conditions.  IBM, therefore, cannot
       * guarantee its reliability, serviceability or functionality.  
       *
       * This sample may include the names of individuals, companies, brands 
       * and products in order to illustrate concepts as completely as 
       * possible.  All of these names are fictitious and any similarity
       * to the names and addresses used by actual persons or business
       * enterprises is entirely coincidental.
       *---------------------------------------------------------------------
       */
      
      
      import
      com.ibm.commerce.foundation.common.datatypes.CommerceFoundationFactory;
      import
      com.ibm.commerce.foundation.common.datatypes.ContextDataType;
      import junit.framework.TestCase;
      import java.util.List;
      import javax.security.auth.callback.CallbackHandler;
      import
      com.ibm.commerce.catalog.facade.client.CatalogEntryFacadeClient;
      import
      com.ibm.commerce.foundation.client.samples.security.auth.callback.SampleCallbackHandlerImpl;
      import
      com.ibm.commerce.foundation.client.util.oagis.SelectionCriteriaHelper;
      import
      com.ibm.commerce.foundation.common.datatypes.BusinessContextType;
      
      public class SampleTest extends TestCase{
              
              private BusinessContextType businessContext = null;
          
          private CallbackHandler iCallbackHandler = null;
          
          private static final java.util.logging.Logger LOGGER =
      com.ibm.commerce.foundation.common.util.logging.LoggingHelper.getLogger(CatalogEntryFacadeClient.class);
         
          private static final String CLASSNAME =
      SampleTest.class.getName();
          
          /**
               * The mapping key for details access profile used in
      Compose Catalog Entries
               */
              public static final String
      CATALOG_ENTRY_ACCESS_PROFILE_DETAILS_KEY =
      "WC_CatalogEntryDetailsProfile";
              
              public SampleTest(String methodName) {
              super(methodName);
          }
      
              
       /*This is the setup method that is run at the beginning of a JUnit
      test. This method will inject values into the command context, such
      as user id and user password*/
              protected void setUp() throws Exception {
              super.setUp();
              
              iCallbackHandler = new
      SampleCallbackHandlerImpl("username", "password");
              businessContext =
      CommerceFoundationFactory.eINSTANCE.createBusinessContextType();
              ContextDataType storeId =
      CommerceFoundationFactory.eINSTANCE.createContextDataType();
              storeId.setName("storeId");
              storeId.setValue("10001");
              businessContext.getContextData().add(storeId);
              ContextDataType catalogID =
      CommerceFoundationFactory.eINSTANCE.createContextDataType();
              catalogID.setName("catalogId");
              catalogID.setValue("10001");
              businessContext.getContextData().add(catalogID);
          }
              
              
              
              
      
      /*This is the test method that is run in JUnit to test the new
      fetch command */
              public void testFetchCatEntriesByPriceRange() {
              System.out.println("19===================Fetch Catalog
      Entry For Category Null=================");
              int expectedCount = 0, actualCount = 0;
              String categoryId = "", accessProfile =
      CATALOG_ENTRY_ACCESS_PROFILE_DETAILS_KEY;
              CatalogEntryFacadeClient client = getClient();
       //The call to the new method with a minimum and maximum price
      specified.
         actualCount = findCatalogEntriesByPriceRange("desk","1", "200", accessProfile).size();
          }
              
               protected CatalogEntryFacadeClient getClient() {
                      return new
      CatalogEntryFacadeClient(businessContext, iCallbackHandler);
              }
                        
               
               public List findCatalogEntriesByPriceRange(String name, String minPrice, String maxPrice, String accessProfile) {
                      
                      final String METHODNAME =
      "findCatalogEntriesByPriceRange(String, String)";
                      
                       
                      if
      (com.ibm.commerce.foundation.common.util.logging.LoggingHelper.isEntryExitTraceEnabled(LOGGER))
      {                    
                              LOGGER.entering(CLASSNAME, METHODNAME, 
                              new Object[] { minPrice, maxPrice
      ,accessProfile }
                              );
                      }
                      
                      //build the XPath
                      StringBuffer sbXPath = new StringBuffer();
                                      
                      sbXPath.append("{" +
      SelectionCriteriaHelper.STR_ACCESS_PROFILE_PARAMETER + "=" +
      accessProfile +
      "&wc_isSKUexcluded=true}/CatalogEntry[Description[Attributes[published=1]] and Price[StandardPrice[Price[(Price[@criteria='"
      + name + "'] and Price >= '" + minPrice + "') and (Price[@criteria='" + name + "']
      and Price
      <= '" + maxPrice + "') ]]]]");
                                       
                      //List response = getCatalogEntry("wcf:XPath", sbXPath.toString());
                      List response =
      getClient().fetchCatalogEntry(sbXPath.toString());
                      
                      if
      (com.ibm.commerce.foundation.common.util.logging.LoggingHelper.isEntryExitTraceEnabled(LOGGER))
      {                    
                              LOGGER.exiting(CLASSNAME, METHODNAME, response);
                      }
                      
                      return response;
              }       
      }
      

  11. Create the unit test configuration:

    1. Right-click the config package.

    2. Select New > Other > Simple > Folder.

    3. Click Next.

    4. In the Folder name field type com.ibm.commerce.catalog.

    5. Click Finish.

  12. Repeat step 11 naming the folder com.ibm.commerce.foundation.

  13. Right-click the com.ibm.commerce.catalog folder. Select New > Other > Simple > File.

  14. Click Next.

  15. In the File name field type wc-component-client.xml.

  16. Open the wc-component-client.xml file and replace the contents with the following XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <!--********************************************************************-->
    <!--  Licensed Materials - Property of IBM                      
           -->
    <!--                                                            
           -->
    <!--  WebSphere Commerce                                        
           -->
    <!--                                                            
           -->
    <!--  (c) Copyright IBM Corp. 2006                              
           -->
    <!--                                                            
           -->
    <!--  US Government Users Restricted Rights - Use, duplication
    or       -->
    <!--  disclosure restricted by GSA ADP Schedule Contract with
    IBM Corp. -->
    <!--                                                            
           -->
    <!--********************************************************************-->
    <_config:DevelopmentClientConfiguration
    xmlns:_config="http://www.ibm.com/xmlns/prod/commerce/foundation/config"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           
    xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation/config
    ../xsd/wc-component-client.xsd">
           
    <_config:invocationservice>
                   
    <_config:invocationbinding
                           
    bindingImpl="com.ibm.commerce.foundation.internal.client.services.invocation.impl.J2SEWebServiceInvocationBindingImpl">
                           
    <_config:property name="url"
    value="http://localhost:81/webapp/wcs/component/catalog/services/CatalogServices"
    />
                   
    </_config:invocationbinding>      
           
    </_config:invocationservice>      
    </_config:DevelopmentClientConfiguration>
    

  17. Repeat steps 13-15 on the com.ibm.commerce.foundation folder and name the file wc-config-mapping-registry.xml .

  18. Open the wc-config-mapping-registry.xml file and replace the contents with the following XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <!--********************************************************************-->
    <!--  Licensed Materials - Property of IBM                      
           -->
    <!--                                                            
           -->
    <!--  WebSphere Commerce                                        
           -->
    <!--                                                            
           -->
    <!--  (c) Copyright IBM Corp. 2006                              
           -->
    <!--                                                            
           -->
    <!--  US Government Users Restricted Rights - Use, duplication
    or       -->
    <!--  disclosure restricted by GSA ADP Schedule Contract with
    IBM Corp. -->
    <!--                                                            
           -->
    <!--********************************************************************-->
    <_config:ConfigurationRegistry
    xmlns:_config="http://www.ibm.com/xmlns/prod/commerce/foundation/config"
    
                   
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   
    xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation/config
    ../xsd/wc-config-mapping-registry.xsd ">
                    
    <_config:filemapping
    configFileName="wc-dataservice-config.properties"
                    
    implementationClassName="com.ibm.commerce.foundation.internal.server.services.dataaccess.config.DataServiceConfigurationPropertyImpl"/>
            
    <_config:filemapping
    configFileName="wc-admin-component.xml"
                    
    implementationClassName="com.ibm.commerce.foundation.internal.common.config.DeploymentComponentConfigurationImpl"/>
            
    <_config:filemapping configFileName="wc-component.xml"
                    
    implementationClassName="com.ibm.commerce.foundation.internal.common.config.DevelopmentComponentConfigurationImpl"/>
     
            
    <_config:filemapping
    configFileName="wc-component-client.xml"
                    
    implementationClassName="com.ibm.commerce.foundation.internal.common.config.DevelopmentComponentClientConfigurationImpl"/>
       
            
    <_config:elementmapping
    configElementName="http://www.ibm.com/xmlns/prod/commerce/foundation/config:database"
                           
    implementationClassName="com.ibm.commerce.foundation.internal.common.config.node.DatabaseConfigNodeImpl"/>
            
    <_config:elementmapping
    configElementName="http://www.ibm.com/xmlns/prod/commerce/foundation/config:dataservice"
                           
    implementationClassName="com.ibm.commerce.foundation.internal.server.services.dataaccess.config.node.DataServiceConfigurationNodeImpl"/>
            
    <_config:elementmapping
    configElementName="http://www.ibm.com/xmlns/prod/commerce/foundation/config:command-configuration"
                           
    implementationClassName="com.ibm.commerce.foundation.internal.server.command.impl.XMLCommandRegistryImpl"/>
            
    <_config:elementmapping
    configElementName="http://www.ibm.com/xmlns/prod/commerce/foundation/config:extendedconfiguration"
                           
    implementationClassName="com.ibm.commerce.foundation.internal.common.config.node.ExtendedConfigurationConfigNodeImpl"/>
            
    <_config:elementmapping
    configElementName="http://www.ibm.com/xmlns/prod/commerce/foundation/config:invocationservice"
                    
    implementationClassName="com.ibm.commerce.foundation.internal.client.services.invocation.metadata.InvocationServiceConfiguration"/>
          
            
    <_config:elementmapping
    configElementName="http://www.ibm.com/xmlns/prod/commerce/foundation/config:authorization-configuration"
                           
    implementationClassName="com.ibm.commerce.foundation.internal.server.services.authorization.impl.PolicyManagerAuthorizationServiceImpl"/>
            
    <_config:elementmapping
    configElementName="http://www.ibm.com/xmlns/prod/commerce/foundation/config:authentication-configuration"
                           
    implementationClassName="com.ibm.commerce.foundation.internal.server.services.businesscontext.IdentityTokenCallbackHandlerImpl"/>
            
    </_config:ConfigurationRegistry>
    

  19. Open WCDE_INSTALL/workspace/SampleTest/.classpath. Add the following lines, between the <classpath> and </classpath> tags:

    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.ibm.ws.ast.st.runtime.runtimeTarget.v70/was.base.v7"/>
    <classpathentry kind="var" path="WAS_V7_WEBSERVICES_THINCLIENT"/>
    <classpathentry kind="var" path="JUNIT_HOME/junit.jar"/>
    

  20. Import the following external JARs into the SampleTest project:

    1. In the Java perspective, right-click the SampleTest project.

    2. Select Properties.

    3. Select Java Build Path.

    4. Select the Libraries panel tab.

    5. For each row in the following table, click the Add External Jars button, and add the Jar file from the specified directory.

    Jar Directory
    Catalog-Client WCDE_INSTALL/workspace/WC
    Catalog-DataObjects WCDE_INSTALL/workspace/WC
    Catalog-Server WCDE_INSTALL/wc.modules/ejbs/cloudscape
    Foundation-Core WCDE_INSTALL/workspace/WC
    Foundation-DataObjects WCDE_INSTALL/workspace/WC
    Foundation-Server WCDE_INSTALL/workspace/WC
    Foundation-Extension WCDE_INSTALL/workspace/WC
    Foundation-Sample WCDE_INSTALL/workspace/WC

  21. Open the TCP/IP monitor:

    1. Select Window > Show View > Other.

    2. Select Debug > TCP/IP Monitor.

    3. Click OK.

    4. Select the TCP/IP Monitor.

    5. Open the TCP/IP Monitor properties by clicking the black triangle at the right-hand side of the TCP/IP Monitor.

    6. Click Add.

    7. Type the following information:

      • Type: HTTP

      • Local monitoring port: 81.

      • Hostname: localhost

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

    8. Click OK.

    9. Select the created TCP/IP monitor.

    10. Click Start.

    11. Click OK.
    Make sure that the local monitoring port corresponds with the port in the wc-component-client.xml file in the com.ibm.commerce.catalog folder. The value specified in the Properties node with a URL attribute references the port that the request sends to. For the TCP/IP monitor to intercept the request the value of the port in this file must be set to localhost with a port number corresponding to the number you specify in the local monitoring port in the TCP/IP monitor. For example, the following line in the wc-component-client.xml file sends the request to localhost port 81, which the TCP/IP monitor is set to intercept according to the settings above:

    value="http://localhost:81/webapp/wcs/component/catalog/services/CatalogServices"
    

  22. Run the JUnit test:

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

    2. Select JUnit Test.

      You should see the request BOD in the left side of the TCP/IP monitor and the response BOD in the right side of the TCP/IP monitor. The response should be populated with CatalogEntries that have a price between the minimum and maximum values you specified in the SampleTest class.

< Previous | Next >


+

Search Tips   |   Advanced Search