Search in sources :

Example 1 with SessionLock

use of org.apache.tapestry5.http.internal.services.SessionLock in project tapestry-5 by apache.

the class SessionImplTest method http_session_invalidate.

@Test
public void http_session_invalidate() {
    HttpSession hs = mockHttpSession();
    HttpServletRequest hsr = mockHttpServletRequest();
    SessionLock lock = mockLock();
    train_getSession(hsr, false, hs);
    replay();
    Session session = new SessionImpl(hsr, hs, lock);
    assertFalse(session.isInvalidated());
    verify();
    train_getSession(hsr, false, null);
    replay();
    assertTrue(session.isInvalidated());
    verify();
    train_getSession(hsr, false, mockHttpSession());
    replay();
    assertTrue(session.isInvalidated());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) SessionImpl(org.apache.tapestry5.http.internal.services.SessionImpl) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) SessionLock(org.apache.tapestry5.http.internal.services.SessionLock) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 2 with SessionLock

use of org.apache.tapestry5.http.internal.services.SessionLock in project tapestry-5 by apache.

the class SessionImplTest method dirty_persisted_object_is_forced_to_update.

@Test
public void dirty_persisted_object_is_forced_to_update() {
    HttpSession hs = mockHttpSession();
    HttpServletRequest hsr = mockHttpServletRequest();
    SessionPersistedObjectAnalyzer analyzer = newMock(SessionPersistedObjectAnalyzer.class);
    Object dirty = new Object();
    SessionLock lock = mockLock();
    lock.acquireWriteLock();
    train_getAttribute(hs, "dirty", dirty);
    replay();
    Session session = new ClusteredSessionImpl(hsr, hs, lock, analyzer);
    assertSame(session.getAttribute("dirty"), dirty);
    verify();
    expect(analyzer.checkAndResetDirtyState(dirty)).andReturn(true);
    train_getSession(hsr, false, hs);
    lock.acquireWriteLock();
    hs.setAttribute("dirty", dirty);
    replay();
    session.restoreDirtyObjects();
    verify();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SessionPersistedObjectAnalyzer(org.apache.tapestry5.http.services.SessionPersistedObjectAnalyzer) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) HttpSession(javax.servlet.http.HttpSession) SessionLock(org.apache.tapestry5.http.internal.services.SessionLock) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 3 with SessionLock

use of org.apache.tapestry5.http.internal.services.SessionLock in project tapestry-5 by apache.

the class SessionImplTest method get_attribute_names.

@Test
public void get_attribute_names() {
    Enumeration e = Collections.enumeration(Arrays.asList("fred", "barney"));
    HttpSession hs = mockHttpSession();
    SessionLock lock = mockLock();
    lock.acquireReadLock();
    expect(hs.getAttributeNames()).andReturn(e);
    replay();
    Session session = new SessionImpl(null, hs, lock);
    assertEquals(session.getAttributeNames(), Arrays.asList("barney", "fred"));
    verify();
}
Also used : Enumeration(java.util.Enumeration) HttpSession(javax.servlet.http.HttpSession) SessionImpl(org.apache.tapestry5.http.internal.services.SessionImpl) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) SessionLock(org.apache.tapestry5.http.internal.services.SessionLock) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 4 with SessionLock

use of org.apache.tapestry5.http.internal.services.SessionLock in project tapestry-5 by apache.

the class SessionImplTest method invalidate.

@Test
public void invalidate() {
    HttpSession hs = mockHttpSession();
    SessionLock lock = mockLock();
    hs.invalidate();
    replay();
    Session session = new SessionImpl(null, hs, lock);
    session.invalidate();
    verify();
}
Also used : HttpSession(javax.servlet.http.HttpSession) SessionImpl(org.apache.tapestry5.http.internal.services.SessionImpl) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) SessionLock(org.apache.tapestry5.http.internal.services.SessionLock) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 5 with SessionLock

use of org.apache.tapestry5.http.internal.services.SessionLock in project tapestry-5 by apache.

the class SessionImplTest method get_attribute_names_by_prefix.

@Test
public void get_attribute_names_by_prefix() {
    Enumeration e = Collections.enumeration(Arrays.asList("fred", "barney", "fanny"));
    HttpSession hs = mockHttpSession();
    SessionLock lock = mockLock();
    lock.acquireReadLock();
    expect(hs.getAttributeNames()).andReturn(e);
    replay();
    Session session = new SessionImpl(null, hs, lock);
    assertEquals(session.getAttributeNames("f"), Arrays.asList("fanny", "fred"));
    verify();
}
Also used : Enumeration(java.util.Enumeration) HttpSession(javax.servlet.http.HttpSession) SessionImpl(org.apache.tapestry5.http.internal.services.SessionImpl) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) SessionLock(org.apache.tapestry5.http.internal.services.SessionLock) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Aggregations

HttpSession (javax.servlet.http.HttpSession)5 ClusteredSessionImpl (org.apache.tapestry5.http.internal.services.ClusteredSessionImpl)5 SessionLock (org.apache.tapestry5.http.internal.services.SessionLock)5 Session (org.apache.tapestry5.http.services.Session)5 Test (org.testng.annotations.Test)5 SessionImpl (org.apache.tapestry5.http.internal.services.SessionImpl)4 Enumeration (java.util.Enumeration)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SessionPersistedObjectAnalyzer (org.apache.tapestry5.http.services.SessionPersistedObjectAnalyzer)1