Search in sources :

Example 11 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletContextAwareWithNullServletContextAndNonNullServletConfig.

@Test
public void servletContextAwareWithNullServletContextAndNonNullServletConfig() {
    ServletContext servletContext = new MockServletContext();
    ServletConfig servletConfig = new MockServletConfig(servletContext);
    ServletContextAwareProcessor processor = new ServletContextAwareProcessor(null, servletConfig);
    ServletContextAwareBean bean = new ServletContextAwareBean();
    assertThat(bean.getServletContext()).isNull();
    processor.postProcessBeforeInitialization(bean, "testBean");
    assertThat(bean.getServletContext()).as("ServletContext should have been set").isNotNull();
    assertThat(bean.getServletContext()).isEqualTo(servletContext);
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor) ServletConfig(jakarta.servlet.ServletConfig) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 12 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletConfigAwareWithNullServletContext.

@Test
public void servletConfigAwareWithNullServletContext() {
    ServletContext servletContext = null;
    ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext);
    ServletConfigAwareBean bean = new ServletConfigAwareBean();
    assertThat(bean.getServletConfig()).isNull();
    processor.postProcessBeforeInitialization(bean, "testBean");
    assertThat(bean.getServletConfig()).isNull();
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 13 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletContextAwareWithNullServletContext.

@Test
public void servletContextAwareWithNullServletContext() {
    ServletContext servletContext = null;
    ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext);
    ServletContextAwareBean bean = new ServletContextAwareBean();
    assertThat(bean.getServletContext()).isNull();
    processor.postProcessBeforeInitialization(bean, "testBean");
    assertThat(bean.getServletContext()).isNull();
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 14 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletConfigAwareWithServletContextAndServletConfig.

@Test
public void servletConfigAwareWithServletContextAndServletConfig() {
    ServletContext servletContext = new MockServletContext();
    ServletConfig servletConfig = new MockServletConfig(servletContext);
    ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, servletConfig);
    ServletConfigAwareBean bean = new ServletConfigAwareBean();
    assertThat(bean.getServletConfig()).isNull();
    processor.postProcessBeforeInitialization(bean, "testBean");
    assertThat(bean.getServletConfig()).as("ServletConfig should have been set").isNotNull();
    assertThat(bean.getServletConfig()).isEqualTo(servletConfig);
}
Also used : ServletContextAwareProcessor(org.springframework.web.context.support.ServletContextAwareProcessor) ServletConfig(jakarta.servlet.ServletConfig) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

ServletContextAwareProcessor (org.springframework.web.context.support.ServletContextAwareProcessor)14 ServletContext (jakarta.servlet.ServletContext)12 Test (org.junit.jupiter.api.Test)12 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)12 ServletConfig (jakarta.servlet.ServletConfig)6 MockServletConfig (org.springframework.web.testfixture.servlet.MockServletConfig)6