Search in sources :

Example 6 with XmlWebApplicationContext

use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-framework by spring-projects.

the class XmlWebApplicationContextTests method withoutMessageSource.

@Test
@SuppressWarnings("resource")
public void withoutMessageSource() throws Exception {
    MockServletContext sc = new MockServletContext("");
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(root);
    wac.setServletContext(sc);
    wac.setNamespace("testNamespace");
    wac.setConfigLocations(new String[] { "/org/springframework/web/context/WEB-INF/test-servlet.xml" });
    wac.refresh();
    try {
        wac.getMessage("someMessage", null, Locale.getDefault());
        fail("Should have thrown NoSuchMessageException");
    } catch (NoSuchMessageException ex) {
    // expected;
    }
    String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
    assertTrue("Default message returned", "default".equals(msg));
}
Also used : XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) NoSuchMessageException(org.springframework.context.NoSuchMessageException) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 7 with XmlWebApplicationContext

use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-framework by spring-projects.

the class BeanNameUrlHandlerMappingTests method setUp.

@Before
public void setUp() throws Exception {
    MockServletContext sc = new MockServletContext("");
    wac = new XmlWebApplicationContext();
    wac.setServletContext(sc);
    wac.setConfigLocations(new String[] { CONF });
    wac.refresh();
}
Also used : XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) Before(org.junit.Before)

Example 8 with XmlWebApplicationContext

use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-framework by spring-projects.

the class PathMatchingUrlHandlerMappingTests method setUp.

@Before
public void setUp() throws Exception {
    MockServletContext sc = new MockServletContext("");
    wac = new XmlWebApplicationContext();
    wac.setServletContext(sc);
    wac.setConfigLocations(new String[] { CONF });
    wac.refresh();
    hm = (HandlerMapping) wac.getBean("urlMapping");
}
Also used : XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) Before(org.junit.Before)

Example 9 with XmlWebApplicationContext

use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-framework by spring-projects.

the class AopNamespaceHandlerScopeIntegrationTests method setUp.

@Before
public void setUp() {
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setConfigLocations(CONTEXT);
    wac.refresh();
    this.context = wac;
}
Also used : XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) Before(org.junit.Before)

Example 10 with XmlWebApplicationContext

use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-framework by spring-projects.

the class ContextLoaderTests method testContextLoaderListenerWithDefaultContext.

@Test
public void testContextLoaderListenerWithDefaultContext() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "/org/springframework/web/context/WEB-INF/applicationContext.xml " + "/org/springframework/web/context/WEB-INF/context-addition.xml");
    ServletContextListener listener = new ContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
    WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    assertTrue("Correct WebApplicationContext exposed in ServletContext", context instanceof XmlWebApplicationContext);
    assertTrue(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext);
    LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
    assertTrue("Has father", context.containsBean("father"));
    assertTrue("Has rod", context.containsBean("rod"));
    assertTrue("Has kerry", context.containsBean("kerry"));
    assertTrue("Not destroyed", !lb.isDestroyed());
    assertFalse(context.containsBean("beans1.bean1"));
    assertFalse(context.containsBean("beans1.bean2"));
    listener.contextDestroyed(event);
    assertTrue("Destroyed", lb.isDestroyed());
    assertNull(sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
    assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
}
Also used : XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) ServletContextListener(javax.servlet.ServletContextListener) LifecycleBean(org.springframework.tests.sample.beans.LifecycleBean) 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)

Aggregations

XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)12 MockServletContext (org.springframework.mock.web.test.MockServletContext)7 Test (org.junit.Test)4 Before (org.junit.Before)3 MockServletContext (org.springframework.mock.web.MockServletContext)2 Filter (javax.servlet.Filter)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 ServletContextListener (javax.servlet.ServletContextListener)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 BeanFactoryPostProcessor (org.springframework.beans.factory.config.BeanFactoryPostProcessor)1 BeanPostProcessor (org.springframework.beans.factory.config.BeanPostProcessor)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 NoSuchMessageException (org.springframework.context.NoSuchMessageException)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 LifecycleBean (org.springframework.tests.sample.beans.LifecycleBean)1 TestBean (org.springframework.tests.sample.beans.TestBean)1 AbstractRefreshableWebApplicationContext (org.springframework.web.context.support.AbstractRefreshableWebApplicationContext)1 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)1 HandlerMapping (org.springframework.web.servlet.HandlerMapping)1