You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/05/11 03:28:53 UTC

svn commit: r1101720 [2/2] - in /myfaces/core/trunk: ./ impl/src/main/java/org/apache/myfaces/application/ impl/src/main/java/org/apache/myfaces/application/jsp/ impl/src/main/java/org/apache/myfaces/view/facelets/ impl/src/test/java/org/apache/myfaces...

Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/StateManagerWithFaceletsTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/StateManagerWithFaceletsTest.java?rev=1101720&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/StateManagerWithFaceletsTest.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/StateManagerWithFaceletsTest.java Wed May 11 01:28:53 2011
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.view.facelets;
+
+import javax.faces.application.StateManager;
+import javax.faces.component.UIViewRoot;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.render.ResponseStateManager;
+
+import org.apache.myfaces.application.StateManagerImpl;
+import org.apache.myfaces.renderkit.html.HtmlResponseStateManager;
+import org.apache.myfaces.shared_impl.util.StateUtils;
+import org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory;
+import org.apache.myfaces.test.mock.MockRenderKit;
+import org.junit.Test;
+import org.testng.Assert;
+
+public class StateManagerWithFaceletsTest extends FaceletMultipleRequestsTestCase
+{
+
+    @Override
+    protected void setUpApplication() throws Exception
+    {
+        super.setUpApplication();
+        
+        application.setStateManager(new StateManagerImpl());
+    }
+
+    @Override
+    protected void setUpServletContextAndSession() throws Exception
+    {
+        super.setUpServletContextAndSession();
+        
+        servletContext.addInitParameter(StateManager.PARTIAL_STATE_SAVING_PARAM_NAME, "true");
+        servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_SERVER);
+    }
+
+    @Test
+    public void testWriteAndRestoreState() throws Exception
+    {
+        String viewStateParam = null;
+        try
+        {
+            setupRequest();
+            
+            UIViewRoot root = facesContext.getViewRoot();
+            root.setViewId("/simpleTree.xhtml");
+            vdl.buildView(facesContext, root, "/simpleTree.xhtml");
+            
+            application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
+            
+            viewStateParam = application.getStateManager().getViewState(facesContext);
+            
+        }
+        finally
+        {
+            tearDownRequest();
+        }
+        
+        try
+        {
+            setupRequest();
+            
+            request.addParameter(ResponseStateManager.VIEW_STATE_PARAM, viewStateParam);
+    
+            UIViewRoot restoredViewRoot = application.getStateManager().restoreView(facesContext, "/simpleTree.xhtml", RenderKitFactory.HTML_BASIC_RENDER_KIT);
+            
+            Assert.assertNotNull(restoredViewRoot);
+        }
+        finally
+        {
+            tearDownRequest();
+        }
+    }
+    
+    @Test
+    public void testWriteAndRestoreStateWithMyFacesRSM() throws Exception
+    {
+        String viewStateParam = null;
+        
+        ((MockRenderKit)renderKit).setResponseStateManager(new HtmlResponseStateManager());
+        StateUtils.initSecret(servletContext);
+        servletContext.setAttribute(StateUtils.SERIAL_FACTORY, new DefaultSerialFactory());
+
+        try
+        {
+            setupRequest();
+            
+            UIViewRoot root = facesContext.getViewRoot();
+            root.setViewId("/simpleTree.xhtml");
+            vdl.buildView(facesContext, root, "/simpleTree.xhtml");
+            
+            application.getStateManager().writeState(facesContext, application.getStateManager().saveView(facesContext));
+            
+            viewStateParam = application.getStateManager().getViewState(facesContext);
+            
+        }
+        finally
+        {
+            tearDownRequest();
+        }
+        
+        try
+        {
+            setupRequest();
+            
+            request.addParameter(ResponseStateManager.VIEW_STATE_PARAM, viewStateParam);
+    
+            UIViewRoot restoredViewRoot = application.getStateManager().restoreView(facesContext, "/simpleTree.xhtml", RenderKitFactory.HTML_BASIC_RENDER_KIT);
+            
+            Assert.assertNotNull(restoredViewRoot);
+        }
+        finally
+        {
+            tearDownRequest();
+        }
+    }
+
+}

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/simpleTree.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/simpleTree.xhtml?rev=1101720&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/simpleTree.xhtml (added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/simpleTree.xhtml Wed May 11 01:28:53 2011
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!--
+ 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.
+
+ $Id: component.xhtml,v 1.4 2008/07/13 19:01:37 rlubke Exp $
+-->
+<html xmlns="http://www.w3.org/1999/xhtml"
+	  xmlns:f="http://java.sun.com/jsf/core"
+	  xmlns:h="http://java.sun.com/jsf/html">
+	<head>
+		<title>Untitled Document</title>
+	</head>
+	<body>
+	<h:form>
+		<span>
+			<h:inputText value="${foo.bar}"/>
+		</span>
+		Some More Text
+	</h:form>
+	</body>
+</html>

Modified: myfaces/core/trunk/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/pom.xml?rev=1101720&r1=1101719&r2=1101720&view=diff
==============================================================================
--- myfaces/core/trunk/pom.xml (original)
+++ myfaces/core/trunk/pom.xml Wed May 11 01:28:53 2011
@@ -462,7 +462,7 @@
             <dependency>
                 <groupId>org.apache.myfaces.test</groupId>
                 <artifactId>myfaces-test20</artifactId>
-                <version>1.0.2</version>
+                <version>1.0.3-SNAPSHOT</version>
                 <scope>test</scope>
             </dependency>