Verifying reactive context

Finally, the most uncommon verification is that of the Reactor's Context. We covered the role and mechanics of Context in Chapter 4Project Reactor - the Foundation for Reactive Apps. Let's assume that we want to verify the reactive API of the authentication service. In order to authenticate a user, LoginService expects that a subscriber will provide a Context that holds the authentication information:

StepVerifier
.create(securityService.login("admin", "admin")) .expectSubscription() .expectAccessibleContext() .hasKey("security") .then() .expectComplete() .verify();

In the preceding code, we can see how to check whether there is an accessible Context instance. We can see that there is only one case in which the .expectAccessibleContext() verification may fail. This happens only when the returned Publisher is not a Reactor type (Flux or Mono). Consequently, subsequent Context verifications will be executed only if there is an accessible context. Along with the .hasKey(), there are a bunch of other methods that allow detailed verification of the current context. To exit the context verification, the builder provides the .then() method.

To summarize this section, we learned how the Reactor Test helps with Reactive Streams testing. This section covers almost everything required to unit test a small piece of reactive code, but there is still a lot more offered by the Spring Framework for testing reactive systems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.83.151