How to test a RestController with subscription queries


We have some (springboot) Rest Controllers which use subscription queries. I need some advise on how to test these controllers in isolation and mock the results of the subscription queries.

Any help and insights on this would help.


Hi @Danny_Kruitbosch,

I believe you can simply create a DefaultSubscriptionQueryResult and mock your QueryGateway using that.

For example:

Mono<String> initialResult = Mono.just("initial");
Flux<String> updates = Flux.just("update1", "update2");
SubscriptionQueryResult<String, String> mockedSubscriptionQueryResult =
         new DefaultSubscriptionQueryResult<>(initialResult,
                                              () -> true);
1 Like