0

I attempt to write a test function for a service that consumes an interval Flux from another service, created like Flux.interval(Duration.ofSeconds(1)).map( ... ).

If seen Support of MockRestServiceServer for WebClient, which is exactly what I would need. However, at present it is recommended to use OkHttp MockWebServer instead. My question now is: How do I mock a server response that provides an interval Flux?

The setBody() function of MockResponse accepts String and Buffer. Probably Buffer is the way to go. However, I don't know how to convert the Flux into a say InputStream or so, that could be read into the buffer.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
PeMa
  • 1,559
  • 18
  • 44

1 Answers1

1

Why not just use Mockito to mock that response? Basically, use Mockito to mock the Service call.

e.g. mocking a service that will give User based on id

//mocked response
Mono<User> monoUser = Mono.just(new User());
Mockito.when(UserService.getUserBasedOnID(id)).thenReturn(monoUser);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Vikram Rawat
  • 1,472
  • 11
  • 16
  • Well, because I don't know how? I will lock at it, but maybe you can provide a minimal working example on what you mean? – PeMa Sep 11 '18 at 06:59
  • Ok, so I guess you mean, I could mock my private function that consumes the other service. That's of course not the same as mocking the answer of the real http call, but at least it is one step closer. So, thanks for the hint. – PeMa Sep 11 '18 at 07:18
  • have added an example... let me know if this helps – Vikram Rawat Sep 11 '18 at 10:32
  • Well, it is a good workaround and I really appreciate your help. Still, it is not a real solution for the issue, since it doesn't do the HTTP call but mocks the answer of the method that does the call. – PeMa Sep 13 '18 at 07:15