Exercise: Setting Up the Mock Server

Objectives

After completing this lesson, you will be able to:

  • Set up a mock server for business partner API of SAP S/4HANA Cloud

Setting up the mock server

Description

In this exercise, you will learn how to set up a Mock Server for Business Partner API of SAP S/4HANA Cloud for testing purposes.

Prerequisites

For the complete execution of current exercise, you must execute the following activities first:

  1. Execute the following exercises:
    • Creating your free trial account in SAP BTP

Steps

  1. Clone the Mock Server repository and checkout the branch mock-server in SAP Business Application Studio

    1. Open SAP Business Application Studio.

    2. Run the following commands in the terminal

      Code snippet
      cd ~/projects
      git clone https://github.com/SAP/cloud-s4-sdk-book.git
      cd cloud-s4-sdk-book
      git checkout mock-server
      Expand
    3. Choose FileOpen Folder... and open /home/user/projects/cloud-s4-sdk-book.

  2. Copy the EDMX document of business partner into the business-partner folder

    1. Browse to the SAP Business Accelerator Hub in a separate tab, then login.

    2. In the API Resources section, click on API Specification button and click on the download EDMX button. This will download the API_BUSINESS_PARTNER.edmx file

    3. Copy the API_BUSINESS_PARTNER.edmx file into the business-partner folder.

      Note
      Sometimes the XML file indentation and consequent color coding are lost during the upload, so the file content looks like a continuous sequence of (black) characters. Be aware this is not impacting the xml structure, so the file will be anyway good for the exercise execution.
  3. Run the mock server on port 8081

    1. Edit the server.js and replace port 3000 with port 8081.

    2. Run the following commands in the Terminal, to install the dependencies and start the mock server

      Code snippet
      npm install
      npm run start
      Expand
  4. Test the mock server by issuing a GET request to A_BusinessPartner entity

    1. Create a file requests.http in the root directory

    2. Add the following content to the file

      Code snippet
      ### GET Business Partners
      GET http://localhost:8081/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner?$format=json
      Expand
    3. Click on Send Request in the requests.http file to submit the GET request

    4. Check the response.

Log in to track your progress & complete quizzes