Skip to content

Commit 57761f4

Browse files
committed
Merge pull request #16266 from alimate
* pr/16266: Polish "Add error rendering support with @WebFluxTest" Add error rendering support with @WebFluxTest
2 parents 62d9c0a + 090f5f5 commit 57761f4

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\
100100
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
101101
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
102102
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
103-
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration
103+
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,\
104+
org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration
104105

105106
# AutoConfigureMockMvc auto-configuration imports
106107
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc=\

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/ExampleWebExceptionHandler.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@
1818
import reactor.core.publisher.Mono;
1919

2020
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
21+
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
22+
import org.springframework.core.annotation.Order;
2123
import org.springframework.http.HttpStatus;
2224
import org.springframework.stereotype.Component;
2325
import org.springframework.web.server.ServerWebExchange;
@@ -29,12 +31,22 @@
2931
* @author Madhura Bhave
3032
*/
3133
@Component
34+
@Order(-2)
3235
public class ExampleWebExceptionHandler implements WebExceptionHandler {
3336

37+
private final ErrorWebExceptionHandler fallback;
38+
39+
public ExampleWebExceptionHandler(ErrorWebExceptionHandler fallback) {
40+
this.fallback = fallback;
41+
}
42+
3443
@Override
3544
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
36-
exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST);
37-
return exchange.getResponse().setComplete();
45+
if (ex instanceof RuntimeException && "foo".equals(ex.getMessage())) {
46+
exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST);
47+
return exchange.getResponse().setComplete();
48+
}
49+
return this.fallback.handle(exchange, ex);
3850
}
3951

4052
}

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAutoConfigurationIntegrationTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration;
2626
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
2727
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
28+
import org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration;
2829
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
2930
import org.springframework.context.ApplicationContext;
3031
import org.springframework.test.context.junit4.SpringRunner;
@@ -37,6 +38,7 @@
3738
*
3839
* @author Stephane Nicoll
3940
* @author Artsiom Yudovin
41+
* @author Ali Dehghani
4042
*/
4143
@RunWith(SpringRunner.class)
4244
@WebFluxTest
@@ -75,4 +77,10 @@ public void thymeleafAutoConfigurationIsImported() {
7577
.has(importedAutoConfiguration(ThymeleafAutoConfiguration.class));
7678
}
7779

80+
@Test
81+
public void errorWebFluxAutoConfigurationIsImported() {
82+
assertThat(this.applicationContext)
83+
.has(importedAutoConfiguration(ErrorWebFluxAutoConfiguration.class));
84+
}
85+
7886
}

0 commit comments

Comments
 (0)