Search in sources :

Example 21 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class AtmosphereFrameworkTest method autodetectBroadcaster.

@Test(dataProvider = "autodetectBroadcaster")
public void autodetectBroadcaster(String autodetectBroadcasterConfig, boolean expectedAutodetect) {
    ServletConfig servletConfig = mock(ServletConfig.class);
    when(servletConfig.getInitParameter(ApplicationConfig.AUTODETECT_BROADCASTER)).thenReturn(autodetectBroadcasterConfig);
    AtmosphereFramework framework = new AtmosphereFramework();
    framework.servletConfig = servletConfig;
    boolean actualAutodetect = framework.autodetectBroadcaster();
    assertEquals(actualAutodetect, expectedAutodetect);
}
Also used : ServletConfig(jakarta.servlet.ServletConfig) Test(org.testng.annotations.Test)

Example 22 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class AtmosphereFrameworkTest method testAtmosphereFrameworkListener.

@Test
public void testAtmosphereFrameworkListener() throws ServletException {
    AtmosphereServlet s = new MyAtmosphereServlet();
    final AtomicInteger count = new AtomicInteger();
    s.framework().frameworkListener(new AtmosphereFrameworkListener() {

        @Override
        public void onPreInit(AtmosphereFramework f) {
            count.incrementAndGet();
        }

        @Override
        public void onPostInit(AtmosphereFramework f) {
            count.incrementAndGet();
        }

        @Override
        public void onPreDestroy(AtmosphereFramework f) {
            count.incrementAndGet();
        }

        @Override
        public void onPostDestroy(AtmosphereFramework f) {
            count.incrementAndGet();
        }
    });
    s.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return "void";
        }

        @Override
        public ServletContext getServletContext() {
            return mock(ServletContext.class);
        }

        @Override
        public String getInitParameter(String name) {
            if (ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356.equals(name)) {
                return "true";
            }
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
    s.destroy();
    assertEquals(count.get(), 4);
}
Also used : Enumeration(java.util.Enumeration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) Test(org.testng.annotations.Test)

Example 23 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class AtmosphereInterceptorTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(mock(AsyncSupport.class));
    framework.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return "void";
        }

        @Override
        public ServletContext getServletContext() {
            return mock(ServletContext.class);
        }

        @Override
        public String getInitParameter(String name) {
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
    config = framework.getAtmosphereConfig();
    processor = new AsynchronousProcessor(config) {

        @Override
        public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
            return action(req, res);
        }
    };
}
Also used : Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) ServletContext(jakarta.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 24 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class AtmosphereRequestTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(new BlockingIOCometSupport(framework.getAtmosphereConfig()));
    framework.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return "void";
        }

        @Override
        public ServletContext getServletContext() {
            return mock(ServletContext.class);
        }

        @Override
        public String getInitParameter(String name) {
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
}
Also used : BlockingIOCometSupport(org.atmosphere.container.BlockingIOCometSupport) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 25 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class AtmosphereResourceListenerTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(new BlockingIOCometSupport(framework.getAtmosphereConfig()));
    framework.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return "void";
        }

        @Override
        public ServletContext getServletContext() {
            return mock(ServletContext.class);
        }

        @Override
        public String getInitParameter(String name) {
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
}
Also used : BlockingIOCometSupport(org.atmosphere.container.BlockingIOCometSupport) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

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