Search in sources :

Example 1 with ApplicationListeners

use of io.undertow.servlet.core.ApplicationListeners in project wildfly by wildfly.

the class UndertowContextTestCase method addSessionListener.

@Test
public void addSessionListener() throws ServletException {
    HttpSessionListener listener = mock(HttpSessionListener.class);
    ServletContext context = mock(ServletContext.class);
    HttpSession session = mock(HttpSession.class);
    ApplicationListeners listeners = new ApplicationListeners(Collections.<ManagedListener>emptyList(), context);
    ArgumentCaptor<HttpSessionEvent> event = ArgumentCaptor.forClass(HttpSessionEvent.class);
    when(this.deployment.getApplicationListeners()).thenReturn(listeners);
    this.context.addSessionListener(listener);
    listeners.start();
    listeners.sessionCreated(session);
    verify(listener).sessionCreated(event.capture());
    assertSame(session, event.getValue().getSession());
    event = ArgumentCaptor.forClass(HttpSessionEvent.class);
    listeners.sessionDestroyed(session);
    verify(listener).sessionDestroyed(event.capture());
    assertSame(session, event.getValue().getSession());
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) HttpSession(javax.servlet.http.HttpSession) ApplicationListeners(io.undertow.servlet.core.ApplicationListeners) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 2 with ApplicationListeners

use of io.undertow.servlet.core.ApplicationListeners in project wildfly by wildfly.

the class UndertowContextTestCase method addRequestListener.

@Test
public void addRequestListener() throws ServletException {
    ServletRequestListener listener = mock(ServletRequestListener.class);
    ServletContext context = mock(ServletContext.class);
    ServletRequest request = mock(ServletRequest.class);
    ApplicationListeners listeners = new ApplicationListeners(Collections.<ManagedListener>emptyList(), context);
    ArgumentCaptor<ServletRequestEvent> event = ArgumentCaptor.forClass(ServletRequestEvent.class);
    when(this.deployment.getApplicationListeners()).thenReturn(listeners);
    this.context.addRequestListener(listener);
    listeners.start();
    listeners.requestInitialized(request);
    verify(listener).requestInitialized(event.capture());
    assertSame(request, event.getValue().getServletRequest());
    assertSame(context, event.getValue().getServletContext());
    event = ArgumentCaptor.forClass(ServletRequestEvent.class);
    listeners.requestDestroyed(request);
    verify(listener).requestDestroyed(event.capture());
    assertSame(request, event.getValue().getServletRequest());
    assertSame(context, event.getValue().getServletContext());
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletRequestListener(javax.servlet.ServletRequestListener) ApplicationListeners(io.undertow.servlet.core.ApplicationListeners) ServletContext(javax.servlet.ServletContext) ServletRequestEvent(javax.servlet.ServletRequestEvent) Test(org.junit.Test)

Example 3 with ApplicationListeners

use of io.undertow.servlet.core.ApplicationListeners in project wildfly by wildfly.

the class UndertowContextTestCase method isStarted.

@Test
public void isStarted() throws ServletException {
    ServletContext context = mock(ServletContext.class);
    ApplicationListeners listeners = new ApplicationListeners(Collections.<ManagedListener>emptyList(), context);
    when(this.deployment.getApplicationListeners()).thenReturn(listeners);
    assertFalse(this.context.isStarted());
    listeners.start();
    assertTrue(this.context.isStarted());
    listeners.stop();
    assertFalse(this.context.isStarted());
}
Also used : ApplicationListeners(io.undertow.servlet.core.ApplicationListeners) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Aggregations

ApplicationListeners (io.undertow.servlet.core.ApplicationListeners)3 ServletContext (javax.servlet.ServletContext)3 Test (org.junit.Test)3 ServletRequest (javax.servlet.ServletRequest)1 ServletRequestEvent (javax.servlet.ServletRequestEvent)1 ServletRequestListener (javax.servlet.ServletRequestListener)1 HttpSession (javax.servlet.http.HttpSession)1 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)1 HttpSessionListener (javax.servlet.http.HttpSessionListener)1