Exercise: Setting up the mock server

Objectives
After completing this lesson, you will be able to:

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 Pay-As-You-Go 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
      Copy code
  2. Copy the EDMX document of business partner into the business-partner folder

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

    2. 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
      Once the file is copied you may have issues to properly display the contained text with proper colored syntax highlighting. In this case, to fix the file, right click on the file text and choose Format Document.
  3. Run the mock server on port 8081

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

    2. Run the following command to install the dependencies and start the mock server

      Code snippet
      npm install
      npm run start
      Copy code
  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
      Copy code
    3. Click on Send Request in the requests.http file to submit the GET request

    4. Check the response.

Save progress to your learning plan by logging in or creating an account

Login or Register