Tutorial: Using the SAP Commerce Cloud Test Adapter

Here you learn how to use the SAP Commerce Cloud Test Adapter to intercept publications to a SAP Commerce Cloud Core target system. You test the export of data to a file in ImpEx format.

Prerequisites

For the purposes of this tutorial, you use the data you loaded in the previous tutorial, Tutorial: Using the CSV Web Service. Before beginning, ensure that you have this data file, and the data model you used for the CSV Web Service tutorial.

Procedure

  1. Download the Test Adapter from the Solution Book and copy it to the /opt/datahub/extensions directory of your Data Hub webapp. Remove the datahub-file-adapter-XXX.jar file used for earlier tutorials.
  2. Configure a HybrisCore target system in your hello-target-datahub-extension.xml file by replacing the target system details as follows:
    	<targetSystems>
            <targetSystem>
                <name>HybrisCoreInstallation</name>
                <type>HybrisCore</type>
                <exportURL>${datahub.extension.exportURL}</exportURL>
                <userName>${datahub.extension.userName}</userName>
                <password>${datahub.extension.password}</password>
    
  3. Compress the new extension.xml file into a JAR file as you did previously with the CSV Web Service tutorial. Replace the existing base-target-datahub-extension.jar file.
  4. Generate an encryption key, then save the result to a file called encryption-key.txt in the /opt/datahub/config directory.

    To generate a key on a Mac, for example, enter the following at your terminal command line: (On Windows, or some linux distributions, you may need to install openssl first.)

    openssl enc -aes-128-cbc -k secret -P -md sha1

    You have output similar to the following. Copy only the value after key= to the encryption-key.txt file.

    salt=AE97747ABBD7E3BA
    key=A3211AE966F91C210302FEBCE3D1FA5E
    iv =5BB75017265D009E09DA20878E12E413
  5. Add credentials for accessing the adapter, and the encryption key path configuration, to your local.properties file in the /opt/datahub/config directory. The resulting file appears as following:
    datahub.security.basic.admin.user=admin
    datahub.security.basic.admin.password=<password>
    
    datahub.extension.exportURL=https://localhost:9002/datahubadapter
    datahub.extension.userName=admin
    datahub.extension.password=<password>
    
    datahub.encryption.key.path=encryption-key.txt
  6. Configure the test adapter to produce file output by adding the following to the local.properties file, then save the file.
    test-adapter.writer.enabled=true

    By default, the test adapter writes output to a directory called impex in your home directory.

  7. Restart Data Hub.
  8. Save the following into the same directory where you are going to run the publish command. Name the new file datafile3.
    {
          "poolName": "GLOBAL",
            "targetSystemPublications": [
                {
              "targetSystemName": "HybrisCoreInstallation"
              }
            ]
    }
  9. Compose the CSV data you previously loaded in the CSV Web Service tutorial.
    curl -k -u admin:<password> --request POST https://localhost:8443/datahub-webapp/v1/pools/GLOBAL/compositions
  10. Now publish the data using the following:
    curl -k -u admin:<password> --data-binary @datafile3 -H "Content-Type:application/json" --request POST https://localhost:8443/datahub-webapp/v1/pools/GLOBAL/publications

    The curl command initiates a publication of 1000 items to the HybrisCore target you defined in your target data model. However, the test adapter you installed intercepts this publication, and redirects the resulting ImpEx data to a file in the impex directory, as described earlier. You see this redirection in the log output with the following lines:

    2016-06-23 10:37:59,659 [DEBUG] [c.h.d.c.a.i.CoreAdapterService] Creating impex for export to: http://localhost:9001/datahubadapter
    2016-06-23 10:37:59,664 [WARN] [c.h.d.t.HybrisTestTargetAdapter] ################################################################################
    2016-06-23 10:37:59,664 [WARN] [c.h.d.t.HybrisTestTargetAdapter] Publishing target system publication 2 to hybris-test-adapter.
    2016-06-23 10:37:59,664 [WARN] [c.h.d.t.HybrisTestTargetAdapter] ################################################################################
    2016-06-23 10:37:59,665 [INFO] [c.h.d.t.HybrisTestTargetAdapter] Publishing file /Users/myUser/impex/HybrisCoreInstallation_1-2-vgLM.impex to hybris-test-adapter.
    
  11. Open the file specified in the fourth line of output shown previously. It contains content similar to the following, in ImpEx format, with one line of ImpEx data for each of the 1000 items published.
    INSERT_UPDATE targetProduct;;styleDescription;styleName;category;sku;size;style;unit;manAid;manName;barCode;description;name;identifier
    ;418;<ignore>;<ignore>;<ignore>;<ignore>;<ignore>;<ignore>;Piece;3923497;Kodak;3173190000000;baseDescription_791;PROFESSIONAL BW400CN Film	 24;779864
    ;345;<ignore>;<ignore>;<ignore>;<ignore>;<ignore>;<ignore>;Piece;0284B007AA;Canon;13803050424;baseDescription_851;EF-S 60mm f/2.8 USM Macro;832383
    ;158;<ignore>;<ignore>;<ignore>;<ignore>;<ignore>;<ignore>;Piece;1629617;Kodak;6004180000000;baseDescription_793;PROFESSIONAL BW400CN Film	 36;779866
    ;361;<ignore>;<ignore>;<ignore>;<ignore>;<ignore>;<ignore>;Piece;NULL;NULL;NULL;baseDescription_958;Trope Beanie;960221
    .
    .
    .
    ##########################
    

Results

You have successfully intercepted a HybrisCore publication, and redirected the resulting ImpEx output to a file. You can now use the SAP Commerce Cloud Test Adapter in a development and test environment, without the need to install SAP Commerce Cloud.