Package org.apache.myfaces.application

Examples of org.apache.myfaces.application.StateCache


        servletContext.addInitParameter("org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION", "2");
        servletContext.addInitParameter(StateManager.SERIALIZE_SERVER_STATE_PARAM_NAME, "true");

        // Initialization
        setupRequest();
        StateCache stateCache = new ServerSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
          
            facesContext.getViewRoot().setViewId("view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view1.xhtml", savedToken);
           
            Assert.assertEquals(1, value);
           
            facesContext.getViewRoot().setViewId("view2.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 2);
        }
        finally
        {
            tearDownRequest();
        }

        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view2.xhtml", savedToken);
           
            Assert.assertEquals(2, value);
           
            facesContext.getViewRoot().setViewId("view2.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 3);
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view1.xhtml", firstSavedToken);
           
            // Since org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION is 2, the first one was already discarded
            Assert.assertNull(value);
        }
        finally
View Full Code Here


    {
        servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_SERVER);

        // Initialization
        setupRequest();
        StateCache stateCache = new ClientSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
          
            facesContext.getViewRoot().setViewId("/view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            // Note we are trying to restore restoring another different view with a token from the previous view.
            // It should return null and later throw ViewExpiredException
            // In server side state saving, the hashCode of the viewId should be part of the key used to restore
            // the state, along with a counter.
            Object value = stateCache.restoreSerializedView(facesContext, "/view2.xhtml", firstSavedToken);
           
            Assert.assertNull(value);
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            // It should restore this:
            Object value = stateCache.restoreSerializedView(facesContext, "/view1.xhtml", firstSavedToken);
           
            Assert.assertEquals(1, value);
        }
        finally
        {
View Full Code Here

            setupRequest();

            // we need to take a viewId which is null -> not existing.
            facesContext.getViewRoot().setViewId(null);

            StateCache stateCache = new ServerSideStateCacheImpl();
            Object savedToken = stateCache.saveSerializedView(facesContext, 1);

        }
        finally
        {
            tearDownRequest();
View Full Code Here

    public void tryStateKeySerialization() throws Exception
    {
        // Initialization
        setupRequest();
        StateCache stateCache = new ServerSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
            facesContext.getViewRoot().setViewId("view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
           
            for (Map.Entry<String, Object> entry : facesContext.getExternalContext().getSessionMap().entrySet())
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
View Full Code Here

        servletContext.addInitParameter("org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION", "5");
        servletContext.addInitParameter("org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION", "2");

        // Initialization
        setupRequest();
        StateCache stateCache = new ServerSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
          
            facesContext.getViewRoot().setViewId("view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view1.xhtml", savedToken);
           
            Assert.assertEquals(1, value);
           
            facesContext.getViewRoot().setViewId("view2.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 2);
        }
        finally
        {
            tearDownRequest();
        }

        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view2.xhtml", savedToken);
           
            Assert.assertEquals(2, value);
           
            facesContext.getViewRoot().setViewId("view2.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 3);
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view1.xhtml", firstSavedToken);
           
            // Since org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION is 2, the first one was already discarded
            Assert.assertNull(value);
        }
        finally
View Full Code Here

    {
        servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_SERVER);

        // Initialization
        setupRequest();
        StateCache stateCache = new ClientSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
          
            facesContext.getViewRoot().setViewId("/view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            // Note we are trying to restore restoring another different view with a token from the previous view.
            // It should return null and later throw ViewExpiredException
            // In server side state saving, the hashCode of the viewId should be part of the key used to restore
            // the state, along with a counter.
            Object value = stateCache.restoreSerializedView(facesContext, "/view2.xhtml", firstSavedToken);
           
            Assert.assertNull(value);
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            // It should restore this:
            Object value = stateCache.restoreSerializedView(facesContext, "/view1.xhtml", firstSavedToken);
           
            Assert.assertEquals(1, value);
        }
        finally
        {
View Full Code Here

   
    public void tryStateKeySerialization() throws Exception
    {
        // Initialization
        setupRequest();
        StateCache stateCache = new ServerSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
            facesContext.getViewRoot().setViewId("view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
           
            for (Map.Entry<String, Object> entry : facesContext.getExternalContext().getSessionMap().entrySet())
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
View Full Code Here

    {
        servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);

        // Initialization
        setupRequest();
        StateCache stateCache = new ClientSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
          
            facesContext.getViewRoot().setViewId("view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view1.xhtml", savedToken);
           
            Assert.assertEquals(1, value);
           
            facesContext.getViewRoot().setViewId("view2.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 2);
        }
        finally
        {
            tearDownRequest();
        }

        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view2.xhtml", savedToken);
           
            Assert.assertEquals(2, value);
           
            facesContext.getViewRoot().setViewId("view2.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 3);
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            Object value = stateCache.restoreSerializedView(facesContext, "view1.xhtml", firstSavedToken);
           
            Assert.assertEquals(1, value);
        }
        finally
        {
View Full Code Here

    {
        servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);

        // Initialization
        setupRequest();
        StateCache stateCache = new ClientSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
          
            facesContext.getViewRoot().setViewId("/view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            // Note we are trying to restore restoring another different view with a token from the previous view.
            // It should return null and later throw ViewExpiredException
            // In client side state saving, the encoded viewId inside the state should be compared against the passed one.
            // as parameter.
            Object value = stateCache.restoreSerializedView(facesContext, "/view2.xhtml", firstSavedToken);
           
            Assert.assertNull(value);
        }
        finally
        {
            tearDownRequest();
        }
       
        try
        {
            setupRequest();
           
            // It should restore this:
            Object value = stateCache.restoreSerializedView(facesContext, "/view1.xhtml", firstSavedToken);
           
            Assert.assertEquals(1, value);
        }
        finally
        {
View Full Code Here

        servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
        servletContext.addInitParameter(ClientSideStateCacheImpl.INIT_PARAM_CLIENT_VIEW_STATE_TIMEOUT, "2");

        // Initialization
        setupRequest();
        StateCache stateCache = new ClientSideStateCacheImpl();
        tearDownRequest();
       
        Object savedToken;
        Object firstSavedToken;
       
        try
        {
            setupRequest();
          
            facesContext.getViewRoot().setViewId("/view1.xhtml");
            savedToken = stateCache.saveSerializedView(facesContext, 1);
            firstSavedToken = savedToken;
        }
        finally
        {
            tearDownRequest();
        }

        //Change timestamp to a previous date
        Long timestamp = (Long)((Object[])firstSavedToken)[TIMESTAMP_PARAM];
        ((Object[])firstSavedToken)[TIMESTAMP_PARAM] = timestamp.longValue() - 60000*3;
       
        try
        {
            setupRequest();
           
            // It should return null, because the timeStamp was changed to a previous date
            Object value = stateCache.restoreSerializedView(facesContext, "/view1.xhtml", firstSavedToken);
           
            Assert.assertNull(value);
        }
        finally
        {
View Full Code Here

TOP

Related Classes of org.apache.myfaces.application.StateCache

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.