Search in sources :

Example 1 with SimpleWebApplicationContext

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

the class ContextLoaderTests method testContextLoaderWithCustomContext.

@Test
public void testContextLoaderWithCustomContext() throws Exception {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, "org.springframework.web.servlet.SimpleWebApplicationContext");
    ServletContextListener listener = new ContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
    WebApplicationContext wc = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    assertTrue("Correct WebApplicationContext exposed in ServletContext", wc instanceof SimpleWebApplicationContext);
}
Also used : ServletContextListener(javax.servlet.ServletContextListener) SimpleWebApplicationContext(org.springframework.web.servlet.SimpleWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) ServletContextEvent(javax.servlet.ServletContextEvent) SimpleWebApplicationContext(org.springframework.web.servlet.SimpleWebApplicationContext) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) Test(org.junit.Test)

Example 2 with SimpleWebApplicationContext

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

the class AbstractTagTests method createPageContext.

protected MockPageContext createPageContext() {
    MockServletContext sc = new MockServletContext();
    SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
    wac.setServletContext(sc);
    wac.setNamespace("test");
    wac.refresh();
    MockHttpServletRequest request = new MockHttpServletRequest(sc);
    MockHttpServletResponse response = new MockHttpServletResponse();
    if (inDispatcherServlet()) {
        request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
        LocaleResolver lr = new AcceptHeaderLocaleResolver();
        request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
        ThemeResolver tr = new FixedThemeResolver();
        request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
        request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);
    } else {
        sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    }
    return new MockPageContext(sc, request, response);
}
Also used : LocaleResolver(org.springframework.web.servlet.LocaleResolver) AcceptHeaderLocaleResolver(org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver) FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) ThemeResolver(org.springframework.web.servlet.ThemeResolver) FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) SimpleWebApplicationContext(org.springframework.web.servlet.SimpleWebApplicationContext) MockPageContext(org.springframework.mock.web.test.MockPageContext) AcceptHeaderLocaleResolver(org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver) MockServletContext(org.springframework.mock.web.test.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse)

Aggregations

MockServletContext (org.springframework.mock.web.test.MockServletContext)2 SimpleWebApplicationContext (org.springframework.web.servlet.SimpleWebApplicationContext)2 ServletContextEvent (javax.servlet.ServletContextEvent)1 ServletContextListener (javax.servlet.ServletContextListener)1 Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)1 MockPageContext (org.springframework.mock.web.test.MockPageContext)1 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)1 LocaleResolver (org.springframework.web.servlet.LocaleResolver)1 ThemeResolver (org.springframework.web.servlet.ThemeResolver)1 AcceptHeaderLocaleResolver (org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver)1 FixedThemeResolver (org.springframework.web.servlet.theme.FixedThemeResolver)1