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 2021/04/19 09:57:53 UTC
[myfaces] branch master updated: MYFACES-4396 unittests
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new 7418a20 MYFACES-4396 unittests
7418a20 is described below
commit 7418a20ecf953449e82aa159c6a6aff55ae4695b
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Apr 19 11:57:46 2021 +0200
MYFACES-4396 unittests
---
.../myfaces/view/facelets/FaceletTestCase.java | 16 ++++++++++++
.../CompositeComponentClientBehaviorTestCase.java | 29 +++++++++++++++++++++
.../testSimpleClientBehaviorProcessThisInCC.xhtml | 30 ++++++++++++++++++++++
3 files changed, 75 insertions(+)
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/FaceletTestCase.java b/impl/src/test/java/org/apache/myfaces/view/facelets/FaceletTestCase.java
index a137c6a..07525b0 100644
--- a/impl/src/test/java/org/apache/myfaces/view/facelets/FaceletTestCase.java
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/FaceletTestCase.java
@@ -37,6 +37,7 @@ import jakarta.faces.component.UIViewRoot;
import jakarta.faces.context.FacesContext;
import jakarta.faces.context.ResponseWriter;
import jakarta.faces.render.RenderKitFactory;
+import java.io.IOException;
import org.apache.myfaces.application.ApplicationFactoryImpl;
import org.apache.myfaces.application.ViewHandlerImpl;
@@ -57,6 +58,7 @@ import org.apache.myfaces.util.lang.ClassUtils;
import org.apache.myfaces.spi.FacesConfigurationProviderFactory;
import org.apache.myfaces.test.base.junit.AbstractJsfConfigurableMockTestCase;
import org.apache.myfaces.test.el.MockExpressionFactory;
+import org.apache.myfaces.test.mock.MockResponseWriter;
import org.apache.myfaces.test.mock.visit.MockVisitContextFactory;
import org.apache.myfaces.view.facelets.impl.FaceletCacheFactoryImpl;
import org.apache.myfaces.view.facelets.mock.MockViewDeclarationLanguageFactory;
@@ -209,17 +211,20 @@ public abstract class FaceletTestCase extends AbstractJsfConfigurableMockTestCas
ViewHandlerImpl viewHandler = (ViewHandlerImpl) facesContext.getApplication().getViewHandler();
viewHandler.setViewIdSupport(new ViewIdSupport(facesContext){
+ @Override
public String calculateActionURL(FacesContext facesContext,
String viewId)
{
return viewId;
}
+ @Override
public String deriveLogicalViewId(FacesContext context, String viewId)
{
return viewId;
}
+ @Override
public String deriveViewId(FacesContext context, String viewId)
{
return viewId;
@@ -401,4 +406,15 @@ public abstract class FaceletTestCase extends AbstractJsfConfigurableMockTestCas
}
}
+ protected String render(UIViewRoot root) throws IOException
+ {
+ StringWriter sw = new StringWriter();
+ MockResponseWriter mrw = new MockResponseWriter(sw);
+ facesContext.setResponseWriter(mrw);
+
+ root.encodeAll(facesContext);
+ sw.flush();
+
+ return sw.toString();
+ }
}
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentClientBehaviorTestCase.java b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentClientBehaviorTestCase.java
index 9cbd5a8..b0abaa9 100644
--- a/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentClientBehaviorTestCase.java
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentClientBehaviorTestCase.java
@@ -26,6 +26,7 @@ import jakarta.faces.component.UIViewRoot;
import org.apache.myfaces.view.facelets.FaceletTestCase;
import org.apache.myfaces.view.facelets.bean.HelloWorld;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
public class CompositeComponentClientBehaviorTestCase extends FaceletTestCase
@@ -271,4 +272,32 @@ public class CompositeComponentClientBehaviorTestCase extends FaceletTestCase
//sw.flush();
//System.out.print(sw.toString());
}
+
+ @Test
+ @Ignore
+ public void testSimpleClientBehaviorProcessThisInCC() throws Exception
+ {
+ HelloWorld helloWorld = new HelloWorld();
+
+ facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
+ helloWorld);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ vdl.buildView(facesContext, root, "testSimpleClientBehaviorProcessThisInCC.xhtml");
+
+ UIComponent form = root.findComponent("form");
+ Assert.assertNotNull(form);
+ UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
+ Assert.assertNotNull(compositeComponent);
+ UICommand button = (UICommand) compositeComponent.findComponent("button");
+ Assert.assertNotNull(button);
+ Assert.assertNotNull(button.getClientBehaviors().get("action"));
+ Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
+
+ String content = render(root);
+
+ Assert.assertTrue(content.contains("myfaces.ab(this,event,'action','form:cc'")
+ || content.contains("myfaces.ab(this,event,'action','@this'"));
+ }
+
}
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleClientBehaviorProcessThisInCC.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleClientBehaviorProcessThisInCC.xhtml
new file mode 100644
index 0000000..b4e2385
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testSimpleClientBehaviorProcessThisInCC.xhtml
@@ -0,0 +1,30 @@
+<!--
+ 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: defineInclude.xml 804043 2009-08-13 22:08:44Z lu4242 $
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:testComposite="http://java.sun.com/jsf/composite/testComposite">
+<head>
+</head>
+<body>
+<h:form id="form">
+ <testComposite:simpleClientBehavior id="cc">
+ <f:ajax execute="@this" event="pushButton"/>
+ </testComposite:simpleClientBehavior>
+</h:form>
+</body>
+</html>
\ No newline at end of file