Add WebInputException subclasses

Closes gh-28142
This commit is contained in:
rstoyanchev
2022-05-09 08:58:31 +01:00
parent 06e1cc2f9b
commit 5d0f49c2c8
15 changed files with 261 additions and 79 deletions

View File

@@ -53,7 +53,7 @@ import org.springframework.web.reactive.result.method.RequestMappingInfo.Builder
import org.springframework.web.server.MethodNotAllowedException;
import org.springframework.web.server.NotAcceptableStatusException;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebInputException;
import org.springframework.web.server.UnsatisfiedRequestParameterException;
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
import org.springframework.web.testfixture.server.MockServerWebExchange;
@@ -182,7 +182,7 @@ public class RequestMappingInfoHandlerMappingTests {
public void getHandlerTestRequestParamMismatch() {
ServerWebExchange exchange = MockServerWebExchange.from(get("/params"));
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, ServerWebInputException.class, ex -> {
assertError(mono, UnsatisfiedRequestParameterException.class, ex -> {
assertThat(ex.getReason()).contains("[foo=bar]");
assertThat(ex.getReason()).contains("[bar=baz]");
});
@@ -212,7 +212,9 @@ public class RequestMappingInfoHandlerMappingTests {
exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_JSON));
this.handlerMapping.getHandler(exchange).block();
assertThat(exchange.getAttributes().get(name)).as("Negated expression shouldn't be listed as producible type").isNull();
assertThat(exchange.getAttributes().get(name))
.as("Negated expression shouldn't be listed as producible type")
.isNull();
}
@Test
@@ -352,7 +354,9 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(request);
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, UnsupportedMediaTypeStatusException.class, ex -> assertThat(ex.getSupportedMediaTypes()).as("Invalid supported consumable media types").isEqualTo(Collections.singletonList(new MediaType("application", "xml"))));
assertError(mono, UnsupportedMediaTypeStatusException.class, ex -> assertThat(ex.getSupportedMediaTypes())
.as("Invalid supported consumable media types")
.isEqualTo(Collections.singletonList(new MediaType("application", "xml"))));
}
private void testHttpOptions(String requestURI, Set<HttpMethod> allowedMethods, @Nullable MediaType acceptPatch) {
@@ -382,7 +386,9 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(get(url).accept(MediaType.APPLICATION_JSON));
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, NotAcceptableStatusException.class, ex -> assertThat(ex.getSupportedMediaTypes()).as("Invalid supported producible media types").isEqualTo(Collections.singletonList(new MediaType("application", "xml"))));
assertError(mono, NotAcceptableStatusException.class, ex -> assertThat(ex.getSupportedMediaTypes())
.as("Invalid supported producible media types")
.isEqualTo(Collections.singletonList(new MediaType("application", "xml"))));
}
private void handleMatch(ServerWebExchange exchange, String pattern) {