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());
}
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());
}
Aggregations