@Test public void notFound() { Mono<ServerResponse> result = ServerResponse.notFound().build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.NOT_FOUND.equals(response.statusCode())) .expectComplete() .verify(); }
public Mono<ServerResponse> get(ServerRequest req) { return this.posts.findById(Long.valueOf(req.pathVariable("id"))) .flatMap(post -> ServerResponse.ok().body(Mono.just(post), Post.class)) .switchIfEmpty(ServerResponse.notFound().build()); } }
public Mono<ServerResponse> get(ServerRequest req) { return this.posts.findById(req.pathVariable("id")) .flatMap(post -> ServerResponse.ok().body(Mono.just(post), Post.class)) .switchIfEmpty(ServerResponse.notFound().build()); }
public Mono<ServerResponse> handleGetUserById(ServerRequest request) { return userRepository.getUserById(request.pathVariable("id")) .flatMap(user -> ServerResponse.ok().body(Mono.just(user), User.class)) .switchIfEmpty(ServerResponse.notFound().build()); }
public Mono<ServerResponse> get(ServerRequest req) { return this.posts.findById(Long.valueOf(req.pathVariable("id"))) .flatMap(post -> ok().syncBody(post)) .switchIfEmpty(notFound().build()); } }
public Mono<ServerResponse> get(ServerRequest req) { return this.posts.findById(req.pathVariable("id")) .flatMap(post -> ServerResponse.ok().body(Mono.just(post), Post.class)) .switchIfEmpty(ServerResponse.notFound().build()); }
public Mono<ServerResponse> get(ServerRequest req) { return this.posts.findById(req.pathVariable("id")) .flatMap(post -> ServerResponse.ok().body(Mono.just(post), Post.class)) .switchIfEmpty(ServerResponse.notFound().build()); }
public Mono<ServerResponse> getPerson(ServerRequest request) { int personId = Integer.valueOf(request.pathVariable("id")); Mono<ServerResponse> notFound = ServerResponse.notFound().build(); Mono<Person> personMono = this.repository.getPerson(personId); return personMono .flatMap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject(person))) .switchIfEmpty(notFound); }
public Mono<ServerResponse> getUserById(ServerRequest request) { Mono<User> userMono = userReactiveRepository.findById(request.pathVariable("id")); Mono<ServerResponse> notFount = ServerResponse.notFound().build(); return userMono.flatMap(user -> ServerResponse.ok() .contentType(MediaType.APPLICATION_JSON_UTF8) .body(fromObject(user))) .switchIfEmpty(notFount); }