use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class BeanNameUrlHandlerMappingTests method asteriskMatches.
@Test
public void asteriskMatches() throws Exception {
HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping");
Object bean = wac.getBean("godCtrl");
MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/test.html");
HandlerExecutionChain hec = hm.getHandler(req);
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
req = new MockHttpServletRequest("GET", "/mypath/testarossa");
hec = hm.getHandler(req);
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
req = new MockHttpServletRequest("GET", "/mypath/tes");
hec = hm.getHandler(req);
assertTrue("Handler is correct bean", hec == null);
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class HandlerMappingIntrospectorTests method getMatchableWhereHandlerMappingDoesNotImplementMatchableInterface.
@Test(expected = IllegalStateException.class)
public void getMatchableWhereHandlerMappingDoesNotImplementMatchableInterface() throws Exception {
StaticWebApplicationContext cxt = new StaticWebApplicationContext();
cxt.registerSingleton("hm1", TestHandlerMapping.class);
cxt.refresh();
MockHttpServletRequest request = new MockHttpServletRequest();
new HandlerMappingIntrospector(cxt).getMatchableHandlerMapping(request);
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class HandlerMappingIntrospectorTests method getCorsConfigurationActual.
@Test
public void getCorsConfigurationActual() throws Exception {
AnnotationConfigWebApplicationContext cxt = new AnnotationConfigWebApplicationContext();
cxt.register(TestConfig.class);
cxt.refresh();
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/path");
request.addHeader("Origin", "http://localhost:9000");
CorsConfiguration corsConfig = new HandlerMappingIntrospector(cxt).getCorsConfiguration(request);
assertNotNull(corsConfig);
assertEquals(Collections.singletonList("http://localhost:9000"), corsConfig.getAllowedOrigins());
assertEquals(Collections.singletonList("POST"), corsConfig.getAllowedMethods());
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class HandlerMappingTests method setup.
@Before
public void setup() {
this.context = new StaticWebApplicationContext();
this.handlerMapping = new TestHandlerMapping();
this.request = new MockHttpServletRequest();
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class HandlerMethodMappingTests method unregisterMapping.
@Test
public void unregisterMapping() throws Exception {
String key = "foo";
HandlerMethod handlerMethod = new HandlerMethod(this.handler, this.method1);
this.mapping.registerMapping(key, this.handler, this.method1);
assertNotNull(this.mapping.getHandlerInternal(new MockHttpServletRequest("GET", key)));
this.mapping.unregisterMapping(key);
assertNull(mapping.getHandlerInternal(new MockHttpServletRequest("GET", key)));
assertNull(this.mapping.getMappingRegistry().getMappingsByUrl(key));
assertNull(this.mapping.getMappingRegistry().getHandlerMethodsByMappingName(this.method1.getName()));
assertNull(this.mapping.getMappingRegistry().getCorsConfiguration(handlerMethod));
}
Aggregations