33
33
import org .springframework .boot .actuate .health .OrderedHealthAggregator ;
34
34
import org .springframework .context .support .StaticApplicationContext ;
35
35
import org .springframework .mock .web .MockHttpServletRequest ;
36
+ import org .springframework .mock .web .MockHttpServletResponse ;
37
+ import org .springframework .web .cors .CorsConfiguration ;
38
+ import org .springframework .web .cors .CorsProcessor ;
36
39
import org .springframework .web .method .HandlerMethod ;
37
40
import org .springframework .web .servlet .HandlerExecutionChain ;
38
41
import org .springframework .web .servlet .HandlerInterceptor ;
47
50
public class CloudFoundryEndpointHandlerMappingTests
48
51
extends AbstractEndpointHandlerMappingTests {
49
52
53
+ @ Test
54
+ public void corsInterceptorShouldBeFirstAndCallCorsProcessor () throws Exception {
55
+ TestMvcEndpoint endpoint = new TestMvcEndpoint (new TestEndpoint ("a" ));
56
+ CorsConfiguration corsConfiguration = new CorsConfiguration ();
57
+ CloudFoundryEndpointHandlerMapping handlerMapping = new CloudFoundryEndpointHandlerMapping (
58
+ Collections .singleton (endpoint ), corsConfiguration , null );
59
+ CorsProcessor corsProcessor = Mockito .mock (CorsProcessor .class );
60
+ handlerMapping .setCorsProcessor (corsProcessor );
61
+ MockHttpServletRequest request = new MockHttpServletRequest ();
62
+ HandlerExecutionChain handlerExecutionChain = handlerMapping
63
+ .getHandlerExecutionChain (endpoint , request );
64
+ HandlerInterceptor [] interceptors = handlerExecutionChain .getInterceptors ();
65
+ CloudFoundryEndpointHandlerMapping .CorsInterceptor corsInterceptor = (CloudFoundryEndpointHandlerMapping .CorsInterceptor ) interceptors [0 ];
66
+ MockHttpServletResponse response = new MockHttpServletResponse ();
67
+ corsInterceptor .preHandle (request , response , new Object ());
68
+ Mockito .verify (corsProcessor ).processRequest (corsConfiguration , request ,
69
+ response );
70
+ }
71
+
50
72
@ Test
51
73
public void getHandlerExecutionChainShouldHaveSecurityInterceptor () throws Exception {
52
74
CloudFoundrySecurityInterceptor securityInterceptor = Mockito
@@ -57,7 +79,7 @@ public void getHandlerExecutionChainShouldHaveSecurityInterceptor() throws Excep
57
79
HandlerExecutionChain handlerExecutionChain = handlerMapping
58
80
.getHandlerExecutionChain (endpoint , new MockHttpServletRequest ());
59
81
HandlerInterceptor [] interceptors = handlerExecutionChain .getInterceptors ();
60
- assertThat (interceptors ). contains (securityInterceptor );
82
+ assertThat (interceptors [ 1 ]). isEqualTo (securityInterceptor );
61
83
}
62
84
63
85
@ Test
0 commit comments