@Test public void update() { String userId = UUID.randomUUID().toString(); CreateShortener createRequest = CreateShortener.builder() .url("www.testLong.org") .userId(userId) .build(); String id = webTestClient.post().uri("/shorteners") .contentType(MediaType.APPLICATION_JSON) .body(BodyInserters.fromValue(createRequest)) .exchange() .expectHeader().contentType(MediaType.APPLICATION_JSON) .expectBody(ShortenerDto.class).returnResult().getResponseBody().id(); String url = "www.testLongUpdate.org"; UpdateShortener request = UpdateShortener.builder() .id(id) .url(url).build(); webTestClient.put().uri("/shorteners/{eventId}", id).accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) .body(BodyInserters.fromValue(request)) .exchange() .expectHeader().contentType(MediaType.APPLICATION_JSON) .expectStatus().is2xxSuccessful(); ShortenerDto validateResult = webTestClient.get().uri("/shorteners/{eventId}", id).accept(MediaType .APPLICATION_JSON) .exchange() .expectStatus() .isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON) .expectBody(ShortenerDto.class).returnResult().getResponseBody(); assertTrue(validateResult.url().equals(url)); }
Mono<ServerResponse> update(ServerRequest request) { log.info("update() -> "); return Mono.fromCallable(() -> request.pathVariable("eventId")) .publishOn(Schedulers.parallel()) .flatMap(id -> request.bodyToMono(UpdateShortener.class) .flatMap(shortenerService::update) .flatMap(this::mapToResponse)); }
ShortenerHandler implements HttpHandler { Mono<ServerResponse> update(ServerRequest request) { log.info("update() -> "); return Mono.fromCallable(() -> request.pathVariable("eventId")) .publishOn(Schedulers.parallel()) .flatMap(id -> request.bodyToMono(UpdateShortener.class) .flatMap(shortenerService::update) .flatMap(this::mapToResponse)); } }
ShortenerHandler implements HttpHandler { Mono<ServerResponse> update(ServerRequest request) { log.info("update() -> "); return Mono.fromCallable(() -> request.pathVariable("eventId")) .publishOn(Schedulers.parallel()) .flatMap(id -> request.bodyToMono(UpdateShortener.class) .flatMap(shortenerService::update) .flatMap(this::mapToResponse)); } ShortenerHandler(ShortenerService shortenerService, ShortenerQuery shortenerQuery); }
ShortenerHandler implements HttpHandler { Mono<ServerResponse> update(ServerRequest request) { log.info("update() -> "); return Mono.fromCallable(() -> request.pathVariable("eventId")) .publishOn(Schedulers.parallel()) .flatMap(id -> request.bodyToMono(UpdateShortener.class) .flatMap(shortenerService::update) .flatMap(this::mapToResponse)); } ShortenerHandler(ShortenerService shortenerService, ShortenerQuery shortenerQuery); @Override RouterFunction<ServerResponse> route(); }
ShortenerHandler implements HttpHandler { Mono<ServerResponse> update(ServerRequest request) { log.info("update() -> "); return Mono.fromCallable(() -> request.pathVariable("eventId")) .publishOn(Schedulers.parallel()) .flatMap(id -> request.bodyToMono(UpdateShortener.class) .flatMap(shortenerService::update) .flatMap(this::mapToResponse)); } ShortenerHandler(ShortenerService shortenerService, ShortenerQuery shortenerQuery); @Override RouterFunction<ServerResponse> route();  }