Merge pull request #16266 from alimate
* pr/16266: Polish "Add error rendering support with @WebFluxTest" Add error rendering support with @WebFluxTest
This commit is contained in:
commit
57761f4437
|
@ -100,7 +100,8 @@ org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\
|
|||
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration
|
||||
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration
|
||||
|
||||
# AutoConfigureMockMvc auto-configuration imports
|
||||
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc=\
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
|
@ -18,6 +18,8 @@ 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.boot.web.reactive.error.ErrorWebExceptionHandler;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
@ -29,12 +31,22 @@ import org.springframework.web.server.WebExceptionHandler;
|
|||
* @author Madhura Bhave
|
||||
*/
|
||||
@Component
|
||||
@Order(-2)
|
||||
public class ExampleWebExceptionHandler implements WebExceptionHandler {
|
||||
|
||||
private final ErrorWebExceptionHandler fallback;
|
||||
|
||||
public ExampleWebExceptionHandler(ErrorWebExceptionHandler fallback) {
|
||||
this.fallback = fallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
|
||||
exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST);
|
||||
return exchange.getResponse().setComplete();
|
||||
if (ex instanceof RuntimeException && "foo".equals(ex.getMessage())) {
|
||||
exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST);
|
||||
return exchange.getResponse().setComplete();
|
||||
}
|
||||
return this.fallback.handle(exchange, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfigura
|
|||
import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
@ -37,6 +38,7 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
|
|||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Artsiom Yudovin
|
||||
* @author Ali Dehghani
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebFluxTest
|
||||
|
@ -75,4 +77,10 @@ public class WebFluxTestAutoConfigurationIntegrationTests {
|
|||
.has(importedAutoConfiguration(ThymeleafAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorWebFluxAutoConfigurationIsImported() {
|
||||
assertThat(this.applicationContext)
|
||||
.has(importedAutoConfiguration(ErrorWebFluxAutoConfiguration.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue