@Test void createContactInfo() { 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(); assertTrue(result.firstName().equals(firstNameTest)); assertTrue(result.lastName().equals(lastNameTest)); assertTrue(!result.id().isEmpty()); CreateContactInfo createContactInfo = CreateContactInfo.builder().email("test@test.com").build(); UserDto result2 = 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(); assertFalse(result2.version().equals(result.version())); assertTrue(result2.contactInformation().isPresent()); assertTrue(!result.id().isEmpty()); }
Mono<ServerResponse> createContactInfo(ServerRequest request) { log.info("createContactInfo() -> "); return Mono.just(request.pathVariable("userId")) .flatMap(userId -> request.bodyToMono(CreateContactInfo.class) .flatMap(cmd -> userApplicationService.createContactInfo(userId, cmd))) .flatMap(this::mapToResponse) .doOnError(this::logOnError); }
UserHandler implements HttpHandler { Mono<ServerResponse> createContactInfo(ServerRequest request) { log.info("createContactInfo() -> "); return Mono.just(request.pathVariable("userId")) .flatMap(userId -> request.bodyToMono(CreateContactInfo.class) .flatMap(cmd -> userApplicationService.createContactInfo(userId, cmd))) .flatMap(this::mapToResponse) .doOnError(this::logOnError); } }
UserHandler implements HttpHandler { Mono<ServerResponse> createContactInfo(ServerRequest request) { log.info("createContactInfo() -> "); return Mono.just(request.pathVariable("userId")) .flatMap(userId -> request.bodyToMono(CreateContactInfo.class) .flatMap(cmd -> userApplicationService.createContactInfo(userId, cmd))) .flatMap(this::mapToResponse) .doOnError(this::logOnError); } UserHandler(UserApplicationService userApplicationService, UserQuery userQuery); }
UserHandler implements HttpHandler { Mono<ServerResponse> createContactInfo(ServerRequest request) { log.info("createContactInfo() -> "); return Mono.just(request.pathVariable("userId")) .flatMap(userId -> request.bodyToMono(CreateContactInfo.class) .flatMap(cmd -> userApplicationService.createContactInfo(userId, cmd))) .flatMap(this::mapToResponse) .doOnError(this::logOnError); } UserHandler(UserApplicationService userApplicationService, UserQuery userQuery); RouterFunction<ServerResponse> route(); }
UserHandler implements HttpHandler { Mono<ServerResponse> createContactInfo(ServerRequest request) { log.info("createContactInfo() -> "); return Mono.just(request.pathVariable("userId")) .flatMap(userId -> request.bodyToMono(CreateContactInfo.class) .flatMap(cmd -> userApplicationService.createContactInfo(userId, cmd))) .flatMap(this::mapToResponse) .doOnError(this::logOnError); } UserHandler(UserApplicationService userApplicationService, UserQuery userQuery); RouterFunction<ServerResponse> route();  }