Search in sources :

Example 1 with ApplicationStateCreator

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

the class ApplicationStateManagerImplTest method get_from_configured_aso.

@SuppressWarnings("unchecked")
@Test
public void get_from_configured_aso() {
    String strategyName = "ethereal";
    ApplicationStatePersistenceStrategy strategy = mockApplicationStatePersistenceStrategy();
    ApplicationStatePersistenceStrategySource source = mockApplicationStatePersistenceStrategySource();
    Class asoClass = ReadOnlyBean.class;
    ApplicationStateCreator<ReadOnlyBean> creator = mockApplicationStateCreator();
    ReadOnlyBean aso = new ReadOnlyBean();
    Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(asoClass, new ApplicationStateContribution(strategyName, creator));
    train_get(source, strategyName, strategy);
    train_get(strategy, asoClass, creator, aso);
    replay();
    ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
    assertSame(manager.get(asoClass), aso);
    verify();
}
Also used : ApplicationStatePersistenceStrategySource(org.apache.tapestry5.services.ApplicationStatePersistenceStrategySource) ApplicationStatePersistenceStrategy(org.apache.tapestry5.services.ApplicationStatePersistenceStrategy) ApplicationStateManager(org.apache.tapestry5.services.ApplicationStateManager) ApplicationStateContribution(org.apache.tapestry5.services.ApplicationStateContribution) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Test(org.testng.annotations.Test)

Example 2 with ApplicationStateCreator

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

the class ApplicationStateManagerImplTest method get_if_exists_and_it_doesnt.

@Test
public void get_if_exists_and_it_doesnt() {
    String strategyName = "ethereal";
    ApplicationStatePersistenceStrategy strategy = mockApplicationStatePersistenceStrategy();
    ApplicationStatePersistenceStrategySource source = mockApplicationStatePersistenceStrategySource();
    Class asoClass = ReadOnlyBean.class;
    ApplicationStateCreator<ReadOnlyBean> creator = mockApplicationStateCreator();
    Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(asoClass, new ApplicationStateContribution(strategyName, creator));
    train_get(source, strategyName, strategy);
    train_getIfExists(strategy, asoClass, null);
    replay();
    ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
    assertNull(manager.getIfExists(asoClass));
    verify();
}
Also used : ApplicationStatePersistenceStrategySource(org.apache.tapestry5.services.ApplicationStatePersistenceStrategySource) ApplicationStatePersistenceStrategy(org.apache.tapestry5.services.ApplicationStatePersistenceStrategy) ApplicationStateManager(org.apache.tapestry5.services.ApplicationStateManager) ApplicationStateContribution(org.apache.tapestry5.services.ApplicationStateContribution) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Test(org.testng.annotations.Test)

Example 3 with ApplicationStateCreator

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

the class ApplicationStateManagerImplTest method get_if_exists_when_it_does_exist.

@Test
public void get_if_exists_when_it_does_exist() {
    String strategyName = "ethereal";
    ApplicationStatePersistenceStrategy strategy = mockApplicationStatePersistenceStrategy();
    ApplicationStatePersistenceStrategySource source = mockApplicationStatePersistenceStrategySource();
    Class asoClass = ReadOnlyBean.class;
    ApplicationStateCreator<ReadOnlyBean> creator = mockApplicationStateCreator();
    ReadOnlyBean aso = new ReadOnlyBean();
    Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(asoClass, new ApplicationStateContribution(strategyName, creator));
    train_get(source, strategyName, strategy);
    train_getIfExists(strategy, asoClass, aso);
    replay();
    ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
    assertSame(manager.getIfExists(asoClass), aso);
    verify();
}
Also used : ApplicationStatePersistenceStrategySource(org.apache.tapestry5.services.ApplicationStatePersistenceStrategySource) ApplicationStatePersistenceStrategy(org.apache.tapestry5.services.ApplicationStatePersistenceStrategy) ApplicationStateManager(org.apache.tapestry5.services.ApplicationStateManager) ApplicationStateContribution(org.apache.tapestry5.services.ApplicationStateContribution) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Test(org.testng.annotations.Test)

Example 4 with ApplicationStateCreator

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

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

Aggregations

ReadOnlyBean (org.apache.tapestry5.internal.transform.pages.ReadOnlyBean)8 ApplicationStatePersistenceStrategy (org.apache.tapestry5.services.ApplicationStatePersistenceStrategy)8 Test (org.testng.annotations.Test)8 ApplicationStateContribution (org.apache.tapestry5.services.ApplicationStateContribution)6 ApplicationStateManager (org.apache.tapestry5.services.ApplicationStateManager)6 ApplicationStatePersistenceStrategySource (org.apache.tapestry5.services.ApplicationStatePersistenceStrategySource)6 Session (org.apache.tapestry5.http.services.Session)3 ApplicationStateCreator (org.apache.tapestry5.services.ApplicationStateCreator)3 Request (org.apache.tapestry5.http.services.Request)2 ObjectLocator (org.apache.tapestry5.commons.ObjectLocator)1 Holder (org.apache.tapestry5.internal.util.Holder)1 IAnswer (org.easymock.IAnswer)1