[richfaces-svn-commits] JBoss Rich Faces SVN: r9242 - in trunk/test-applications/seleniumTest/src: main/webapp/WEB-INF and 3 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Jun 26 10:18:54 EDT 2008


Author: andrei_exadel
Date: 2008-06-26 10:18:54 -0400 (Thu, 26 Jun 2008)
New Revision: 9242

Added:
   trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JSupport.java
   trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxSupport/
   trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxSupport/ajaxSupport.xhtml
   trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxSupportTest.java
Modified:
   trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
Log:
ajax support test

Added: trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JSupport.java
===================================================================
--- trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JSupport.java	                        (rev 0)
+++ trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JSupport.java	2008-06-26 14:18:54 UTC (rev 9242)
@@ -0,0 +1,52 @@
+package org.ajax4jsf.bean;
+
+import javax.faces.event.ActionEvent;
+
+public class A4JSupport {
+	
+	private String data = null;
+	
+	public static class Messages {
+		public static final String FOR_LINK = "Link onclick passed";
+		
+		public static final String FOR_CHECKBOX = "Checkbox onchange passed";
+		
+		public static final String FOR_COMMAND = "Command onclick passed";
+		
+		public static final String FOR_SUBMIT = "Default listener";
+		
+		public static final String NO_DATA = "nodata";
+	}
+	
+	public void linkListener (ActionEvent event) {
+		data = Messages.FOR_LINK;
+	}
+	
+	public void checkBoxListener (ActionEvent event) {
+		data = Messages.FOR_CHECKBOX;
+	}
+	
+	public void commandListener (ActionEvent event) {
+		data = Messages.FOR_COMMAND;
+	}
+
+	public void listener (ActionEvent event) {
+		data = Messages.FOR_SUBMIT;
+	}
+
+
+	/**
+	 * @return the data
+	 */
+	public String getData() {
+		return (data != null) ? data : Messages.NO_DATA;
+	}
+
+	/**
+	 * @param data the data to set
+	 */
+	public void setData(String data) {
+		this.data = data;
+	}
+	
+}

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-26 14:07:34 UTC (rev 9241)
+++ trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml	2008-06-26 14:18:54 UTC (rev 9242)
@@ -155,4 +155,9 @@
 		<managed-bean-class>org.ajax4jsf.bean.A4JActionParam</managed-bean-class>
 		<managed-bean-scope>request</managed-bean-scope>
 	</managed-bean>
+	<managed-bean>
+		<managed-bean-name>ajaxSupport</managed-bean-name>
+		<managed-bean-class>org.ajax4jsf.bean.A4JSupport</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/ajaxSupport/ajaxSupport.xhtml
===================================================================
--- trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxSupport/ajaxSupport.xhtml	                        (rev 0)
+++ trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxSupport/ajaxSupport.xhtml	2008-06-26 14:18:54 UTC (rev 9242)
@@ -0,0 +1,66 @@
+<!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">
+		<h:form id="_form">
+			<table>
+				<tr>
+					<td><i>ReRender Area:</i></td>
+					<td>
+						<h:outputText style="font-weight: bold; border: 1px solid green" value="#{ajaxSupport.data}" id="data"></h:outputText>
+					</td>
+				</tr>
+			</table>
+				
+				<br/>
+				<br/>
+				
+			<table border="1" cellpadding="2" cellspacing="0">
+				<tr>
+					<th>Controls</th><th>Event</th>
+				</tr>
+				<tr>
+					<td>
+						<h:outputLink value="#" id="link" style="text-decoration: none; color: blue;">
+							<h:outputText value="Link"></h:outputText>
+							<a4j:support event="onclick" reRender="data" actionListener="#{ajaxSupport.linkListener}"></a4j:support>
+						</h:outputLink>
+					</td>
+					<td>
+						onclick
+					</td>
+				</tr>
+				<tr>
+					<td>
+						<h:selectBooleanCheckbox value="true" id="checkbox">
+							<a4j:support event="onchange" reRender="data" actionListener="#{ajaxSupport.checkBoxListener}"></a4j:support>
+						</h:selectBooleanCheckbox>
+					</td>
+					<td>
+						onchange
+					</td>
+				</tr>
+				<tr>
+					<td>
+						<h:commandLink value="Submit" id="command" actionListener="#{ajaxSupport.listener}"  style="text-decoration: none; color: blue;">
+							<a4j:support event="onclick"  actionListener="#{ajaxSupport.commandListener}" reRender="data" disableDefault="true" requestDelay="2000"></a4j:support>
+						</h:commandLink>
+					</td>
+					<td>
+						onclick
+					</td>
+				</tr>
+			</table>
+		</h:form>
+	</ui:define>
+</ui:composition>
+</html>
\ No newline at end of file

Added: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxSupportTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxSupportTest.java	                        (rev 0)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxSupportTest.java	2008-06-26 14:18:54 UTC (rev 9242)
@@ -0,0 +1,110 @@
+/**
+ * 
+ */
+package org.richfaces.testng;
+
+import org.ajax4jsf.bean.A4JSupport;
+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;
+
+/**
+ * @author Andrey Markavstov
+ *
+ */
+public class AjaxSupportTest extends SeleniumTestBase implements
+		RichSeleniumTest {
+
+	public AjaxSupportTest() {
+		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 testAjaxSupportComponent() throws Exception {
+		_testAjaxSupportComponent(Template.SIMPLE);
+	}
+	
+	private void _testAjaxSupportComponent(Template template) {
+		renderPage(template);
+		String parentId = getParentId() + "_form:";
+		
+		String dataId = parentId + "data"; 
+		String linkId = parentId + "link";
+		String checkBoxId = parentId + "checkbox";
+		String command = parentId + "command";
+		
+		clickById(linkId);
+		waitForAjaxCompletion();
+		String data = getTextById(dataId);
+		checkMessage(data, A4JSupport.Messages.FOR_LINK, "'onclick' ajax support for link[id='_form:link'] failed.", A4JSupport.Messages.FOR_LINK + " successful");
+		
+		clickById(checkBoxId);
+		waitForAjaxCompletion();
+		data = getTextById(dataId);
+		checkMessage(data, A4JSupport.Messages.FOR_CHECKBOX, "'onchange' ajax support for checkbox[id='_form:checkbox'] failed.", A4JSupport.Messages.FOR_CHECKBOX+ " successful");
+		
+		clickById(command);
+		pause(1000, command);
+		if (!data.equals(getTextById(dataId))) {
+			writeStatus("<a4j:support failed. 'requestDelay' attribute does not work.");
+			Assert.fail("<a4j:support failed. 'requestDelay' attribute does not work.");
+		}
+		waitForAjaxCompletion();
+		data = getTextById(dataId);
+		checkMessage(data, A4JSupport.Messages.FOR_COMMAND, "'onclick' ajax support for command link[id='_form:command'] failed.", A4JSupport.Messages.FOR_COMMAND+ " successful");
+		
+		if (A4JSupport.Messages.FOR_SUBMIT.equals(data)) {
+			writeStatus("<a4j:support failed. 'disableDefault' attribute does not work");
+			Assert.fail("<a4j:support failed. 'disableDefault' attribute does not work.");
+		}
+		
+		
+	}
+
+	private void checkMessage(String data, String message, String errorMessage, String okMessage) {
+		if (message.equals(data)) {
+			writeStatus(okMessage);
+		}else if (A4JSupport.Messages.NO_DATA.equals(data)) {
+			writeStatus(errorMessage + " Caused by: action listener for <a4j:support> skipped", true);
+			Assert.fail(errorMessage + " Caused by: action listener for <a4j:support> skipped");
+		}else if ("".equals(data)) {
+			writeStatus(errorMessage + "Caused by: no ajax request has been sent.", true);
+			Assert.fail(errorMessage + "Caused by: no ajax request has been sent.");
+		}
+	}
+	
+	@Override
+	public String getTestUrl() {
+		return "pages/ajaxSupport/ajaxSupport.xhtml";
+	}
+
+}




More information about the richfaces-svn-commits mailing list