Search in sources :

Example 1 with RequestContextListener

use of jodd.servlet.RequestContextListener in project jodd by oblac.

the class ShutdownTest method testSessionShutdown.

@Test
public void testSessionShutdown() {
    // http session
    HttpSession session = createSession("S2");
    HttpServletRequest request = createRequest(session);
    ServletRequestEvent requestEvent = createServletRequestEvent(request);
    HttpSessionBindingEvent event = createHttpSessionBindingEvent(session);
    // jodd
    RequestContextListener requestContextListener = new RequestContextListener();
    // start session, init request
    requestContextListener.requestInitialized(requestEvent);
    // petite
    PetiteContainer pc = new PetiteContainer();
    pc.registerPetiteBean(Ses.class, null, null, null, false);
    Ses ses = (Ses) pc.getBean("ses");
    assertNotNull(ses);
    ses.setValue("jodd");
    // session not expired
    assertEquals("jodd", ses.getValue());
    // shutdown
    pc.shutdown();
    assertEquals("-jodd", ses.getValue());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSessionBindingEvent(javax.servlet.http.HttpSessionBindingEvent) ServletsMockitoUtil.createHttpSessionBindingEvent(jodd.petite.ServletsMockitoUtil.createHttpSessionBindingEvent) Ses(jodd.petite.tst.Ses) RequestContextListener(jodd.servlet.RequestContextListener) HttpSession(javax.servlet.http.HttpSession) ServletsMockitoUtil.createServletRequestEvent(jodd.petite.ServletsMockitoUtil.createServletRequestEvent) ServletRequestEvent(javax.servlet.ServletRequestEvent) Test(org.junit.Test)

Example 2 with RequestContextListener

use of jodd.servlet.RequestContextListener in project jodd by oblac.

the class ShutdownTest method testSessionExpired.

@Test
public void testSessionExpired() {
    // http session
    HttpSession session = createSession("S1");
    HttpServletRequest request = createRequest(session);
    ServletRequestEvent requestEvent = createServletRequestEvent(request);
    HttpSessionBindingEvent event = createHttpSessionBindingEvent(session);
    // jodd
    RequestContextListener requestContextListener = new RequestContextListener();
    // start session, init request
    requestContextListener.requestInitialized(requestEvent);
    // petite
    PetiteContainer pc = new PetiteContainer();
    pc.registerPetiteBean(Ses.class, null, null, null, false);
    // callback not yet added
    SessionScope.SessionBeans sessionBeans = (SessionScope.SessionBeans) session.getAttribute(ATTR_NAME);
    assertNull(sessionBeans);
    Ses ses = (Ses) pc.getBean("ses");
    assertNotNull(ses);
    // callback added
    sessionBeans = (SessionScope.SessionBeans) session.getAttribute(ATTR_NAME);
    assertNotNull(sessionBeans);
    ses.setValue("jodd");
    // session expired
    sessionBeans.valueUnbound(event);
    assertEquals("-jodd", ses.getValue());
    pc.shutdown();
    assertEquals("-jodd", ses.getValue());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSessionBindingEvent(javax.servlet.http.HttpSessionBindingEvent) ServletsMockitoUtil.createHttpSessionBindingEvent(jodd.petite.ServletsMockitoUtil.createHttpSessionBindingEvent) Ses(jodd.petite.tst.Ses) RequestContextListener(jodd.servlet.RequestContextListener) HttpSession(javax.servlet.http.HttpSession) ServletsMockitoUtil.createServletRequestEvent(jodd.petite.ServletsMockitoUtil.createServletRequestEvent) ServletRequestEvent(javax.servlet.ServletRequestEvent) SessionScope(jodd.petite.scope.SessionScope) Test(org.junit.Test)

Aggregations

ServletRequestEvent (javax.servlet.ServletRequestEvent)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2 HttpSessionBindingEvent (javax.servlet.http.HttpSessionBindingEvent)2 ServletsMockitoUtil.createHttpSessionBindingEvent (jodd.petite.ServletsMockitoUtil.createHttpSessionBindingEvent)2 ServletsMockitoUtil.createServletRequestEvent (jodd.petite.ServletsMockitoUtil.createServletRequestEvent)2 Ses (jodd.petite.tst.Ses)2 RequestContextListener (jodd.servlet.RequestContextListener)2 Test (org.junit.Test)2 SessionScope (jodd.petite.scope.SessionScope)1