use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CompositeContentTypeResolverBuilderTests method setDefaultContentTypeWithStrategy.
// SPR-12286
@Test
public void setDefaultContentTypeWithStrategy() throws Exception {
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().defaultContentTypeResolver(new FixedContentTypeResolver(MediaType.APPLICATION_JSON)).build();
List<MediaType> expected = Collections.singletonList(MediaType.APPLICATION_JSON);
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
assertEquals(expected, resolver.resolveMediaTypes(exchange));
exchange = MockServerHttpRequest.get("/").accept(MediaType.ALL).toExchange();
assertEquals(expected, resolver.resolveMediaTypes(exchange));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CompositeContentTypeResolverBuilderTests method favorParameter.
@Test
public void favorParameter() throws Exception {
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().favorParameter(true).mediaType("json", MediaType.APPLICATION_JSON).build();
ServerWebExchange exchange = MockServerHttpRequest.get("/flower?format=json").toExchange();
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class PathExtensionContentTypeResolverTests method getMediaTypeFromFilenameNoJaf.
// SPR-10334
@Test
public void getMediaTypeFromFilenameNoJaf() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("test.json").toExchange();
PathExtensionContentTypeResolver resolver = new PathExtensionContentTypeResolver();
resolver.setUseJaf(false);
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.<MediaType>emptyList(), mediaTypes);
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RouterFunctionsTests method toHttpHandlerHandlerThrowResponseStatusExceptionInResponseWriteTo.
@Test
public void toHttpHandlerHandlerThrowResponseStatusExceptionInResponseWriteTo() throws Exception {
HandlerFunction<ServerResponse> handlerFunction = // Mono.<ServerResponse> is required for compilation in Eclipse
request -> Mono.<ServerResponse>just(new ServerResponse() {
@Override
public HttpStatus statusCode() {
return HttpStatus.OK;
}
@Override
public HttpHeaders headers() {
return new HttpHeaders();
}
@Override
public Mono<Void> writeTo(ServerWebExchange exchange, HandlerStrategies strategies) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found");
}
});
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.NOT_FOUND, httpResponse.getStatusCode());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CorsUrlHandlerMappingTests method actualRequestWithoutCorsConfigurationProvider.
@Test
public void actualRequestWithoutCorsConfigurationProvider() throws Exception {
String origin = "http://domain2.com";
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertSame(this.welcomeController, actual);
}
Aggregations