Creating Mock services in SAP Integration Suite – API management
I have often a need to create a mock service to test an interface in SAP CPI or SAP PI/PO. That way I can check my sync response and see if a flow works as expected.
I have been using Mockable.io and can create a short video on it earlier. It did have some challenges that the standard service did not give a lot of functionality in the free version. I have seen it takes quit a bit of time to record payloads.
I thought API management could be a great way to handle the setup then there was not need for external services to mock requests.
I did spend some time to figure out how to use the API mgt for it but i guess it is quite some time size I have created anything in API mgt.
So fair I have achieved the following which is sufficient for my current case.
- Change payloads depending on the request URI used
- Fetch input data and use in response
- Save the payload that is sent in a KVM
The proxy I ended up with is quite simple.
The proxy is quite a simple with a proxy endpoint PreFlow.
I did not want to use a backend you have to go to Target Endpoint at specify the default route to none.
Setting payload in the response
I have different types of integration i want to overwrite in the same context so I just check if path suffix matches a part of the URI. Then with an AssignMessage I can set the payload that I want. I can also use variables for the content.
What does the payload look like
In mock scenarios you also often want to check the payloads that you deliver are correct. The easiest way to save a payload is just to save it in the Key Value Mapping under the message ID.
Then in my KVM I can see the payloads.
Just remember to delete the KVM from time to time.
An improvement could be to add an API to fetch last saved message.
You can download the API Proxy Sample here
Mock for testing integrations
The mock described here is quite useful for developing integrations. If you want to test integrations on SAP CPI that uses services that needs to be mocked, then I’ll recommend the Figaf Tool that handles everything about setting up the mock and sending the correct response back.