You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/11/26 13:28:29 UTC

[myfaces] branch 2.3.x updated: MYFACES-4267 added unittest

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch 2.3.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/2.3.x by this push:
     new a42428f  MYFACES-4267 added unittest
a42428f is described below

commit a42428f63dc9e7797ae163e8aecfcd9fdb6153b1
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Nov 26 14:28:31 2018 +0100

    MYFACES-4267 added unittest
---
 .../view/facelets/stateless/StatelessTest.java     | 131 +++++++++++++++++++++
 .../view/facelets/stateless/stateless.xhtml        |  24 ++++
 .../myfaces/view/facelets/stateless/template.xhtml |  16 +++
 3 files changed, 171 insertions(+)

diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/stateless/StatelessTest.java b/impl/src/test/java/org/apache/myfaces/view/facelets/stateless/StatelessTest.java
new file mode 100644
index 0000000..18e5eac
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/stateless/StatelessTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.stateless;
+
+import javax.faces.application.StateManager;
+import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
+import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
+import org.apache.myfaces.shared.config.MyfacesConfig;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ *
+ * @author lu4242
+ */
+public class StatelessTest extends AbstractMyFacesRequestTestCase
+{
+
+    @Override
+    protected boolean isScanAnnotations()
+    {
+        return true;
+    }
+
+    @Override
+    protected void setUpWebConfigParams() throws Exception
+    {
+        super.setUpWebConfigParams();
+        servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets.stateless");
+        servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
+        servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", "true");
+        servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS, "auto");
+        servletContext.addInitParameter("org.apache.myfaces.STRICT_JSF_2_REFRESH_TARGET_AJAX", "true");
+    }
+    
+    @Test
+    public void postWithoutPrependFormId() throws Exception
+    {
+        startViewRequest("/stateless.xhtml");
+        processLifecycleExecuteAndRender();
+        
+        Assert.assertTrue(facesContext.getViewRoot().isTransient());
+        
+        UIComponent form = facesContext.getViewRoot().findComponent("form1");
+        UIComponent formButton = facesContext.getViewRoot().findComponent("form1:smt");
+        
+        client.submit(formButton);
+        
+        processLifecycleExecuteAndRender();
+        String text = getRenderedContent(facesContext);
+
+        endRequest();
+    }
+    
+    @Test
+    public void postAjaxWithoutPrependFormId() throws Exception
+    {
+        startViewRequest("/stateless.xhtml");
+        processLifecycleExecuteAndRender();
+        
+        Assert.assertTrue(facesContext.getViewRoot().isTransient());
+        
+        UIComponent form = facesContext.getViewRoot().findComponent("form1");
+        UIComponent formButton = facesContext.getViewRoot().findComponent("form1:smtAjax");
+        
+        client.ajax(formButton, "action", formButton.getClientId(facesContext), form.getClientId(facesContext), true);
+        
+        processLifecycleExecuteAndRender();
+        String text = getRenderedContent(facesContext);
+
+        endRequest();
+    }
+    
+    @Test
+    public void postWithPrependFormId() throws Exception
+    {
+        startViewRequest("/stateless.xhtml");
+        processLifecycleExecuteAndRender();
+        
+        Assert.assertTrue(facesContext.getViewRoot().isTransient());
+        
+        UIComponent form = facesContext.getViewRoot().findComponent("form2");
+        UIComponent formButton = facesContext.getViewRoot().findComponent("form2:smt");
+        
+        client.submit(formButton);
+        
+        processLifecycleExecuteAndRender();
+        String text = getRenderedContent(facesContext);
+
+        endRequest();
+    }
+
+    @Test
+    public void postAjaxWithPrependFormId() throws Exception
+    {
+        startViewRequest("/stateless.xhtml");
+        processLifecycleExecuteAndRender();
+        
+        Assert.assertTrue(facesContext.getViewRoot().isTransient());
+        
+        UIComponent form = facesContext.getViewRoot().findComponent("form2");
+        UIComponent formButton = facesContext.getViewRoot().findComponent("form2:smtAjax");
+        
+        client.ajax(formButton, "action", formButton.getClientId(facesContext), form.getClientId(facesContext), true);
+        
+        processLifecycleExecuteAndRender();
+        String text = getRenderedContent(facesContext);
+
+        endRequest();
+    }
+    
+    
+}
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/stateless.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/stateless.xhtml
new file mode 100644
index 0000000..6388315
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/stateless.xhtml
@@ -0,0 +1,24 @@
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:c="http://java.sun.com/jsp/jstl/core"
+                xmlns:h="http://xmlns.jcp.org/jsf/html"
+                xmlns:f="http://xmlns.jcp.org/jsf/core"
+                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+                template="template.xhtml">
+
+    <ui:define name="body">
+
+        <h:form id="form1" prependId="false">
+            <h:commandButton id="smt" value="Submit" />
+            <h:commandButton id="smtAjax" value="Submit">
+                <f:ajax render="@form" execute="@this" />
+            </h:commandButton>
+        </h:form>
+
+        <h:form id="form2">
+            <h:commandButton id="smt" value="Submit" />
+            <h:commandButton id="smtAjax" value="Submit">
+                <f:ajax render="@form" execute="@this" />
+            </h:commandButton>
+        </h:form>
+    </ui:define>
+</ui:composition>
\ No newline at end of file
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/template.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/template.xhtml
new file mode 100644
index 0000000..92b5620
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/stateless/template.xhtml
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:c="http://java.sun.com/jsp/jstl/core"
+      xmlns:h="http://xmlns.jcp.org/jsf/html"
+      xmlns:f="http://xmlns.jcp.org/jsf/core"
+      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
+
+    <f:view transient="true">
+        <h:head>
+            
+        </h:head>
+        <h:body>
+            <ui:insert name="body" />
+        </h:body>
+    </f:view>
+</html>
\ No newline at end of file