Testing Controllers with WebTestClient 

Imagine that we test a Payment service. In this scenario, suppose that the Payment service supports the GET and POST methods for the /payments endpoint. The first HTTP call is responsible for retrieving the list of executed payments for the current user. In turn, the second makes it possible to submit a new payment. Implementation of that rest controller looks like the following:

@RestController
@RequestMapping("/payments")
public class PaymentController {
   private final PaymentService paymentService;   public PaymentController(PaymentService paymentService) {       this.paymentService = paymentService; } @GetMapping("/") public Flux<Payment> list() { return paymentService.list(); } @PostMapping("/") public ...

Get Hands-On Reactive Programming in Spring 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.