Search in sources :

Example 36 with ServletConfig

use of jakarta.servlet.ServletConfig in project spring-framework by spring-projects.

the class ServletContextAwareProcessorTests method servletContextAwareWithServletConfig.

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

use of jakarta.servlet.ServletConfig 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 38 with ServletConfig

use of jakarta.servlet.ServletConfig 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)

Example 39 with ServletConfig

use of jakarta.servlet.ServletConfig in project metrics by dropwizard.

the class HealthCheckServletTest method constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig.

@Test
public void constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig() throws Exception {
    final HealthCheckRegistry healthCheckRegistry = mock(HealthCheckRegistry.class);
    final ServletContext servletContext = mock(ServletContext.class);
    final ServletConfig servletConfig = mock(ServletConfig.class);
    when(servletConfig.getServletContext()).thenReturn(servletContext);
    final io.dropwizard.metrics.servlets.HealthCheckServlet healthCheckServlet = new io.dropwizard.metrics.servlets.HealthCheckServlet(healthCheckRegistry);
    healthCheckServlet.init(servletConfig);
    verify(servletConfig, times(1)).getServletContext();
    verify(servletContext, never()).getAttribute(eq(io.dropwizard.metrics.servlets.HealthCheckServlet.HEALTH_CHECK_REGISTRY));
}
Also used : HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) Test(org.junit.Test)

Example 40 with ServletConfig

use of jakarta.servlet.ServletConfig in project metrics by dropwizard.

the class HealthCheckServletTest method constructorWithRegistryAsArgumentUsesServletConfigWhenNullButWrongTypeInContext.

@Test(expected = ServletException.class)
public void constructorWithRegistryAsArgumentUsesServletConfigWhenNullButWrongTypeInContext() throws Exception {
    final ServletContext servletContext = mock(ServletContext.class);
    final ServletConfig servletConfig = mock(ServletConfig.class);
    when(servletConfig.getServletContext()).thenReturn(servletContext);
    when(servletContext.getAttribute(eq(io.dropwizard.metrics.servlets.HealthCheckServlet.HEALTH_CHECK_REGISTRY))).thenReturn("IRELLEVANT_STRING");
    final io.dropwizard.metrics.servlets.HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
    healthCheckServlet.init(servletConfig);
}
Also used : ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) Test(org.junit.Test)

Aggregations

ServletConfig (jakarta.servlet.ServletConfig)42 ServletContext (jakarta.servlet.ServletContext)40 Enumeration (java.util.Enumeration)28 BeforeMethod (org.testng.annotations.BeforeMethod)22 ServletException (jakarta.servlet.ServletException)10 IOException (java.io.IOException)10 BlockingIOCometSupport (org.atmosphere.container.BlockingIOCometSupport)9 Test (org.junit.jupiter.api.Test)7 MockServletConfig (org.springframework.web.testfixture.servlet.MockServletConfig)7 AtmosphereFramework (org.atmosphere.cpr.AtmosphereFramework)6 Test (org.junit.Test)6 ServletContextAwareProcessor (org.springframework.web.context.support.ServletContextAwareProcessor)6 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)6 SimpleBroadcaster (org.atmosphere.util.SimpleBroadcaster)5 AsynchronousProcessor (org.atmosphere.cpr.AsynchronousProcessor)4 AtmosphereRequest (org.atmosphere.cpr.AtmosphereRequest)4 AtmosphereResourceImpl (org.atmosphere.cpr.AtmosphereResourceImpl)4 AtmosphereResponse (org.atmosphere.cpr.AtmosphereResponse)4 Test (org.testng.annotations.Test)4 MetricRegistry (com.codahale.metrics.MetricRegistry)2