use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method buildVoidPublisher.
@Test
public void buildVoidPublisher() throws Exception {
Mono<Void> mono = Mono.empty();
Mono<ServerResponse> result = ServerResponse.ok().build(mono);
ServerWebExchange exchange = mock(ServerWebExchange.class);
MockServerHttpResponse response = new MockServerHttpResponse();
when(exchange.getResponse()).thenReturn(response);
HandlerStrategies strategies = mock(HandlerStrategies.class);
result.then(res -> res.writeTo(exchange, strategies)).block();
StepVerifier.create(response.getBody()).expectComplete().verify();
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method responseBodyMessageConversionError.
@Test
public void responseBodyMessageConversionError() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body").toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> assertThat(error, instanceOf(NotAcceptableStatusException.class))).verify();
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method noHandler.
@Test
public void noHandler() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/does-not-exist").toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> {
assertThat(error, instanceOf(ResponseStatusException.class));
assertThat(error.getMessage(), is("Request failure [status: 404, reason: \"No matching handler\"]"));
}).verify();
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method controllerReturnsMonoError.
@Test
public void controllerReturnsMonoError() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/error-signal").toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> assertSame(EXCEPTION, error)).verify();
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CompositeContentTypeResolverBuilderTests method setDefaultContentType.
// SPR-10513
@Test
public void setDefaultContentType() throws Exception {
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().defaultContentType(MediaType.APPLICATION_JSON).build();
ServerWebExchange exchange = MockServerHttpRequest.get("/").accept(MediaType.ALL).toExchange();
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
}
Aggregations