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 1717
1818import  reactor .core .publisher .Mono ;
1919
20- import  org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
2120import  org .springframework .boot .test .autoconfigure .web .reactive .WebFluxTest ;
22- import  org .springframework .boot .web .reactive .error .ErrorWebExceptionHandler ;
2321import  org .springframework .http .HttpStatus ;
24- import  org .springframework .stereotype .Component ;
2522import  org .springframework .web .server .ServerWebExchange ;
2623import  org .springframework .web .server .WebExceptionHandler ;
2724
3128 * @author Madhura Bhave 
3229 * @author Ali Dehghani 
3330 */ 
34- @ Component 
35- @ ConditionalOnProperty (name  = "custom-error-handler.enable" )
36- public  class  ExampleWebExceptionHandler  implements  ErrorWebExceptionHandler  {
31+ public  class  ExampleWebExceptionHandler  implements  WebExceptionHandler  {
3732
3833	@ Override 
3934	public  Mono <Void > handle (ServerWebExchange  exchange , Throwable  ex ) {
Original file line number Diff line number Diff line change 2121
2222import  org .springframework .beans .factory .annotation .Autowired ;
2323import  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 ;
2428import  org .springframework .security .test .context .support .WithMockUser ;
2529import  org .springframework .test .context .junit4 .SpringRunner ;
2630import  org .springframework .test .web .reactive .server .WebTestClient ;
3337 */ 
3438@ RunWith (SpringRunner .class )
3539@ WithMockUser 
36- @ WebFluxTest ( properties  =  "custom-error-handler.enable=true" ) 
40+ @ WebFluxTest 
3741public  class  WebFluxTestAllControllersIntegrationTests  {
3842
3943	@ Autowired 
@@ -61,4 +65,19 @@ public void shouldFindJsonController() {
6165		this .webClient .get ().uri ("/json" ).exchange ().expectStatus ().isOk ();
6266	}
6367
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+ 
6483}
Original file line number Diff line number Diff line change 2121
2222import  org .springframework .beans .factory .annotation .Autowired ;
2323import  org .springframework .boot .test .autoconfigure .web .reactive .WebFluxTest ;
24+ import  org .springframework .boot .test .context .TestConfiguration ;
25+ import  org .springframework .context .annotation .Bean ;
2426import  org .springframework .http .HttpStatus ;
2527import  org .springframework .security .test .context .support .WithMockUser ;
2628import  org .springframework .test .context .junit4 .SpringRunner ;
@@ -53,4 +55,18 @@ public void defaultWebExceptionHandling() {
5355		// @formatter:on 
5456	}
5557
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+ 
5672}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments