SAP / cloud-sdk-java

Use the SAP Cloud SDK for Java to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
22 stars 13 forks source link

Stubbing a child entity using wiremock makes another OData call to S/4 #471

Closed soumyachitnis-sap closed 4 months ago

soumyachitnis-sap commented 4 months ago

Hello Colleagues,

We were writing integration tests for our integration code which pulls data from S/4 Cloud when we noticed the below behavior which looks inefficient.

We are currently pulling enterpriseProject and ProjectElements data from the API /sap/opu/odata/sap/API_ENTERPRISE_PROJECT_SRV;v=0002/A_EnterpriseProject

With the above call we also expand the child entity 'ProjectElements' and read the necessary data from the child entity with the methods provided by VDM services.

image

But despite fetching all the required fields from the child, when we begun reading the entire set of data read from S/4 Cloud as below

image

the method fetchEnterpriseProjectElement() actually makes another unnecessary OData call - a roundtrip to get the relevant projectElement data.

We observed this when we were writing integration tests using wiremock. Despite already providing the stub for project and projectElement together it actually made another roundtrip and making the test fail.

MatKuhr commented 4 months ago

Yes, this is intentional, indicated by the fetch prefix in the method name. There should be an alternative getEnterpriseProjectElementOrFetch() method that only performs the request, if the data hasn't been downloaded yet.