'Wiremock test and pagination production

I couldn't find answer on my question, maybe is interesting one. I have in my production code feignClient which asks another server about information by pageable - pageSize(0, 1, 2... etc) by 100 elements. It's working)) But then I tried to test my code by wireMock, I mocked response from pagination and my test died in the cycle. I can't understand the best way to make integration test or my production code is bad. Parts:

List<Object> objects = new ArrayList<>();
List<Answer> convertedObjects;
Pageable page = PageRequest.of(0, 100);

do {
page.next();

List<Object> list = FeignClient.answer(page.pageNumber(), page.pageSize());

convertedObjects = converterList(list, Object.class);
objects.addAll(convertedObjects);
} while(!convertedObject.isEmpty());

Then I test it

Wiremock.stubFor(url).willReturn(object)...
restTemplate.exchange(url)...

So this cycle in my production code don't let move on the next step. Because wireMock every time is answering on my willReturn. Actually I need return only one time, how can deal with it? Thanks!



Solution 1:[1]

This is what the Scenarios feature is for.

You'll need to put both stubs into a scenario (i.e. same scenario name), make the first stub trigger a transition to a new state, then make the second stub contingent on the scenario being in the second state and the first stub contingent on the scenario being in the STARTED state.

See: http://wiremock.org/docs/stateful-behaviour/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Toomas Test