File tree Expand file tree Collapse file tree 3 files changed +37
-7
lines changed
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient Expand file tree Collapse file tree 3 files changed +37
-7
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import reactor .core .publisher .Mono ;
19
19
20
- import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
21
20
import org .springframework .boot .test .autoconfigure .web .reactive .WebFluxTest ;
22
- import org .springframework .boot .web .reactive .error .ErrorWebExceptionHandler ;
23
21
import org .springframework .http .HttpStatus ;
24
- import org .springframework .stereotype .Component ;
25
22
import org .springframework .web .server .ServerWebExchange ;
26
23
import org .springframework .web .server .WebExceptionHandler ;
27
24
31
28
* @author Madhura Bhave
32
29
* @author Ali Dehghani
33
30
*/
34
- @ Component
35
- @ ConditionalOnProperty (name = "custom-error-handler.enable" )
36
- public class ExampleWebExceptionHandler implements ErrorWebExceptionHandler {
31
+ public class ExampleWebExceptionHandler implements WebExceptionHandler {
37
32
38
33
@ Override
39
34
public Mono <Void > handle (ServerWebExchange exchange , Throwable ex ) {
Original file line number Diff line number Diff line change 21
21
22
22
import org .springframework .beans .factory .annotation .Autowired ;
23
23
import org .springframework .boot .test .autoconfigure .web .reactive .WebFluxTest ;
24
+ import org .springframework .boot .test .context .TestConfiguration ;
25
+ import org .springframework .context .annotation .Bean ;
26
+ import org .springframework .core .Ordered ;
27
+ import org .springframework .core .annotation .Order ;
24
28
import org .springframework .security .test .context .support .WithMockUser ;
25
29
import org .springframework .test .context .junit4 .SpringRunner ;
26
30
import org .springframework .test .web .reactive .server .WebTestClient ;
33
37
*/
34
38
@ RunWith (SpringRunner .class )
35
39
@ WithMockUser
36
- @ WebFluxTest ( properties = "custom-error-handler.enable=true" )
40
+ @ WebFluxTest
37
41
public class WebFluxTestAllControllersIntegrationTests {
38
42
39
43
@ Autowired
@@ -61,4 +65,19 @@ public void shouldFindJsonController() {
61
65
this .webClient .get ().uri ("/json" ).exchange ().expectStatus ().isOk ();
62
66
}
63
67
68
+ /**
69
+ * A test configuration to register a custom exception handler. Since the registered
70
+ * handler has the highest possible priority, the default exception handler provided
71
+ * by the Spring Boot will not get a chance to handle exceptions.
72
+ */
73
+ @ TestConfiguration
74
+ static class TestConfig {
75
+
76
+ @ Bean
77
+ @ Order (Ordered .HIGHEST_PRECEDENCE )
78
+ ExampleWebExceptionHandler exampleWebExceptionHandler () {
79
+ return new ExampleWebExceptionHandler ();
80
+ }
81
+ }
82
+
64
83
}
Original file line number Diff line number Diff line change 21
21
22
22
import org .springframework .beans .factory .annotation .Autowired ;
23
23
import org .springframework .boot .test .autoconfigure .web .reactive .WebFluxTest ;
24
+ import org .springframework .boot .test .context .TestConfiguration ;
25
+ import org .springframework .context .annotation .Bean ;
24
26
import org .springframework .http .HttpStatus ;
25
27
import org .springframework .security .test .context .support .WithMockUser ;
26
28
import org .springframework .test .context .junit4 .SpringRunner ;
@@ -53,4 +55,18 @@ public void defaultWebExceptionHandling() {
53
55
// @formatter:on
54
56
}
55
57
58
+ /**
59
+ * Registers an exception handler with the default priority, so the default handler
60
+ * provided by Spring Boot will be called first.
61
+ */
62
+ @ TestConfiguration
63
+ static class TestConfig {
64
+
65
+ @ Bean
66
+ ExampleWebExceptionHandler exampleWebExceptionHandler () {
67
+ return new ExampleWebExceptionHandler ();
68
+ }
69
+
70
+ }
71
+
56
72
}
You can’t perform that action at this time.
0 commit comments