use of jakarta.servlet.ServletContext 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();
}
use of jakarta.servlet.ServletContext 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();
}
use of jakarta.servlet.ServletContext in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletContextAwareWithServletContextAndServletConfig.
@Test
public void servletContextAwareWithServletContextAndServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletConfig servletConfig = new MockServletConfig(servletContext);
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, 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);
}
use of jakarta.servlet.ServletContext in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletConfigAwareWithNullServletContextAndNonNullServletConfig.
@Test
public void servletConfigAwareWithNullServletContextAndNonNullServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletConfig servletConfig = new MockServletConfig(servletContext);
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(null, 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);
}
use of jakarta.servlet.ServletContext in project spring-boot by spring-projects.
the class OnWarDeploymentCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ResourceLoader resourceLoader = context.getResourceLoader();
if (resourceLoader instanceof WebApplicationContext) {
WebApplicationContext applicationContext = (WebApplicationContext) resourceLoader;
ServletContext servletContext = applicationContext.getServletContext();
if (servletContext != null) {
return ConditionOutcome.match("Application is deployed as a WAR file.");
}
}
return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnWarDeployment.class).because("the application is not deployed as a WAR file."));
}
Aggregations