@Test @DisplayName("Book list call without any params") void bookListTest() throws Exception { when(libraryService.getList(null, null)) .thenReturn(Flux.fromIterable(new ArrayList<>() { { Field id = Book.class.getDeclaredField("id"); id.setAccessible(true); Book book = new Book("1-isbn", "Some title of tested book"); book.addAuthor(new Author("Ivan")); book.addAuthor(new Author("Petr")); book.addGenre(new Genre("horror")); id.set(book, "111"); add(book); book = new Book("2-isbn", "Another title of another book"); book.addAuthor(new Author("Ivan")); book.addGenre(new Genre("comedy")); id.set(book, "222"); add(book); } })); createWebClient(createApplicationContext()).get() .uri("/book/list") .accept(MediaType.APPLICATION_JSON_UTF8) .exchange() .expectStatus().is2xxSuccessful() .expectBody() .jsonPath("$[0].id").isEqualTo("111") .jsonPath("$[1].id").isEqualTo("222") .jsonPath("$[0].authors[0].name").exists() .jsonPath("$[2].authors[0].name").doesNotExist() .jsonPath("$[0].authors[1].name").exists(); }
public Mono<ServerResponse> bookList(ServerRequest request) { Predicate<String> notEmpty = s -> !s.equals(""); Optional<String> genre = request.queryParam("genre").filter(notEmpty); Optional<String> author = request.queryParam("author").filter(notEmpty); return ServerResponse.ok().body(libraryService.getList(author.orElse(null), genre.orElse(null)), Book.class); }
LibraryHandlers { public Mono<ServerResponse> bookList(ServerRequest request) { Predicate<String> notEmpty = s -> !s.equals(""); Optional<String> genre = request.queryParam("genre").filter(notEmpty); Optional<String> author = request.queryParam("author").filter(notEmpty); return ServerResponse.ok().body(libraryService.getList(author.orElse(null), genre.orElse(null)), Book.class); } }
LibraryHandlers { public Mono<ServerResponse> bookList(ServerRequest request) { Predicate<String> notEmpty = s -> !s.equals(""); Optional<String> genre = request.queryParam("genre").filter(notEmpty); Optional<String> author = request.queryParam("author").filter(notEmpty); return ServerResponse.ok().body(libraryService.getList(author.orElse(null), genre.orElse(null)), Book.class); } LibraryHandlers(LibraryService libraryService); }
LibraryHandlers { public Mono<ServerResponse> bookList(ServerRequest request) { Predicate<String> notEmpty = s -> !s.equals(""); Optional<String> genre = request.queryParam("genre").filter(notEmpty); Optional<String> author = request.queryParam("author").filter(notEmpty); return ServerResponse.ok().body(libraryService.getList(author.orElse(null), genre.orElse(null)), Book.class); } LibraryHandlers(LibraryService libraryService); Mono<ServerResponse> bookList(ServerRequest request); Mono<ServerResponse> bookShow(ServerRequest request); Mono<ServerResponse> bookRegister(ServerRequest request); Mono<ServerResponse> bookUpdate(ServerRequest request); Mono<ServerResponse> bookDelete(ServerRequest request); Mono<ServerResponse> authorList(ServerRequest request); Mono<ServerResponse> genreList(ServerRequest request); }
LibraryHandlers { public Mono<ServerResponse> bookList(ServerRequest request) { Predicate<String> notEmpty = s -> !s.equals(""); Optional<String> genre = request.queryParam("genre").filter(notEmpty); Optional<String> author = request.queryParam("author").filter(notEmpty); return ServerResponse.ok().body(libraryService.getList(author.orElse(null), genre.orElse(null)), Book.class); } LibraryHandlers(LibraryService libraryService); Mono<ServerResponse> bookList(ServerRequest request); Mono<ServerResponse> bookShow(ServerRequest request); Mono<ServerResponse> bookRegister(ServerRequest request); Mono<ServerResponse> bookUpdate(ServerRequest request); Mono<ServerResponse> bookDelete(ServerRequest request); Mono<ServerResponse> authorList(ServerRequest request); Mono<ServerResponse> genreList(ServerRequest request);  }