use of org.springframework.web.context.ServletConfigAwareBean 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");
assertThat(contextBean.getServletContext()).isSameAs(servletContext);
assertThat(configBean.getServletConfig()).isSameAs(servlet.getServletConfig());
MultipartResolver multipartResolver = servlet.getMultipartResolver();
assertThat(multipartResolver).isNotNull();
((ConfigurableApplicationContext) servlet.getWebApplicationContext()).refresh();
ServletContextAwareBean contextBean2 = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
ServletConfigAwareBean configBean2 = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
assertThat(contextBean2.getServletContext()).isSameAs(servletContext);
assertThat(configBean2.getServletConfig()).isSameAs(servlet.getServletConfig());
assertThat(contextBean != contextBean2).isTrue();
assertThat(configBean != configBean2).isTrue();
MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
assertThat(multipartResolver != multipartResolver2).isTrue();
servlet.destroy();
}
use of org.springframework.web.context.ServletConfigAwareBean 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");
assertThat(contextBean.getServletContext()).isSameAs(servletContext);
assertThat(configBean.getServletConfig()).isSameAs(servlet.getServletConfig());
MultipartResolver multipartResolver = servlet.getMultipartResolver();
assertThat(multipartResolver).isNotNull();
servlet.refresh();
ServletContextAwareBean contextBean2 = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
ServletConfigAwareBean configBean2 = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
assertThat(contextBean2.getServletContext()).isSameAs(servletContext);
assertThat(configBean2.getServletConfig()).isSameAs(servlet.getServletConfig());
assertThat(contextBean2).isNotSameAs(contextBean);
assertThat(configBean2).isNotSameAs(configBean);
MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
assertThat(multipartResolver2).isNotSameAs(multipartResolver);
servlet.destroy();
}
Aggregations