Package org.apache.tapestry5.services

Examples of org.apache.tapestry5.services.Session


        train_getAttribute(ss, "foo", "bar");

        replay();

        Request request = new RequestImpl(sr, CHARSET, null);
        Session session = request.getSession(true);

        assertEquals(session.getAttribute("foo"), "bar");

        verify();
    }
View Full Code Here


        replay();

        Request request = new RequestImpl(sr, CHARSET, null);

        Session session1 = request.getSession(true);

        verify();

        hsession1.invalidate();

        train_getSession(sr, false, hsession2);
        train_getSession(sr, true, hsession2);

        replay();

        session1.invalidate();

        Session session2 = request.getSession(true);

        assertNotSame(session2, session1);
        assertSame(request.getSession(true), session2);

        verify();
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public <T> T get(Class<T> asoClass, ApplicationStateCreator<T> creator)
    {
        Session session = getSession();

        String key = buildKey(asoClass);

        Map<String, Object> asoMap = getASOMap();

        T aso = (T) asoMap.get(key);

        if (aso != null) return aso;

        // Otherwise, get/create it in the session and record it in the
        // aso map.

        aso = (T) session.getAttribute(key);

        if (aso == null)
        {
            aso = creator.create();
            session.setAttribute(key, aso);
        }

        asoMap.put(key, aso);

        return aso;
View Full Code Here

    public <T> boolean exists(Class<T> asoClass)
    {
        String key = buildKey(asoClass);

        Session session = request.getSession(false);

        return session != null && session.getAttribute(key) != null;
    }
View Full Code Here

            if (aso == null) continue;

            if (needsRestore(aso))
            {
                Session session = request.getSession(true);

                // It is expected that the ASO implements HttpSessionBindingListener and
                // can clear its dirty flag as it is saved.

                session.setAttribute(key, aso);
            }
        }
    }
View Full Code Here

    @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 = "aso:" + asoClass.getName();
        ApplicationStateCreator creator = mockApplicationStateCreator();
        Map<String, Object> asoMap = CollectionFactory.newMap();
View Full Code Here

    @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 = "aso:" + asoClass.getName();
        ApplicationStateCreator creator = mockApplicationStateCreator();
        Map<String, Object> asoMap = CollectionFactory.newMap();

        // First for exists()
        train_getSession(request, false, session);
        train_getAttribute(session, key, null);

        // Second for get()
        train_getSession(request, true, session);

        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
        // Not in map
        train_getAttribute(session, key, null);

        train_create(creator, aso);

        session.setAttribute(key, aso);

        // Then for exists() after
        train_getSession(request, false, session);
        train_getAttribute(session, key, aso);
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void set_aso()
    {
        Request request = mockRequest();
        Session session = mockSession();
        Class asoClass = ReadOnlyBean.class;
        Object aso = new ReadOnlyBean();
        String key = "aso:" + asoClass.getName();
        Map<String, Object> asoMap = CollectionFactory.newMap();

        train_getSession(request, true, session);
        session.setAttribute(key, aso);

        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);

        replay();
View Full Code Here

    @Test
    public void aso_map_created_as_needed()
    {
        Request request = mockRequest();
        Session session = mockSession();
        Class asoClass = ReadOnlyBean.class;
        Object aso = new ReadOnlyBean();
        String key = "aso:" + asoClass.getName();
        Capture<Map<String, Object>> asoMapCapture = newCapture();

        train_getSession(request, true, session);
        session.setAttribute(key, aso);

        train_getAttribute(request, ASO_MAP_ATTRIBUTE, null);

        request.setAttribute(eq(ASO_MAP_ATTRIBUTE), capture(asoMapCapture));
View Full Code Here

    @Test
    public void restore_non_optimized_object()
    {
        Request request = mockRequest();
        Session session = mockSession();
        Map<String, Object> asoMap = CollectionFactory.newMap();

        String key = "foo:bar";
        Object aso = new Object();

        asoMap.put(key, aso);

        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
        train_getSession(request, true, session);
        session.setAttribute(key, aso);

        replay();

        EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.services.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.