Search in sources :

Example 56 with ServletContext

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

the class SimpleRestInterceptorTest method setupAtmosphere.

private void setupAtmosphere() throws Exception {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(Mockito.mock(AsyncSupport.class));
    framework.init(new ServletConfig() {

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

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

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

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
    config = framework.getAtmosphereConfig();
}
Also used : Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext)

Example 57 with ServletContext

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

the class MeteorTest 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 58 with ServletContext

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

the class UrlMappingTest 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 new Action(Action.TYPE.CREATED);
        }
    };
}
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 59 with ServletContext

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

the class WebSocketHandlerTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(new BlockingIOCometSupport(framework.getAtmosphereConfig()));
    framework.addInitParameter(RECYCLE_ATMOSPHERE_REQUEST_RESPONSE, "false");
    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;
        }
    });
    framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
}
Also used : SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) BlockingIOCometSupport(org.atmosphere.container.BlockingIOCometSupport) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 60 with ServletContext

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

Aggregations

ServletContext (jakarta.servlet.ServletContext)116 Test (org.junit.jupiter.api.Test)45 ServletConfig (jakarta.servlet.ServletConfig)34 Enumeration (java.util.Enumeration)29 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)24 BeforeMethod (org.testng.annotations.BeforeMethod)22 IOException (java.io.IOException)17 FilterRegistration (jakarta.servlet.FilterRegistration)15 DelegatingFilterProxy (org.springframework.web.filter.DelegatingFilterProxy)15 ServletException (jakarta.servlet.ServletException)12 ServletContextAwareProcessor (org.springframework.web.context.support.ServletContextAwareProcessor)12 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)12 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)12 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)11 BlockingIOCometSupport (org.atmosphere.container.BlockingIOCometSupport)9 Filter (jakarta.servlet.Filter)8 WebApplicationContext (org.springframework.web.context.WebApplicationContext)8 Context (org.apache.catalina.Context)7 AtmosphereFramework (org.atmosphere.cpr.AtmosphereFramework)6 Test (org.junit.Test)6