use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method handleMatchUriTemplateVariablesDecode.
// SPR-9098
@Test
public void handleMatchUriTemplateVariablesDecode() throws Exception {
RequestMappingInfo key = paths("/{group}/{identifier}").build();
URI url = URI.create("/group/a%2Fb");
ServerWebExchange exchange = MockServerHttpRequest.method(HttpMethod.GET, url).toExchange();
HttpRequestPathHelper pathHelper = new HttpRequestPathHelper();
pathHelper.setUrlDecode(false);
String lookupPath = pathHelper.getLookupPathForRequest(exchange);
this.handlerMapping.setPathHelper(pathHelper);
this.handlerMapping.handleMatch(key, lookupPath, exchange);
String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
@SuppressWarnings("unchecked") Map<String, String> uriVariables = (Map<String, String>) exchange.getAttributes().get(name);
assertNotNull(uriVariables);
assertEquals("group", uriVariables.get("group"));
assertEquals("a/b", uriVariables.get("identifier"));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method testHttpOptions.
private void testHttpOptions(String requestURI, String allowHeader) throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.options(requestURI).toExchange();
HandlerMethod handlerMethod = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
BindingContext bindingContext = new BindingContext();
InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod);
Mono<HandlerResult> mono = invocable.invoke(exchange, bindingContext);
HandlerResult result = mono.block();
assertNotNull(result);
Optional<Object> value = result.getReturnValue();
assertTrue(value.isPresent());
assertEquals(HttpHeaders.class, value.get().getClass());
assertEquals(allowHeader, ((HttpHeaders) value.get()).getFirst("Allow"));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method getHandlerTestRequestParamMismatch.
// SPR-12854
@Test
public void getHandlerTestRequestParamMismatch() throws Exception {
ServerWebExchange exchange = get("/params").toExchange();
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, ServerWebInputException.class, ex -> {
assertThat(ex.getReason(), containsString("[foo=bar]"));
assertThat(ex.getReason(), containsString("[bar=baz]"));
});
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class HttpEntityArgumentResolverTests method httpEntityWithMonoBody.
@Test
public void httpEntityWithMonoBody() throws Exception {
ServerWebExchange exchange = postExchange("line1");
ResolvableType type = httpEntityType(Mono.class, String.class);
HttpEntity<Mono<String>> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertEquals("line1", httpEntity.getBody().block());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class HttpEntityArgumentResolverTests method requestEntity.
@Test
public void requestEntity() throws Exception {
ServerWebExchange exchange = postExchange("line1");
ResolvableType type = forClassWithGenerics(RequestEntity.class, String.class);
RequestEntity<String> requestEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getMethod(), requestEntity.getMethod());
assertEquals(exchange.getRequest().getURI(), requestEntity.getUrl());
assertEquals(exchange.getRequest().getHeaders(), requestEntity.getHeaders());
assertEquals("line1", requestEntity.getBody());
}
Aggregations