You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2018/05/08 12:48:20 UTC
[myfaces] 17/28: copy to move history
This is an automated email from the ASF dual-hosted git repository.
deki pushed a commit to branch 2.1.x-client-window
in repository https://gitbox.apache.org/repos/asf/myfaces.git
commit e8c627b9e981a098bed4f1823785bce95209d8aa
Author: Leonardo Uribe <lu...@apache.org>
AuthorDate: Fri Nov 16 03:17:03 2012 +0000
copy to move history
---
.../viewstate/ClientSideStateCacheTest.java | 211 +++++++++++++++++++++
1 file changed, 211 insertions(+)
diff --git a/impl/src/test/java/org/apache/myfaces/application/viewstate/ClientSideStateCacheTest.java b/impl/src/test/java/org/apache/myfaces/application/viewstate/ClientSideStateCacheTest.java
new file mode 100644
index 0000000..a601f3b
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/application/viewstate/ClientSideStateCacheTest.java
@@ -0,0 +1,211 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.renderkit;
+
+import javax.faces.application.StateManager;
+import org.apache.myfaces.application.StateCache;
+import org.apache.myfaces.test.base.junit4.AbstractJsfConfigurableMultipleRequestsTestCase;
+import org.junit.Test;
+import org.testng.Assert;
+
+/**
+ *
+ * @author lu4242
+ */
+public class ClientSideStateCacheTest extends AbstractJsfConfigurableMultipleRequestsTestCase
+{
+
+ private static final int TIMESTAMP_PARAM = 2;
+
+ @Test
+ public void testSaveRestoreState() throws Exception
+ {
+ 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
+ {
+ tearDownRequest();
+ }
+ }
+
+ @Test
+ public void testSaveRestoreStateWrongViewId() throws Exception
+ {
+ 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
+ {
+ tearDownRequest();
+ }
+
+ }
+
+ @Test
+ public void testSaveRestoreStateClientTimeout() throws Exception
+ {
+ 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
+ {
+ tearDownRequest();
+ }
+ }
+
+
+}
--
To stop receiving notification emails like this one, please contact
deki@apache.org.