@Test void getById() { String firstNameTest = "FirstNameTest"; String lastNameTest = "LastNameTest"; CreateUser request = CreateUser.builder() .firstName(firstNameTest) .lastName(lastNameTest) .build(); UserDto result = webTestClient.post().uri("/users") .contentType(MediaType.APPLICATION_JSON) .body(BodyInserters.fromValue(request)) .exchange() .expectHeader().contentType(MediaType.APPLICATION_JSON) .expectBody(UserDto.class).returnResult().getResponseBody(); CreateContactInfo createContactInfo = CreateContactInfo.builder().email("test@test.com").build(); webTestClient.put().uri("/users/{userId}/contactinformation", result.id()) .contentType(MediaType.APPLICATION_JSON) .body(BodyInserters.fromValue(createContactInfo)) .exchange() .expectHeader().contentType(MediaType.APPLICATION_JSON) .expectBody(UserDto.class).returnResult().getResponseBody(); UserDto resultGet = webTestClient.get().uri("/users/{id}", result.id()) .exchange() .expectHeader().contentType(MediaType.APPLICATION_JSON) .expectBody(UserDto.class).returnResult().getResponseBody(); assertEquals(firstNameTest, resultGet.firstName()); assertEquals(lastNameTest, resultGet.lastName()); assertTrue(resultGet.contactInformation().isPresent()); assertEquals(resultGet.contactInformation().get().email().get(), "test@test.com"); }
Mono<ServerResponse> getById(ServerRequest request) { log.info("getById() -> "); return userQuery.getById(request.pathVariable("id")) .flatMap(this::mapToResponse) .doOnError(this::logOnError); }
UserHandler implements HttpHandler { Mono<ServerResponse> getById(ServerRequest request) { log.info("getById() -> "); return userQuery.getById(request.pathVariable("id")) .flatMap(this::mapToResponse) .doOnError(this::logOnError); } }
UserHandler implements HttpHandler { Mono<ServerResponse> getById(ServerRequest request) { log.info("getById() -> "); return userQuery.getById(request.pathVariable("id")) .flatMap(this::mapToResponse) .doOnError(this::logOnError); } UserHandler(UserApplicationService userApplicationService, UserQuery userQuery); }
UserHandler implements HttpHandler { Mono<ServerResponse> getById(ServerRequest request) { log.info("getById() -> "); return userQuery.getById(request.pathVariable("id")) .flatMap(this::mapToResponse) .doOnError(this::logOnError); } UserHandler(UserApplicationService userApplicationService, UserQuery userQuery); RouterFunction<ServerResponse> route(); }
UserHandler implements HttpHandler { Mono<ServerResponse> getById(ServerRequest request) { log.info("getById() -> "); return userQuery.getById(request.pathVariable("id")) .flatMap(this::mapToResponse) .doOnError(this::logOnError); } UserHandler(UserApplicationService userApplicationService, UserQuery userQuery); RouterFunction<ServerResponse> route();  }