Search in sources :

Example 1 with ServletContextAwareBean

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

the class DispatcherServletTests method dispatcherServletContextRefresh.

@Test
public void dispatcherServletContextRefresh() throws ServletException {
    MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
    DispatcherServlet servlet = new DispatcherServlet();
    servlet.init(new MockServletConfig(servletContext, "empty"));
    ServletContextAwareBean contextBean = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
    ServletConfigAwareBean configBean = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
    assertSame(servletContext, contextBean.getServletContext());
    assertSame(servlet.getServletConfig(), configBean.getServletConfig());
    MultipartResolver multipartResolver = servlet.getMultipartResolver();
    assertNotNull(multipartResolver);
    ((ConfigurableApplicationContext) servlet.getWebApplicationContext()).refresh();
    ServletContextAwareBean contextBean2 = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
    ServletConfigAwareBean configBean2 = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
    assertSame(servletContext, contextBean2.getServletContext());
    assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
    assertTrue(contextBean != contextBean2);
    assertTrue(configBean != configBean2);
    MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
    assertTrue(multipartResolver != multipartResolver2);
    servlet.destroy();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ServletContextAwareBean(org.springframework.web.context.ServletContextAwareBean) MockServletConfig(org.springframework.mock.web.test.MockServletConfig) MultipartResolver(org.springframework.web.multipart.MultipartResolver) ServletConfigAwareBean(org.springframework.web.context.ServletConfigAwareBean) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 2 with ServletContextAwareBean

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

the class DispatcherServletTests method dispatcherServletRefresh.

@Test
public void dispatcherServletRefresh() throws ServletException {
    MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
    DispatcherServlet servlet = new DispatcherServlet();
    servlet.init(new MockServletConfig(servletContext, "empty"));
    ServletContextAwareBean contextBean = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
    ServletConfigAwareBean configBean = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
    assertSame(servletContext, contextBean.getServletContext());
    assertSame(servlet.getServletConfig(), configBean.getServletConfig());
    MultipartResolver multipartResolver = servlet.getMultipartResolver();
    assertNotNull(multipartResolver);
    servlet.refresh();
    ServletContextAwareBean contextBean2 = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
    ServletConfigAwareBean configBean2 = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
    assertSame(servletContext, contextBean2.getServletContext());
    assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
    assertNotSame(contextBean, contextBean2);
    assertNotSame(configBean, configBean2);
    MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
    assertNotSame(multipartResolver, multipartResolver2);
    servlet.destroy();
}
Also used : ServletContextAwareBean(org.springframework.web.context.ServletContextAwareBean) MockServletConfig(org.springframework.mock.web.test.MockServletConfig) MultipartResolver(org.springframework.web.multipart.MultipartResolver) ServletConfigAwareBean(org.springframework.web.context.ServletConfigAwareBean) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 MockServletConfig (org.springframework.mock.web.test.MockServletConfig)2 MockServletContext (org.springframework.mock.web.test.MockServletContext)2 ServletConfigAwareBean (org.springframework.web.context.ServletConfigAwareBean)2 ServletContextAwareBean (org.springframework.web.context.ServletContextAwareBean)2 MultipartResolver (org.springframework.web.multipart.MultipartResolver)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1