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:
- Execute the following exercises:
- Creating your free trial account in SAP BTP
Steps
Clone the Mock Server repository and checkout the branch mock-server in SAP Business Application Studio
Open SAP Business Application Studio.
Run the following commands in the terminal
Code Snippet1234cd ~/projects git clone https://github.com/SAP/cloud-s4-sdk-book.git cd cloud-s4-sdk-book git checkout mock-serverChoose File → Open Folder... and open /home/user/projects/cloud-s4-sdk-book.
Copy the EDMX document of business partner into the business-partner folder
Browse to the SAP Business Accelerator Hub in a separate tab, then login.
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
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.
Run the mock server on port 8081
Edit the server.js and replace port 3000 with port 8081.
Run the following commands in the Terminal, to install the dependencies and start the mock server
Code Snippet12npm install npm run start
Test the mock server by issuing a GET request to A_BusinessPartner entity
Create a requests.http file, in the project root directory.
Add the following content to the file
Code Snippet12### GET Business Partners GET http://localhost:8081/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner?$format=jsonClick on Send Request in the requests.http file to submit the GET request
Check the response.