Search in sources :

Example 6 with MultipartResolver

use of org.springframework.web.multipart.MultipartResolver 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();
}
Also used : ServletContextAwareBean(org.springframework.web.context.ServletContextAwareBean) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) MultipartResolver(org.springframework.web.multipart.MultipartResolver) ServletConfigAwareBean(org.springframework.web.context.ServletConfigAwareBean) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

MultipartResolver (org.springframework.web.multipart.MultipartResolver)6 Test (org.junit.jupiter.api.Test)3 ServletConfigAwareBean (org.springframework.web.context.ServletConfigAwareBean)2 ServletContextAwareBean (org.springframework.web.context.ServletContextAwareBean)2 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)2 MockServletConfig (org.springframework.web.testfixture.servlet.MockServletConfig)2 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 StandardServletMultipartResolver (org.springframework.web.multipart.support.StandardServletMultipartResolver)1