Author: andrei_exadel
Date: 2008-06-24 08:33:22 -0400 (Tue, 24 Jun 2008)
New Revision: 9181
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JActionParam.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/actionParam/
trunk/test-applications/seleniumTest/src/main/webapp/pages/actionParam/actionParam.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxActionParameterTest.java
Modified:
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
Log:
actionParameter test
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JActionParam.java
===================================================================
---
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JActionParam.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JActionParam.java 2008-06-24
12:33:22 UTC (rev 9181)
@@ -0,0 +1,58 @@
+package org.ajax4jsf.bean;
+
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+
+import com.sun.faces.context.FacesContextImpl;
+
+public class A4JActionParam {
+
+ private static final String PARAMETER_NAME = "param";
+
+ private static final String PARAMETER_VALUE = "Action Parameter";
+
+ private String parameterName;
+
+ private String parameterValue;
+
+ public void listener(ActionEvent event) {
+ FacesContext context = FacesContextImpl.getCurrentInstance();
+ Map<String, String> p = context.getExternalContext().getRequestParameterMap();
+ if (p.get(PARAMETER_NAME) != null &&
p.get(PARAMETER_NAME).equals(PARAMETER_VALUE)) {
+ parameterName = PARAMETER_NAME;
+ }
+ }
+
+ /**
+ * @return the parameter
+ */
+ public String getParameter() {
+ return (parameterName != null || parameterValue!=null) ? (parameterName +
"='" + parameterValue + "'") : "";
+ }
+
+ /**
+ * @param parameter the parameter to set
+ */
+ public void setParameter(String parameter) {
+ ;
+ }
+
+ /**
+ * @return the parameterValue
+ */
+ public String getParameterValue() {
+ return parameterValue;
+ }
+
+ /**
+ * @param parameterValue the parameterValue to set
+ */
+ public void setParameterValue(String parameterValue) {
+ this.parameterValue = parameterValue;
+ }
+
+
+
+}
Modified: trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-06-24
12:26:06 UTC (rev 9180)
+++
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-06-24
12:33:22 UTC (rev 9181)
@@ -145,4 +145,9 @@
<managed-bean-class>org.ajax4jsf.bean.AjaxListenerTestBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
+ <managed-bean>
+ <managed-bean-name>actionParam</managed-bean-name>
+ <managed-bean-class>org.ajax4jsf.bean.A4JActionParam</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
</faces-config>
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/src/main/webapp/pages/actionParam/actionParam.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/pages/actionParam/actionParam.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/webapp/pages/actionParam/actionParam.xhtml 2008-06-24
12:33:22 UTC (rev 9181)
@@ -0,0 +1,32 @@
+<!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:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+<ui:composition template="#{templateBean.template}">
+ <ui:define name="style">
+
+ </ui:define>
+ <ui:define name="component">
+
+ <table style="width: 600px"><tr>
+ <td><b>Parameter:</b></td>
+ <td><h:outputText style="color: green"
value="#{actionParam.parameter}"
id="_parameter"></h:outputText></td>
+ </tr></table>
+ <h:form id="_form1">
+ <a4j:commandLink value="Ajax Submit" id="ajaxSubmit"
reRender="_parameter" actionListener="#{actionParam.listener}">
+ <a4j:actionparam assignTo="#{actionParam.parameterValue}"
name="param" value="Action Parameter"></a4j:actionparam>
+ </a4j:commandLink>
+ </h:form>
+
+ <h:form id="_form2">
+ <h:commandLink value="Html Submit" id="htmlSubmit"
actionListener="#{actionParam.listener}">
+ <a4j:actionparam assignTo="#{actionParam.parameterValue}"
name="param" value="Action Parameter"></a4j:actionparam>
+ </h:commandLink>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxActionParameterTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxActionParameterTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxActionParameterTest.java 2008-06-24
12:33:22 UTC (rev 9181)
@@ -0,0 +1,90 @@
+package org.richfaces.testng;
+
+import org.ajax4jsf.template.Template;
+import org.richfaces.RichSeleniumTest;
+import org.richfaces.SeleniumTestBase;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+public class AjaxActionParameterTest extends SeleniumTestBase implements
+ RichSeleniumTest {
+
+ public AjaxActionParameterTest() {
+ super("http", "localhost", serverPort);
+ }
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeMethod
+ @Parameters( { "browser", "filterPrefix" })
+ public void startSelenium(String browser, String filterPrefix) {
+ super.startSelenium(browser, filterPrefix);
+ }
+
+ @BeforeMethod
+ @Parameters( { "loadStyleStrategy", "loadScriptStrategy" })
+ protected void loadConfiguration(String loadStyleStrategy,
+ String loadScriptStrategy) throws Exception {
+ super.loadConfiguration(loadStyleStrategy, loadScriptStrategy);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterMethod(alwaysRun = true)
+ public void stopSelenium() {
+ super.stopSelenium();
+ }
+
+ @Test
+ public void testAjaxCommandLinkComponent() throws Exception {
+ _testAjaxCommandLinkComponent(Template.SIMPLE);
+ _testAjaxCommandLinkComponent(Template.DATA_TABLE);
+ }
+
+ private void _testAjaxCommandLinkComponent(Template template) {
+ renderPage(template);
+ String parentId = getParentId();
+
+ String paramID = parentId + "_parameter";
+ String ajaxButttonID = parentId + "_form1:ajaxSubmit";
+ String htmlButttonID = parentId + "_form2:htmlSubmit";
+
+ clickById(ajaxButttonID);
+ waitForAjaxCompletion();
+
+ String parameter = getTextById(paramID);
+ if (parameter == null) {
+ writeStatus("<a4j:actionParameter> failed. Parameter has been not sent with
ajax request.");
+ Assert.fail("<a4j:actionParameter> failed. Parameter has been not sent with
ajax request.");
+ } else if (parameter != null &&
parameter.equals("param='null'")) {
+ writeStatus("<a4j:actionParameter> failed. Parameter value has been not
assigned to bean");
+ Assert.fail("<a4j:actionParameter> failed. Parameter value has been not
assigned to bean");
+ } else {
+ writeStatus("<a4j:actionParameter> passed successfully");
+ }
+
+ clickCommandAndWait(htmlButttonID);
+
+ parameter = getTextById(paramID);
+ if (parameter == null) {
+ writeStatus("<a4j:actionParameter> failed. Parameter has been not sent with
ajax request.");
+ Assert.fail("<a4j:actionParameter> failed. Parameter has been not sent with
ajax request.");
+ } else if (parameter != null &&
parameter.equals("param='null'")) {
+ writeStatus("<a4j:actionParameter> failed. Parameter value has been not
assigned to bean");
+ Assert.fail("<a4j:actionParameter> failed. Parameter value has been not
assigned to bean");
+ } else {
+ writeStatus("<a4j:actionParameter> passed successfully");
+ }
+ }
+
+ @Override
+ public String getTestUrl() {
+ return "pages/actionParam/actionParam.xhtml";
+ }
+
+}