Search in sources :

Example 11 with Session

use of org.apache.tapestry5.services.Session 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 12 with Session

use of org.apache.tapestry5.services.Session in project tapestry-5 by apache.

the class SessionImplTest method get_max_inactive.

@Test
public void get_max_inactive() {
    HttpSession hs = mockHttpSession();
    int seconds = 999;
    expect(hs.getMaxInactiveInterval()).andReturn(seconds);
    replay();
    Session session = new SessionImpl(null, hs, null);
    assertEquals(session.getMaxInactiveInterval(), seconds);
    verify();
}
Also used : HttpSession(javax.servlet.http.HttpSession) SessionImpl(org.apache.tapestry5.http.internal.services.SessionImpl) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 13 with Session

use of org.apache.tapestry5.services.Session in project tapestry-5 by apache.

the class SessionPersistentFieldStrategyTest method post_change_to_root_component.

@Test
public void post_change_to_root_component() {
    Session session = mockSession();
    Request request = mockRequest();
    Object value = new Object();
    train_getSession(request, true, session);
    session.setAttribute("state:foo.Bar::field", value);
    replay();
    SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request);
    strategy.postChange("foo.Bar", null, "field", value);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 14 with Session

use of org.apache.tapestry5.services.Session in project tapestry-5 by apache.

the class SessionPersistentFieldStrategyTest method post_change_to_nested_component.

@Test
public void post_change_to_nested_component() {
    Session session = mockSession();
    Request request = mockRequest();
    Object value = new Object();
    train_getSession(request, true, session);
    session.setAttribute("state:foo.Bar:fee.fum:field", value);
    replay();
    SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request);
    strategy.postChange("foo.Bar", "fee.fum", "field", value);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 15 with Session

use of org.apache.tapestry5.services.Session in project tapestry-5 by apache.

the class SessionPersistentFieldStrategyTest method discard_changes.

/**
 * TAPESTRY-1475
 */
@Test
public void discard_changes() {
    Session session = mockSession();
    Request request = mockRequest();
    train_getSession(request, false, session);
    train_getAttributeNames(session, "state:foo.Bar:", "state:foo.Bar:baz:field");
    session.setAttribute("state:foo.Bar:baz:field", null);
    replay();
    SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request);
    strategy.discardChanges("foo.Bar");
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)31 Session (org.apache.tapestry5.http.services.Session)30 Request (org.apache.tapestry5.http.services.Request)14 HttpSession (javax.servlet.http.HttpSession)10 Logger (org.slf4j.Logger)8 ClusteredSessionImpl (org.apache.tapestry5.http.internal.services.ClusteredSessionImpl)7 Session (org.hibernate.Session)7 SessionImpl (org.apache.tapestry5.http.internal.services.SessionImpl)6 ApplicationStatePersistenceStrategy (org.apache.tapestry5.services.ApplicationStatePersistenceStrategy)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Resource (org.apache.tapestry5.commons.Resource)5 SessionLock (org.apache.tapestry5.http.internal.services.SessionLock)5 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)5 HibernateEntityValueEncoder (org.apache.tapestry5.hibernate.web.internal.HibernateEntityValueEncoder)4 ReadOnlyBean (org.apache.tapestry5.internal.transform.pages.ReadOnlyBean)4 EntityPersistentFieldStrategy (org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy)3 RequestImpl (org.apache.tapestry5.http.internal.services.RequestImpl)3 TapestrySessionFactory (org.apache.tapestry5.http.internal.services.TapestrySessionFactory)3 PersistentFieldChange (org.apache.tapestry5.services.PersistentFieldChange)3 Enumeration (java.util.Enumeration)2