Search in sources :

Example 6 with PathPatternsParameterizedTest

use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.

the class CrossOriginTests method maxAgeWithDefaultOrigin.

@PathPatternsParameterizedTest
void maxAgeWithDefaultOrigin(TestRequestMappingInfoHandlerMapping mapping) throws Exception {
    mapping.registerHandler(new MaxAgeWithDefaultOriginController());
    this.request.setRequestURI("/classAge");
    HandlerExecutionChain chain = mapping.getHandler(request);
    CorsConfiguration config = getCorsConfiguration(chain, false);
    assertThat(config).isNotNull();
    assertThat(config.getAllowedMethods()).containsExactly("GET");
    assertThat(config.getAllowedOrigins()).containsExactly("*");
    assertThat(config.getMaxAge()).isEqualTo(10);
    this.request.setRequestURI("/methodAge");
    chain = mapping.getHandler(request);
    config = getCorsConfiguration(chain, false);
    assertThat(config).isNotNull();
    assertThat(config.getAllowedMethods()).containsExactly("GET");
    assertThat(config.getAllowedOrigins()).containsExactly("*");
    assertThat(config.getMaxAge()).isEqualTo(100);
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 7 with PathPatternsParameterizedTest

use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.

the class CrossOriginTests method defaultAnnotation.

@PathPatternsParameterizedTest
void defaultAnnotation(TestRequestMappingInfoHandlerMapping mapping) throws Exception {
    mapping.registerHandler(new MethodLevelController());
    this.request.setRequestURI("/default");
    HandlerExecutionChain chain = mapping.getHandler(request);
    CorsConfiguration config = getCorsConfiguration(chain, false);
    assertThat(config).isNotNull();
    assertThat(config.getAllowedMethods()).containsExactly("GET");
    assertThat(config.getAllowedOrigins()).containsExactly("*");
    assertThat(config.getAllowCredentials()).isNull();
    assertThat(config.getAllowedHeaders()).containsExactly("*");
    assertThat(CollectionUtils.isEmpty(config.getExposedHeaders())).isTrue();
    assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(1800));
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 8 with PathPatternsParameterizedTest

use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.

the class CrossOriginTests method customOriginPatternViaValueAttribute.

@PathPatternsParameterizedTest
public void customOriginPatternViaValueAttribute(TestRequestMappingInfoHandlerMapping mapping) throws Exception {
    mapping.registerHandler(new MethodLevelController());
    this.request.setRequestURI("/customOriginPattern");
    HandlerExecutionChain chain = mapping.getHandler(request);
    CorsConfiguration config = getCorsConfiguration(chain, false);
    assertThat(config).isNotNull();
    assertThat(config.getAllowedOrigins()).isNull();
    assertThat(config.getAllowedOriginPatterns()).isEqualTo(Collections.singletonList("http://*.example.com"));
    assertThat(config.getAllowCredentials()).isNull();
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 9 with PathPatternsParameterizedTest

use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.

the class CrossOriginTests method classLevelComposedAnnotation.

// SPR-13468
@PathPatternsParameterizedTest
void classLevelComposedAnnotation(TestRequestMappingInfoHandlerMapping mapping) throws Exception {
    mapping.registerHandler(new ClassLevelMappingWithComposedAnnotation());
    this.request.setRequestURI("/foo");
    HandlerExecutionChain chain = mapping.getHandler(request);
    CorsConfiguration config = getCorsConfiguration(chain, false);
    assertThat(config).isNotNull();
    assertThat(config.getAllowedMethods()).containsExactly("GET");
    assertThat(config.getAllowedOrigins()).containsExactly("http://www.foo.example");
    assertThat(config.getAllowCredentials()).isTrue();
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 10 with PathPatternsParameterizedTest

use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.

the class CrossOriginTests method noAnnotationWithoutOrigin.

@PathPatternsParameterizedTest
void noAnnotationWithoutOrigin(TestRequestMappingInfoHandlerMapping mapping) throws Exception {
    mapping.registerHandler(new MethodLevelController());
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/no");
    HandlerExecutionChain chain = mapping.getHandler(request);
    assertThat(getCorsConfiguration(chain, false)).isNull();
}
Also used : HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Aggregations

PathPatternsParameterizedTest (org.springframework.web.servlet.handler.PathPatternsParameterizedTest)195 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)171 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)142 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)37 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)19 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)13 ModelAndView (org.springframework.web.servlet.ModelAndView)12 HttpSession (jakarta.servlet.http.HttpSession)7 Map (java.util.Map)7 MultiValueMap (org.springframework.util.MultiValueMap)7 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)6 ModelMap (org.springframework.ui.ModelMap)5 HandlerMethod (org.springframework.web.method.HandlerMethod)5 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)5 ArrayList (java.util.ArrayList)4 MarshallingHttpMessageConverter (org.springframework.http.converter.xml.MarshallingHttpMessageConverter)4 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)4 RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)4 MockMultipartFile (org.springframework.web.testfixture.servlet.MockMultipartFile)4 MockMultipartHttpServletRequest (org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest)4