Author: ppitonak(a)redhat.com
Date: 2011-01-12 07:35:17 -0500 (Wed, 12 Jan 2011)
New Revision: 20962
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jParam/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jParam/TestA4JParam.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JParamBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jParam/simple.xhtml
Log:
https://issues.jboss.org/browse/RFPL-1047
* added 4 tests for a4j:param
* a4j:param's sample improved
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JParamBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JParamBean.java 2011-01-12
09:55:56 UTC (rev 20961)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JParamBean.java 2011-01-12
12:35:17 UTC (rev 20962)
@@ -1,6 +1,6 @@
/*******************************************************************************
* JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -22,12 +22,14 @@
package org.richfaces.tests.metamer.bean;
import java.io.Serializable;
+import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
+import javax.faces.context.FacesContext;
-import org.ajax4jsf.component.UIActionParameter;
+import org.richfaces.component.UIParameter;
import org.richfaces.tests.metamer.Attributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,10 +57,11 @@
logger = LoggerFactory.getLogger(getClass());
logger.debug("initializing bean " + getClass().getName());
- attributes = Attributes.getComponentAttributesFromClass(UIActionParameter.class,
getClass());
+ attributes = Attributes.getComponentAttributesFromFacesConfig(UIParameter.class,
getClass());
attributes.setAttribute("name", "param");
attributes.setAttribute("noEscape", true);
+ attributes.get("noEscape").setType(Boolean.class);
attributes.setAttribute("value", "screen.width");
}
@@ -89,6 +92,11 @@
this.parameter = parameter;
}
+ public String getRequestParameter() {
+ Map<String, String> requestParameterMap =
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
+ return
requestParameterMap.get(attributes.get("name").getValue().toString());
+ }
+
public String reset() {
parameter = null;
return null;
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jParam/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jParam/simple.xhtml 2011-01-12
09:55:56 UTC (rev 20961)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jParam/simple.xhtml 2011-01-12
12:35:17 UTC (rev 20962)
@@ -6,7 +6,7 @@
<!--
JBoss, Home of Professional Open Source
-Copyright 2010, Red Hat, Inc. and individual contributors
+Copyright 2010-2011, Red Hat, Inc. and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
full listing of individual contributors.
@@ -43,13 +43,9 @@
<ui:define name="component">
- <a4j:commandButton id="button" value="Parametrized
Button" render="output" >
- <a4j:param id="a4jParam"
-
actionListener="#{a4jParamBean.attributes.actionListener}"
+ <a4j:commandButton id="button1" value="A4J Command
Button" render="output1,output2" >
+ <a4j:param id="a4jParam1"
assignTo="#{a4jParamBean.parameter}"
-
assignToBinding="#{a4jParamBean.attributes['assignToBinding'].value}"
-
converter="#{a4jParamBean.attributes['converter'].value}"
-
disable="#{a4jParamBean.attributes['disable'].value}"
name="#{a4jParamBean.attributes['name'].value}"
noEscape="#{a4jParamBean.attributes['noEscape'].value}"
rendered="#{a4jParamBean.attributes['rendered'].value}"
@@ -57,13 +53,24 @@
/>
</a4j:commandButton>
- <a4j:commandButton id="resetButton" value="Reset"
action="#{a4jParamBean.reset}" render="output"/>
+ <h:commandButton id="button2" value="H Command
Button">
+ <a4j:param id="a4jParam2"
+ assignTo="#{a4jParamBean.parameter}"
+
name="#{a4jParamBean.attributes['name'].value}"
+
noEscape="#{a4jParamBean.attributes['noEscape'].value}"
+
rendered="#{a4jParamBean.attributes['rendered'].value}"
+
value="#{a4jParamBean.attributes['value'].value}"
+ />
+ </h:commandButton>
+ <a4j:commandButton id="resetButton" value="Reset"
action="#{a4jParamBean.reset}" render="output1,output2"/>
+
+ <br/><br/>
+
+ output1: <a4j:outputPanel id="output1"
layout="inline">#{a4jParamBean.parameter}</a4j:outputPanel>
<br/>
+ output2: <a4j:outputPanel id="output2"
layout="inline">#{a4jParamBean.requestParameter}</a4j:outputPanel>
- <h:panelGroup id="output">
- Your parameter's value is #{a4jParamBean.parameter}
- </h:panelGroup>
</ui:define>
<ui:define name="outOfTemplateAfter">
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jParam/TestA4JParam.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jParam/TestA4JParam.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jParam/TestA4JParam.java 2011-01-12
12:35:17 UTC (rev 20962)
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.a4jParam;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/a4jParam/simple.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestA4JParam extends AbstractMetamerTest {
+
+ private JQueryLocator button1 = pjq("input[id$=button1]");
+ private JQueryLocator button2 = pjq("input[id$=button2]");
+ private JQueryLocator resetButton = pjq("input[id$=resetButton]");
+ private JQueryLocator output1 = pjq("span[id$=output1]");
+ private JQueryLocator output2 = pjq("span[id$=output2]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/a4jParam/simple.xhtml");
+ }
+
+ @Test
+ public void testParameter() {
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).click(button1);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ String screenWidth = selenium.getEval(new
JavaScript("window.screen.width"));
+
+ assertEquals(selenium.getText(output1), screenWidth, "Output 1 after
clicking on first button.");
+ assertEquals(selenium.getText(output2), screenWidth, "Output 2 after
clicking on first button.");
+
+ reqTime = selenium.getText(time);
+ guardXhr(selenium).click(resetButton);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output1), "", "Output 1 after
clicking on reset button.");
+ assertEquals(selenium.getText(output2), "", "Output 2 after
clicking on reset button.");
+
+ reqTime = selenium.getText(time);
+ guardHttp(selenium).click(button2);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output1), "screen.width", "Output 1
after clicking on second button.");
+ assertEquals(selenium.getText(output2), "screen.width", "Output 2
after clicking on second button.");
+ }
+
+ @Test
+ public void testName() {
+ selenium.type(pjq("input[id$=nameInput]"), "metamer");
+ selenium.waitForPageToLoad();
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).click(button1);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ String screenWidth = selenium.getEval(new
JavaScript("window.screen.width"));
+
+ assertEquals(selenium.getText(output1), screenWidth, "Output 1 after
clicking on first button.");
+ assertEquals(selenium.getText(output2), screenWidth, "Output 2 after
clicking on first button.");
+ }
+
+ @Test
+ public void testNoEscape() {
+ JQueryLocator renderedInput =
pjq("input[type=radio][name$=noEscapeInput][value=false]");
+ selenium.click(renderedInput);
+ selenium.waitForPageToLoad();
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).click(button1);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output1), "screen.width", "Output 1
after clicking on first button.");
+ assertEquals(selenium.getText(output2), "screen.width", "Output 2
after clicking on first button.");
+ }
+
+ @Test
+ public void testValue() {
+ selenium.type(pjq("input[id$=valueInput]"), "4+5");
+ selenium.waitForPageToLoad();
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).click(button1);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output1), "9", "Output 1 after
clicking on first button.");
+ assertEquals(selenium.getText(output2), "9", "Output 2 after
clicking on first button.");
+
+ reqTime = selenium.getText(time);
+ guardXhr(selenium).click(resetButton);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output1), "", "Output 1 after
clicking on reset button.");
+ assertEquals(selenium.getText(output2), "", "Output 2 after
clicking on reset button.");
+
+ reqTime = selenium.getText(time);
+ guardHttp(selenium).click(button2);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output1), "4+5", "Output 1 after
clicking on second button.");
+ assertEquals(selenium.getText(output2), "4+5", "Output 2 after
clicking on second button.");
+ }
+}
Property changes on:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jParam/TestA4JParam.java
___________________________________________________________________
Name: svn:keywords
+ Revision