use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method ignoreInvalidEscapeSequence.
@Test
public void ignoreInvalidEscapeSequence() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
setPathWithinHandlerMapping(exchange, "/%foo%/bar.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class MessageReaderArgumentResolverTests method emptyBody.
// More extensive "empty body" tests in RequestBody- and HttpEntityArgumentResolverTests
// SPR-9942
@Test
// SPR-9942
@SuppressWarnings("unchecked")
public void emptyBody() throws Exception {
ServerWebExchange exchange = post("/path").contentType(MediaType.APPLICATION_JSON).toExchange();
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
MethodParameter param = this.testMethod.arg(type);
Mono<TestBean> result = (Mono<TestBean>) this.resolver.readBody(param, true, this.bindingContext, exchange).block();
StepVerifier.create(result).expectError(ServerWebInputException.class).verify();
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class MessageReaderArgumentResolverTests method missingContentType.
@Test
public void missingContentType() throws Exception {
ServerWebExchange exchange = post("/path").body("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}").toExchange();
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
MethodParameter param = this.testMethod.arg(type);
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange);
StepVerifier.create(result).expectError(UnsupportedMediaTypeStatusException.class).verify();
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class ModelAttributeMethodArgumentResolverTests method testValidationError.
private void testValidationError(MethodParameter param, Function<Mono<?>, Mono<?>> valueMonoExtractor) throws URISyntaxException {
ServerWebExchange exchange = postForm("age=invalid");
Mono<?> mono = createResolver().resolveArgument(param, this.bindContext, exchange);
mono = valueMonoExtractor.apply(mono);
StepVerifier.create(mono).consumeErrorWith(ex -> {
assertTrue(ex instanceof WebExchangeBindException);
WebExchangeBindException bindException = (WebExchangeBindException) ex;
assertEquals(1, bindException.getErrorCount());
assertTrue(bindException.hasFieldErrors("age"));
}).verify();
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CookieValueMethodArgumentResolverTests method resolveCookieStringArgument.
@Test
public void resolveCookieStringArgument() {
HttpCookie cookie = new HttpCookie("name", "foo");
ServerWebExchange exchange = MockServerHttpRequest.get("/").cookie(cookie.getName(), cookie).toExchange();
Mono<Object> mono = this.resolver.resolveArgument(this.cookieStringParameter, this.bindingContext, exchange);
assertEquals("Invalid result", cookie.getValue(), mono.block());
}
Aggregations