Commit f3fa952c authored by Madhura Bhave's avatar Madhura Bhave

Support WebExceptionHandler in @WebFluxTest

Closes gh-13627
parent 64a0d2f2
......@@ -32,6 +32,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.server.WebExceptionHandler;
/**
* {@link TypeExcludeFilter} for {@link WebFluxTest @WebFluxTest}.
......@@ -49,6 +50,7 @@ class WebFluxTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
includes.add(WebFluxConfigurer.class);
includes.add(Converter.class);
includes.add(GenericConverter.class);
includes.add(WebExceptionHandler.class);
DEFAULT_INCLUDES = Collections.unmodifiableSet(includes);
}
......
......@@ -36,4 +36,9 @@ public class ExampleController1 {
return Mono.just("one");
}
@GetMapping("/one/error")
public Mono<String> error() {
throw new RuntimeException("foo");
}
}
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
import reactor.core.publisher.Mono;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebExceptionHandler;
/**
* Example {@link WebExceptionHandler} used with {@link WebFluxTest} tests.
*
* @author Madhura Bhave
*/
@Component
public class ExampleWebExceptionHandler implements WebExceptionHandler {
@Override
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST);
return exchange.getResponse().setComplete();
}
}
......@@ -48,4 +48,9 @@ public class WebFluxTestAllControllersIntegrationTests {
.expectBody(String.class).isEqualTo("two");
}
@Test
public void webExceptionHandling() {
this.webClient.get().uri("/one/error").exchange().expectStatus().isBadRequest();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment