use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method getHandlerMappedInterceptors.
@Test
public void getHandlerMappedInterceptors() throws Exception {
String path = "/foo";
HandlerInterceptor interceptor = new HandlerInterceptorAdapter() {
};
MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] { path }, interceptor);
TestRequestMappingInfoHandlerMapping mapping = new TestRequestMappingInfoHandlerMapping();
mapping.registerHandler(new TestController());
mapping.setInterceptors(new Object[] { mappedInterceptor });
mapping.setApplicationContext(new StaticWebApplicationContext());
HandlerExecutionChain chain = mapping.getHandler(new MockHttpServletRequest("GET", path));
assertNotNull(chain);
assertNotNull(chain.getInterceptors());
assertSame(interceptor, chain.getInterceptors()[0]);
chain = mapping.getHandler(new MockHttpServletRequest("GET", "/invalid"));
assertNull(chain);
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterTests method setup.
@Before
public void setup() throws Exception {
this.webAppContext = new StaticWebApplicationContext();
this.handlerAdapter = new RequestMappingHandlerAdapter();
this.handlerAdapter.setApplicationContext(this.webAppContext);
this.request = new MockHttpServletRequest("GET", "/");
this.response = new MockHttpServletResponse();
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class AbstractHtmlElementTagTests method createAndPopulatePageContext.
protected MockPageContext createAndPopulatePageContext() throws JspException {
MockPageContext pageContext = createPageContext();
MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest();
StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request);
wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
extendRequest(request);
extendPageContext(pageContext);
RequestContext requestContext = new JspAwareRequestContext(pageContext);
pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
return pageContext;
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class ViewResolverTests method testCacheRemoval.
@Test
public void testCacheRemoval() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
View cached = vr.resolveViewName("example1", Locale.getDefault());
if (view != cached) {
fail("Caching doesn't work");
}
vr.removeFromCache("example1", Locale.getDefault());
cached = vr.resolveViewName("example1", Locale.getDefault());
if (view == cached) {
// the chance of having the same reference (hashCode) twice if negligible).
fail("View wasn't removed from cache");
}
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class ViewResolverTests method testBeanNameViewResolver.
@Test
public void testBeanNameViewResolver() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
MutablePropertyValues pvs1 = new MutablePropertyValues();
pvs1.addPropertyValue(new PropertyValue("url", "/example1.jsp"));
wac.registerSingleton("example1", InternalResourceView.class, pvs1);
MutablePropertyValues pvs2 = new MutablePropertyValues();
pvs2.addPropertyValue(new PropertyValue("url", "/example2.jsp"));
wac.registerSingleton("example2", JstlView.class, pvs2);
BeanNameViewResolver vr = new BeanNameViewResolver();
vr.setApplicationContext(wac);
wac.refresh();
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", InternalResourceView.class, view.getClass());
assertEquals("Correct URL", "/example1.jsp", ((InternalResourceView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "/example2.jsp", ((JstlView) view).getUrl());
}
Aggregations