Good Afternoon to the experts,
I have a requirement where I will be invoking sequential calling of 3 REST APIs as part of a single client call GET /offers to retrieve offers available for each product in different aisles of a department store as below
- Get all the aisles in a department store /aisels
- Get all the products in an aisle /aisles/{aisleID}/products
Get all the offers for the product /product/{productId/offers
To do this from my
@Service
class using the RestTemplate exchange method:ResponseEntity aisles= restTemplate.exchange(url, HttpMethod.GET, requestEntity, Aisles.class);
Then retrieve each aisleId
in a loop and invoke the 2nd API to get the Products
ResponseEntity<Products> products= restTemplate.exchange(url,
HttpMethod.GET, requestEntity, Products.class);
Then retrieve each productId
in a loop and invoke the 3rd API to get the Offers
Finally collate all the responses to send the list of offers to the client.
Now, I am new to mockito framework for writing the JUnits. And my service class got a single method named retrieveAllOffers() in which I have the 3 exchange methods as above.
I was wondering how could I mock these 3 calls in my Junit to get a successful response scenario.
Your help is highly appreciated.