Search in sources :

Example 1 with ServletContextAwareProcessor

use of org.springframework.web.context.support.ServletContextAwareProcessor 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();
    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) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 2 with ServletContextAwareProcessor

use of org.springframework.web.context.support.ServletContextAwareProcessor 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();
    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) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 3 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletConfigAwareWithServletConfig.

@Test
public void servletConfigAwareWithServletConfig() {
    ServletContext servletContext = new MockServletContext();
    ServletConfig servletConfig = new MockServletConfig(servletContext);
    ServletContextAwareProcessor processor = new ServletContextAwareProcessor(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)

Example 4 with ServletContextAwareProcessor

use of org.springframework.web.context.support.ServletContextAwareProcessor 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();
    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) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 5 with ServletContextAwareProcessor

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

the class ServletContextAwareProcessorTests method servletConfigAwareWithServletContextOnly.

@Test
public void servletConfigAwareWithServletContextOnly() {
    ServletContext servletContext = new MockServletContext();
    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) 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