Search in sources :

Example 6 with Session

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

the class SessionApplicationStatePersistenceStrategyTest method check_exists_with_invalid_session.

@SuppressWarnings("unchecked")
@Test
@Issue("TAP5-2537")
public void check_exists_with_invalid_session() {
    Request request = mockRequest();
    Session session = mockSession();
    Class asoClass = ReadOnlyBean.class;
    train_getSession(request, false, session);
    train_isInvalidated(session, true);
    replay();
    ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
    assertFalse(strategy.exists(asoClass));
    verify();
}
Also used : ApplicationStatePersistenceStrategy(org.apache.tapestry5.services.ApplicationStatePersistenceStrategy) Request(org.apache.tapestry5.http.services.Request) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Session(org.apache.tapestry5.http.services.Session) Issue(spock.lang.Issue) Test(org.testng.annotations.Test)

Example 7 with Session

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

the class SessionApplicationStatePersistenceStrategyTest method set_aso.

@SuppressWarnings("unchecked")
@Test
public void set_aso() {
    Request request = mockRequest();
    Session session = mockSession();
    Class asoClass = ReadOnlyBean.class;
    Object aso = new ReadOnlyBean();
    String key = "sso:" + asoClass.getName();
    train_getSession(request, true, session);
    session.setAttribute(key, aso);
    replay();
    ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
    strategy.set(asoClass, aso);
    verify();
}
Also used : ApplicationStatePersistenceStrategy(org.apache.tapestry5.services.ApplicationStatePersistenceStrategy) Request(org.apache.tapestry5.http.services.Request) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 8 with Session

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

the class SessionApplicationStatePersistenceStrategyTest method get_aso_already_exists.

@SuppressWarnings("unchecked")
@Test
public void get_aso_already_exists() {
    Request request = mockRequest();
    Session session = mockSession();
    Class asoClass = ReadOnlyBean.class;
    Object aso = new ReadOnlyBean();
    String key = "sso:" + asoClass.getName();
    ApplicationStateCreator creator = mockApplicationStateCreator();
    train_getSession(request, true, session);
    train_getAttribute(session, key, aso);
    replay();
    ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
    assertSame(strategy.get(asoClass, creator), aso);
    verify();
}
Also used : ApplicationStatePersistenceStrategy(org.apache.tapestry5.services.ApplicationStatePersistenceStrategy) Request(org.apache.tapestry5.http.services.Request) ApplicationStateCreator(org.apache.tapestry5.services.ApplicationStateCreator) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 9 with Session

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

the class SessionApplicationStatePersistenceStrategyTest method get_aso_needs_to_be_created.

@SuppressWarnings("unchecked")
@Test
public void get_aso_needs_to_be_created() {
    Request request = mockRequest();
    Session session = mockSession();
    Class asoClass = ReadOnlyBean.class;
    Object aso = new ReadOnlyBean();
    String key = "sso:" + asoClass.getName();
    ApplicationStateCreator creator = mockApplicationStateCreator();
    // First for exists()
    train_getSession(request, false, session);
    train_isInvalidated(session, false);
    train_getAttribute(session, key, null);
    // Second for get()
    train_getSession(request, true, session);
    // Not in map
    train_getAttribute(session, key, null);
    train_create(creator, aso);
    train_getSession(request, true, session);
    session.setAttribute(key, aso);
    // Then for exists() after
    train_getSession(request, false, session);
    train_isInvalidated(session, false);
    train_getAttribute(session, key, aso);
    replay();
    ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
    assertFalse(strategy.exists(asoClass));
    assertSame(strategy.get(asoClass, creator), aso);
    assertTrue(strategy.exists(asoClass));
    verify();
}
Also used : ApplicationStatePersistenceStrategy(org.apache.tapestry5.services.ApplicationStatePersistenceStrategy) Request(org.apache.tapestry5.http.services.Request) ApplicationStateCreator(org.apache.tapestry5.services.ApplicationStateCreator) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 10 with Session

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

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