use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method getHandlerProducibleMediaTypesAttribute.
@Test
public void getHandlerProducibleMediaTypesAttribute() throws Exception {
ServerWebExchange exchange = get("/content").accept(MediaType.APPLICATION_XML).toExchange();
this.handlerMapping.getHandler(exchange).block();
String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
assertEquals(Collections.singleton(MediaType.APPLICATION_XML), exchange.getAttributes().get(name));
exchange = get("/content").accept(MediaType.APPLICATION_JSON).toExchange();
this.handlerMapping.getHandler(exchange).block();
assertNull("Negated expression shouldn't be listed as producible type", exchange.getAttributes().get(name));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method testMediaTypeNotAcceptable.
private void testMediaTypeNotAcceptable(String url) throws Exception {
ServerWebExchange exchange = get(url).accept(MediaType.APPLICATION_JSON).toExchange();
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, NotAcceptableStatusException.class, ex -> assertEquals("Invalid supported producible media types", Collections.singletonList(new MediaType("application", "xml")), ex.getSupportedMediaTypes()));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method handleMatchBestMatchingPatternAttribute.
@Test
public void handleMatchBestMatchingPatternAttribute() throws Exception {
RequestMappingInfo key = paths("/{path1}/2", "/**").build();
ServerWebExchange exchange = get("/1/2").toExchange();
this.handlerMapping.handleMatch(key, "/1/2", exchange);
assertEquals("/{path1}/2", exchange.getAttributes().get(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method getHandlerEmptyPathMatch.
@Test
public void getHandlerEmptyPathMatch() throws Exception {
Method expected = on(TestController.class).annot(requestMapping("")).resolveMethod();
ServerWebExchange exchange = get("").toExchange();
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertEquals(expected, hm.getMethod());
exchange = get("/").toExchange();
hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertEquals(expected, hm.getMethod());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method handleMatchUriTemplateVariables.
@Test
@SuppressWarnings("unchecked")
public void handleMatchUriTemplateVariables() throws Exception {
String lookupPath = "/1/2";
ServerWebExchange exchange = get(lookupPath).toExchange();
RequestMappingInfo key = paths("/{path1}/{path2}").build();
this.handlerMapping.handleMatch(key, lookupPath, exchange);
String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
Map<String, String> uriVariables = (Map<String, String>) exchange.getAttributes().get(name);
assertNotNull(uriVariables);
assertEquals("1", uriVariables.get("path1"));
assertEquals("2", uriVariables.get("path2"));
}
Aggregations