I have an @Service
class that does some null checks and then makes a call to an external micro-service using WebClient. Sonar is complaining that this class is not test because the method is not fully tested. Question is, how can I mock this call or use a mockserver for this? I've tried WebTestClient but I can't seem to get things to work..
public Mono<CartResponse> someServiceCall(BarRequest barRequest)
//some null checks and random logic.
return WebClient.create("http://" + fooHostName)
.post()
.uri(uri)
.body(Mono.just(barRequest), BarRequest.class)
.exchange()
.flatMap(serviceResponse -> {
if (serviceResponse.statusCode().is5xxServerError()) {
//some error logic
return Mono.just(barResponse);
}
return serviceResponse.bodyToMono(BarResponse.class);
});
So I don't want to actually make this call I just want it covered in the test, so I'd like some insight on how to get this either mocked or spin up a mock server.. I've been at this for about a day now..