use of org.springframework.mock.web.test.MockServletContext 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);
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class ContextLoaderTests method testContextLoaderWithInvalidLocation.
@Test
public void testContextLoaderWithInvalidLocation() throws Exception {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "/WEB-INF/myContext.xml");
ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
try {
listener.contextInitialized(event);
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
// expected
assertTrue(ex.getCause() instanceof FileNotFoundException);
}
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletContextAwareWithServletContext.
@Test
public void servletContextAwareWithServletContext() {
ServletContext servletContext = new MockServletContext();
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext);
ServletContextAwareBean bean = new ServletContextAwareBean();
assertNull(bean.getServletContext());
processor.postProcessBeforeInitialization(bean, "testBean");
assertNotNull("ServletContext should have been set", bean.getServletContext());
assertEquals(servletContext, bean.getServletContext());
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletContextAwareWithNonNullServletContextAndNullServletConfig.
@Test
public void servletContextAwareWithNonNullServletContextAndNullServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, null);
ServletContextAwareBean bean = new ServletContextAwareBean();
assertNull(bean.getServletContext());
processor.postProcessBeforeInitialization(bean, "testBean");
assertNotNull("ServletContext should have been set", bean.getServletContext());
assertEquals(servletContext, bean.getServletContext());
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletConfigAwareWithNonNullServletContextAndNullServletConfig.
@Test
public void servletConfigAwareWithNonNullServletContextAndNullServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, null);
ServletConfigAwareBean bean = new ServletConfigAwareBean();
assertNull(bean.getServletConfig());
processor.postProcessBeforeInitialization(bean, "testBean");
assertNull(bean.getServletConfig());
}
Aggregations