Search in sources :

Example 6 with ServletContext

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

the class WebSocketTest 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) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ServletContext

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

the class ManagedAtmosphereHandlerTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
    framework.addAnnotationPackage(ManagedGet.class);
    framework.setAsyncSupport(new AsynchronousProcessor(framework.getAtmosphereConfig()) {

        @Override
        public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
            return suspended(req, res);
        }

        public void action(AtmosphereResourceImpl r) {
            try {
                resumed(r.getRequest(), r.getResponse());
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ServletException e) {
                e.printStackTrace();
            }
        }
    }).init(new ServletConfig() {

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

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

        @Override
        public String getInitParameter(String name) {
            return ApplicationConfig.CLIENT_HEARTBEAT_INTERVAL_IN_SECONDS.equals(name) ? "10" : null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
}
Also used : AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) IOException(java.io.IOException) SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) ServletException(jakarta.servlet.ServletException) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AsynchronousProcessor(org.atmosphere.cpr.AsynchronousProcessor) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) ServletContext(jakarta.servlet.ServletContext) AtmosphereResourceImpl(org.atmosphere.cpr.AtmosphereResourceImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with ServletContext

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

the class AtmosphereHandlerTest method create.

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

        @Override
        public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
            return suspended(req, res);
        }

        public void action(AtmosphereResourceImpl r) {
            try {
                resumed(r.getRequest(), r.getResponse());
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ServletException e) {
                e.printStackTrace();
            }
        }
    }).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 : ServletException(jakarta.servlet.ServletException) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with ServletContext

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

the class AtmosphereInterceptorTest method configureTest.

@Test
public void configureTest() throws ServletException, IOException {
    final AtomicInteger count = new AtomicInteger();
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(mock(AsyncSupport.class));
    framework.interceptor(new AtmosphereInterceptor() {

        @Override
        public void configure(AtmosphereConfig config) {
            count.incrementAndGet();
        }

        @Override
        public Action inspect(AtmosphereResource r) {
            return Action.CREATED;
        }

        @Override
        public void destroy() {
        }

        @Override
        public void postInspect(AtmosphereResource r) {
        }
    });
    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);
        }
    };
    framework.addAtmosphereHandler("/*", handler);
    assertEquals(Action.CREATED, processor.service(mock(AtmosphereRequestImpl.class), AtmosphereResponseImpl.newInstance()));
    assertEquals(1, count.get());
}
Also used : Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServletContext(jakarta.servlet.ServletContext) Test(org.testng.annotations.Test)

Example 10 with ServletContext

use of jakarta.servlet.ServletContext in project spring-security by spring-projects.

the class SessionManagementConfigTests method requestWhenCreateSessionIsSetToIfRequiredThenCreatesSessionOnLoginChallenge.

@Test
public void requestWhenCreateSessionIsSetToIfRequiredThenCreatesSessionOnLoginChallenge() throws Exception {
    this.spring.configLocations(xml("CreateSessionIfRequired")).autowire();
    ServletContext servletContext = this.mvc.getDispatcherServlet().getServletContext();
    MockHttpServletRequest request = get("/auth").buildRequest(servletContext);
    MockHttpServletResponse response = request(request, this.spring.getContext());
    assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_MOVED_TEMPORARILY);
    assertThat(request.getSession(false)).isNotNull();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletContext(jakarta.servlet.ServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ServletContext (jakarta.servlet.ServletContext)148 Test (org.junit.jupiter.api.Test)63 ServletConfig (jakarta.servlet.ServletConfig)40 Enumeration (java.util.Enumeration)29 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)24 BeforeMethod (org.testng.annotations.BeforeMethod)22 IOException (java.io.IOException)20 ServletException (jakarta.servlet.ServletException)17 FilterRegistration (jakarta.servlet.FilterRegistration)16 DelegatingFilterProxy (org.springframework.web.filter.DelegatingFilterProxy)15 Filter (jakarta.servlet.Filter)13 Test (org.junit.Test)13 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 WebApplicationContext (org.springframework.web.context.WebApplicationContext)9 File (java.io.File)8 Context (org.apache.catalina.Context)7 BlockingIOCometSupport (org.atmosphere.container.BlockingIOCometSupport)7