Search in sources :

Example 41 with ServletConfig

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

the class MetricsServletTest method constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig.

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

Example 42 with ServletConfig

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

the class MetricsServletTest method constructorWithRegistryAsArgumentUsesServletConfigWhenNull.

@Test
public void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() throws Exception {
    final MetricRegistry metricRegistry = mock(MetricRegistry.class);
    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.MetricsServlet.METRICS_REGISTRY))).thenReturn(metricRegistry);
    final io.dropwizard.metrics.servlets.MetricsServlet metricsServlet = new io.dropwizard.metrics.servlets.MetricsServlet(null);
    metricsServlet.init(servletConfig);
    verify(servletConfig, times(1)).getServletContext();
    verify(servletContext, times(1)).getAttribute(eq(io.dropwizard.metrics.servlets.MetricsServlet.METRICS_REGISTRY));
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) 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