cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
Read only

SAP CAP mock REST service

T1mey
Active Participant
0 Likes
770

I have a CAP application which communicates with an external API  (for user information).

I have written some simple test cases. All working fine. Now the more complex stuff should be tested and I need to mock my API.

As best with a static json response I can rely on.

So I tried to realize that but can't get a working solution.

Found something that looked promising... 

https://github.com/SAP-samples/cap-service-integration-codejam/blob/main/exercises/06-mock-separate-...

But.. No luck with it.

 

Accepted Solutions (0)

Answers (1)

Answers (1)

danielek
Discoverer
0 Likes

Local testing can for instance be done by:

  • Providing test data for remote service in srv/external/data.
  • Providing a handler for remote service to allow simulating functions and actions.

The provided data and handler for remote service is only loaded when running in development mode where no credentials are specified.

For convenience (separation) the mocked, remote service can be launched in separate terminal via cds mock <ext serv> --port <xyz>.

After, in another terminal, the normal cds watch command can be executed which will now run against the mocked service.

 

It may be needed to clean up the file .cds-services.json located in the user directory. On windows that would be in c:\Users\<user>\.

T1mey
Active Participant
0 Likes
I think all you describe is only valid for external ODATA services. Not for REST services.
danielek
Discoverer
0 Likes
Sorry. You can however provide a custom handler (implementation) for your REST service and manage it by using profiles in package.json for instance. You just need to provide the "impl": "location/to/custom/handler.js"'. In dev you could then have a handler loaded providing a static response if you like. In prod, hybrid, etc you just provide profiles and handlers for these cases.