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/01/19 13:12:15 UTC
[myfaces] branch master updated: MYFACES-4378 added tests
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 0b64161 MYFACES-4378 added tests
0b64161 is described below
commit 0b641610962fe5829bb95fba65f38a5a798de2fe
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Tue Jan 19 14:12:05 2021 +0100
MYFACES-4378 added tests
---
.../pss/acid/AcidMyFacesRequestTestCase.java | 22 ++++++++++
.../facelets/pss/acid/component/OnloadScript.java | 48 ++++++++++++++++++++++
.../pss/acid/WEB-INF/testcomponent.taglib.xml | 13 ++++--
.../view/facelets/pss/acid/onloadscript.xhtml | 36 ++++++++++++++++
4 files changed, 116 insertions(+), 3 deletions(-)
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java b/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java
index 8a55d3e..3f1b1f7 100644
--- a/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java
@@ -2201,4 +2201,26 @@ public class AcidMyFacesRequestTestCase extends AbstractMyFacesCDIRequestTestCas
endRequest();
}
+
+ @Test
+ public void testOnloadScript() throws Exception
+ {
+ startViewRequest("/onloadscript.xhtml");
+ processLifecycleExecuteAndRender();
+
+ MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
+ Assert.assertTrue(new String(writer2.content()).contains("onloadScript successfully executed"));
+ Assert.assertTrue(new String(writer2.content()).contains("Remove this c:if and it will work."));
+
+ UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
+ client.submit(button);
+ processLifecycleExecuteAndRender();
+
+ writer2 = (MockPrintWriter) response.getWriter();
+ Assert.assertTrue(new String(writer2.content()).contains("onloadScript successfully executed"));
+ Assert.assertTrue(new String(writer2.content()).contains("Remove this c:if and it will work."));
+
+
+ endRequest();
+ }
}
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/OnloadScript.java b/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/OnloadScript.java
new file mode 100644
index 0000000..a8063c5
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/OnloadScript.java
@@ -0,0 +1,48 @@
+/*
+ * 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.pss.acid.component;
+
+import jakarta.faces.component.FacesComponent;
+import jakarta.faces.component.UIOutput;
+import jakarta.faces.component.UIViewRoot;
+import jakarta.faces.context.FacesContext;
+import jakarta.faces.event.ComponentSystemEvent;
+import jakarta.faces.event.ListenerFor;
+import jakarta.faces.event.PostAddToViewEvent;
+
+@FacesComponent(value = "com.myapp.OnloadScript")
+@ListenerFor(systemEventClass = PostAddToViewEvent.class)
+public class OnloadScript extends UIOutput {
+
+ public OnloadScript() {
+ setRendererType("javax.faces.resource.Script");
+ }
+
+ @Override
+ public void processEvent(ComponentSystemEvent event) {
+ FacesContext context = event.getFacesContext();
+ UIViewRoot view = context.getViewRoot();
+
+ if (context.isPostback()
+ ? !view.getComponentResources(context, "body").contains(this)
+ : event instanceof PostAddToViewEvent) {
+ view.addComponentResource(context, this, "body");
+ }
+ }
+}
\ No newline at end of file
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/WEB-INF/testcomponent.taglib.xml b/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/WEB-INF/testcomponent.taglib.xml
index 4e9d3c1..0132e99 100644
--- a/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/WEB-INF/testcomponent.taglib.xml
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/WEB-INF/testcomponent.taglib.xml
@@ -24,6 +24,13 @@
</tag>
<tag>
+ <tag-name>onloadScript</tag-name>
+ <component>
+ <component-type>com.myapp.OnloadScript</component-type>
+ </component>
+ </tag>
+
+ <tag>
<tag-name>togglecomponent</tag-name>
<component>
<component-type>com.myapp.UIToggleComponent</component-type>
@@ -64,14 +71,14 @@
<component-type>com.myapp.UISelfRenderComponent</component-type>
</component>
</tag>
-
+
<tag>
<tag-name>rdcomponent</tag-name>
<component>
<component-type>com.myapp.UIRDComponent</component-type>
</component>
</tag>
-
+
<tag>
<tag-name>addSimpleComponentVDL</tag-name>
<component>
@@ -99,7 +106,7 @@
<component-type>com.myapp.UIAddSimpleCCVDL</component-type>
</component>
</tag>
-
+
<tag>
<tag-name>dynamicFormComponent</tag-name>
<component>
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/onloadscript.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/onloadscript.xhtml
new file mode 100644
index 0000000..ebe617e
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/onloadscript.xhtml
@@ -0,0 +1,36 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!--
+ 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.
+-->
+<!DOCTYPE html>
+<html lang="en"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://xmlns.jcp.org/jsf/html"
+ xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
+ xmlns:test="http://testcomponent">
+ <h:body>
+ <test:onloadScript>
+ document.getElementById('result').innerHTML='onloadScript successfully executed';
+ </test:onloadScript>
+
+ <h:form>
+ <h:commandButton id="postback" value="non-ajax postback" />
+ </h:form>
+
+ <c:if test="#{true}">
+ Remove this c:if and it will work.
+ </c:if>
+
+ <div id="result" />
+ </h:body>
+</html>