[richfaces-svn-commits] JBoss Rich Faces SVN: r18803 - in modules/tests/metamer/trunk/ftest-source/src/main: java/org/richfaces/tests/metamer/ftest and 9 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Aug 19 07:55:16 EDT 2010


Author: lfryc at redhat.com
Date: 2010-08-19 07:55:16 -0400 (Thu, 19 Aug 2010)
New Revision: 18803

Added:
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusAttributes.java
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusFacets.java
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestSimple.java
   modules/tests/metamer/trunk/ftest-source/src/main/resources/
   modules/tests/metamer/trunk/ftest-source/src/main/resources/org/
   modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/
   modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/
   modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/metamer/
   modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/metamer/ftest/
   modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/metamer/ftest/a4jStatus/
   modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/metamer/ftest/a4jStatus/status-halt.js
Modified:
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/RichJQueryAttributes.java
Log:
a4j:status - simple - basic tests (RFPL-735)

Modified: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java	2010-08-19 11:53:51 UTC (rev 18802)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java	2010-08-19 11:55:16 UTC (rev 18803)
@@ -21,8 +21,11 @@
  *******************************************************************************/
 package org.richfaces.tests.metamer.ftest;
 
+import org.apache.commons.lang.Validate;
+import org.jboss.test.selenium.dom.Event;
 import org.jboss.test.selenium.framework.AjaxSelenium;
 import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.AttributeLocator;
 import org.jboss.test.selenium.locator.ElementLocator;
 import org.jboss.test.selenium.locator.JQueryLocator;
 
@@ -34,12 +37,52 @@
  * @version $Revision$
  */
 public class AbstractComponentAttributes {
+
+    private Type type;
+
+    public static class Type {
+        public static Type SERVER = new Type();
+        public static Type AJAX = new Type();
+    }
+
+    public AbstractComponentAttributes() {
+        this(Type.SERVER);
+    }
+
+    public AbstractComponentAttributes(Type type) {
+        Validate.notNull(type);
+        this.type = type;
+    }
+
     AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
 
     JQueryLocator propertyLocator = pjq("input[id$={0}Input]");
 
-    protected void setProperty(String propertyName, String value) {
+    protected void setProperty(String propertyName, Object value) {
         final ElementLocator<?> locator = propertyLocator.format(propertyName);
-        guardHttp(selenium).type(locator, value);
+        final AttributeLocator<?> typeLocator = locator.getAttribute(new org.jboss.test.selenium.locator.Attribute(
+            "type"));
+
+        String inputType = selenium.getAttribute(typeLocator);
+
+        String valueAsString = value.toString();
+        // INPUT TEXT
+        if ("text".equals(inputType)) {
+            if (type == Type.SERVER) {
+                guardHttp(selenium).type(locator, valueAsString);
+            } else if (type == Type.AJAX) {
+                selenium.type(locator, valueAsString);
+            }
+            // INPUT CHECKBOX
+        } else if ("checkbox".equals(inputType)) {
+            boolean checked = Boolean.valueOf(valueAsString);
+
+            if (type == Type.SERVER) {
+                guardHttp(selenium).check(locator, checked);
+            } else if (type == Type.AJAX) {
+                selenium.check(locator, checked);
+                selenium.fireEvent(locator, Event.CHANGE);
+            }
+        }
     }
 }

Copied: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusAttributes.java (from rev 18802, modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/RichJQueryAttributes.java)
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusAttributes.java	                        (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusAttributes.java	2010-08-19 11:55:16 UTC (rev 18803)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.a4jStatus;
+
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+/**
+ * @author <a href="mailto:lfryc at redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class StatusAttributes extends AbstractComponentAttributes {
+    public void setOnError(JavaScript javaScript) {
+        setProperty("onerror", javaScript.toString());
+    }
+    
+    public void setOnStart(JavaScript javaScript) {
+        setProperty("onstart", javaScript.toString());
+    }
+    
+    public void setOnStop(JavaScript javaScript) {
+        setProperty("onstop", javaScript.toString());
+    }
+    
+    public void setOnSuccess(JavaScript javaScript) {
+        setProperty("onsuccess", javaScript.toString());
+    }
+    
+    public void setRendered(boolean rendered) {
+        setProperty("rendered", Boolean.toString(rendered));
+    }
+}

Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusFacets.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusFacets.java	                        (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusFacets.java	2010-08-19 11:55:16 UTC (rev 18803)
@@ -0,0 +1,18 @@
+package org.richfaces.tests.metamer.ftest.a4jStatus;
+
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+public class StatusFacets extends AbstractComponentAttributes {
+
+    public void setStartText(String startText) {
+        setProperty("facetStartText", startText);
+    }
+
+    public void setStopText(String stopText) {
+        setProperty("facetStopText", stopText);
+    }
+
+    public void setErrorText(String errorText) {
+        setProperty("facetErrorText", errorText);
+    }
+}

Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestSimple.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestSimple.java	                        (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestSimple.java	2010-08-19 11:55:16 UTC (rev 18803)
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.a4jStatus;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.waiting.retrievers.TextRetriever;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static org.jboss.test.selenium.utils.URLUtils.*;
+import static org.jboss.test.selenium.encapsulated.JavaScript.js;
+import static org.testng.Assert.*;
+
+/**
+ * @author <a href="mailto:lfryc at redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestSimple extends AbstractMetamerTest {
+    @Override
+    public URL getTestUrl() {
+        return buildUrl(contextPath, "faces/components/a4jStatus/simple.xhtml");
+    }
+
+    StatusAttributes attributes = new StatusAttributes();
+
+    JQueryLocator button1 = pjq("input[id$=button1]");
+    JQueryLocator button2 = pjq("input[id$=button2]");
+    JQueryLocator buttonError = pjq("input[id$=button3]");
+    JQueryLocator status = pjq("span[id$=status]");
+
+    TextRetriever retrieveStatus = retrieveText.locator(status);
+
+    JavaScript extension = JavaScript.fromResource(getClass().getPackage().getName().replaceAll("\\.", "/")
+        + "/status-halt.js");
+
+    @BeforeMethod
+    public void installExtensions() {
+        selenium.getPageExtensions().install();
+        selenium.runScript(extension);
+    }
+
+    @Test
+    public void testRequestButton1() {
+        testRequestButton(button1, "START", "STOP");
+    }
+
+    @Test
+    public void testRequestButton2() {
+        testRequestButton(button2, "START", "STOP");
+    }
+
+    @Test
+    public void testRequestButtonError() {
+        testRequestButton(buttonError, "START", "ERROR");
+    }
+
+    @Test
+    public void testInterleaving() {
+        testRequestButton1();
+        testRequestButtonError();
+        testRequestButton2();
+        testRequestButtonError();
+        testRequestButton1();
+    }
+
+    private void testRequestButton(ElementLocator<?> button, String startText, String stopText) {
+        selenium.click(button);
+        waitForHalt();
+        assertEquals(retrieveStatus.retrieve(), startText);
+        unhalt();
+        waitAjax.waitForChange(startText, retrieveStatus);
+        assertEquals(retrieveStatus.retrieve(), stopText);
+    }
+
+    private void waitForHalt() {
+        selenium.waitForCondition(js("selenium.browserbot.getCurrentWindow().Metamer.halt == true"));
+    }
+
+    private void unhalt() {
+        selenium.getEval(js("selenium.browserbot.getCurrentWindow().Metamer.halt = false"));
+    }
+}
\ No newline at end of file

Modified: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/RichJQueryAttributes.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/RichJQueryAttributes.java	2010-08-19 11:53:51 UTC (rev 18802)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/RichJQueryAttributes.java	2010-08-19 11:55:16 UTC (rev 18803)
@@ -41,7 +41,7 @@
         setProperty("query", query);
     }
 
-    public void setRendered(String rendered) {
+    public void setRendered(boolean rendered) {
         setProperty("rendered", rendered);
     }
 

Added: modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/metamer/ftest/a4jStatus/status-halt.js
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/metamer/ftest/a4jStatus/status-halt.js	                        (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/metamer/ftest/a4jStatus/status-halt.js	2010-08-19 11:55:16 UTC (rev 18803)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.
+ */
+var Metamer = {
+	halt : false,
+	callback : null,
+	object : null,
+	content : null,
+	wait : function() {
+		if (Metamer.halt) {
+			setTimeout("Metamer.wait()", 100);
+		} else {
+			Metamer.halt = false;
+			Metamer.callback();
+		}
+	}
+};
+
+Metamer.XHRWrapperInjection = {
+	send : RichFacesSelenium.XHRWrapper.prototype.send
+};
+
+RichFacesSelenium.XHRWrapper.prototype.send = function(content) {
+	Metamer.halt = true;
+	Metamer.object = this;
+	Metamer.content = content;
+	Metamer.callback = function() {
+		Metamer.XHRWrapperInjection.send.call(Metamer.object, Metamer.content);
+	};
+	Metamer.wait();
+};
\ No newline at end of file



More information about the richfaces-svn-commits mailing list