[richfaces-svn-commits] JBoss Rich Faces SVN: r18825 - in modules/tests/metamer/trunk: ftest-source/src/main/java/org/richfaces/tests/metamer/ftest and 2 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Thu Aug 19 13:25:45 EDT 2010
Author: lfryc at redhat.com
Date: 2010-08-19 13:25:44 -0400 (Thu, 19 Aug 2010)
New Revision: 18825
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/AbstracStatusTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestFacets.java
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jStatus/simple.xhtml
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/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/org/richfaces/tests/metamer/ftest/a4jStatus/status-halt.js
Log:
a4j:status - added tests for testing live switching of facets (RFPL-735)
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/a4jStatus/simple.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/a4jStatus/simple.xhtml 2010-08-19 17:10:14 UTC (rev 18824)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/a4jStatus/simple.xhtml 2010-08-19 17:25:44 UTC (rev 18825)
@@ -39,18 +39,18 @@
<ui:define name="outOfTemplateBefore">
<fieldset>
<legend>Facets Settings</legend>
- <h:panelGrid id="facetsSettings" columns="2">
- <h:outputText value="Facet Start: " />
- <h:inputText id="facetStartTextInput" value="#{a4jStatusBean.facetStartValue}" />
-
- <h:outputText value="Facet Stop: " />
- <h:inputText id="facetStopTextInput" value="#{a4jStatusBean.facetStopValue}" />
-
- <h:outputText value="Facet Error: " />
- <h:inputText id="facetErrorTextInput" value="#{a4jStatusBean.facetErrorValue}" />
-
- <a4j:commandButton id="apply" value="Apply instantly" render="status,facetGrid" execute="facetGrid" />
- </h:panelGrid>
+ <a4j:ajax event="change" render="status" execute="facetsSettings">
+ <h:panelGrid id="facetsSettings" columns="2">
+ <h:outputText value="Facet Start: " />
+ <h:inputText id="facetStartTextInput" value="#{a4jStatusBean.facetStartValue}" />
+
+ <h:outputText value="Facet Stop: " />
+ <h:inputText id="facetStopTextInput" value="#{a4jStatusBean.facetStopValue}" />
+
+ <h:outputText value="Facet Error: " />
+ <h:inputText id="facetErrorTextInput" value="#{a4jStatusBean.facetErrorValue}" />
+ </h:panelGrid>
+ </a4j:ajax>
</fieldset>
</ui:define>
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 17:10:14 UTC (rev 18824)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java 2010-08-19 17:25:44 UTC (rev 18825)
@@ -30,6 +30,7 @@
import org.jboss.test.selenium.locator.JQueryLocator;
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
import static org.richfaces.tests.metamer.ftest.AbstractMetamerTest.pjq;
/**
@@ -58,6 +59,11 @@
JQueryLocator propertyLocator = pjq("input[id$={0}Input]");
+ protected String getProperty(String propertyName) {
+ final ElementLocator<?> locator = propertyLocator.format(propertyName);
+ return selenium.getValue(locator);
+ }
+
protected void setProperty(String propertyName, Object value) {
final ElementLocator<?> locator = propertyLocator.format(propertyName);
final AttributeLocator<?> typeLocator = locator.getAttribute(new org.jboss.test.selenium.locator.Attribute(
@@ -71,7 +77,7 @@
if (type == Type.SERVER) {
guardHttp(selenium).type(locator, valueAsString);
} else if (type == Type.AJAX) {
- selenium.type(locator, valueAsString);
+ guardXhr(selenium).type(locator, valueAsString);
}
// INPUT CHECKBOX
} else if ("checkbox".equals(inputType)) {
@@ -81,7 +87,7 @@
guardHttp(selenium).check(locator, checked);
} else if (type == Type.AJAX) {
selenium.check(locator, checked);
- selenium.fireEvent(locator, Event.CHANGE);
+ guardXhr(selenium).fireEvent(locator, Event.CHANGE);
}
}
}
Copied: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/AbstracStatusTest.java (from rev 18803, 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/AbstracStatusTest.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/AbstracStatusTest.java 2010-08-19 17:25:44 UTC (rev 18825)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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 static org.jboss.test.selenium.encapsulated.JavaScript.js;
+import static org.testng.Assert.assertEquals;
+
+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;
+
+/**
+ * @author <a href="mailto:lfryc at redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class AbstracStatusTest extends AbstractMetamerTest {
+ JQueryLocator button1 = pjq("input[id$=button1]");
+ JQueryLocator button2 = pjq("input[id$=button2]");
+ JQueryLocator buttonError = pjq("input[id$=button3]");
+ JQueryLocator status = pjq("span[id$=status]");
+
+ StatusAttributes attributes = new StatusAttributes();
+
+ TextRetriever retrieveStatus = retrieveText.locator(status);
+
+ JavaScript extension = JavaScript.fromResource(getClass().getPackage().getName().replaceAll("\\.", "/")
+ + "/status-halt.js");
+
+ void installStatusExtensions() {
+ selenium.getPageExtensions().install();
+ selenium.runScript(extension);
+ }
+
+ void testRequestButton(ElementLocator<?> button, String startStatusText, String stopStatusText) {
+ enableHalt();
+ selenium.click(button);
+ waitForHalt();
+ assertEquals(retrieveStatus.retrieve(), startStatusText);
+ unhalt();
+ waitAjax.waitForChange(startStatusText, retrieveStatus);
+ assertEquals(retrieveStatus.retrieve(), stopStatusText);
+ disableHalt();
+ }
+
+ void waitForHalt() {
+ selenium.waitForCondition(js("selenium.browserbot.getCurrentWindow().Metamer.halt == true"));
+ }
+
+ void unhalt() {
+ selenium.getEval(js("selenium.browserbot.getCurrentWindow().Metamer.halt = false"));
+ }
+
+ void enableHalt() {
+ selenium.getEval(js("selenium.browserbot.getCurrentWindow().Metamer.haltEnabled = true"));
+ }
+
+ void disableHalt() {
+ selenium.getEval(js("selenium.browserbot.getCurrentWindow().Metamer.haltEnabled = false"));
+ }
+}
Modified: 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 2010-08-19 17:10:14 UTC (rev 18824)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/StatusFacets.java 2010-08-19 17:25:44 UTC (rev 18825)
@@ -4,15 +4,31 @@
public class StatusFacets extends AbstractComponentAttributes {
+ public StatusFacets() {
+ super(AbstractComponentAttributes.Type.AJAX);
+ }
+
public void setStartText(String startText) {
setProperty("facetStartText", startText);
}
+ public String getStartText() {
+ return getProperty("facetStartText");
+ }
+
public void setStopText(String stopText) {
setProperty("facetStopText", stopText);
}
+ public String getStopText() {
+ return getProperty("facetStopText");
+ }
+
public void setErrorText(String errorText) {
setProperty("facetErrorText", errorText);
}
+
+ public String getErrorText() {
+ return getProperty("facetErrorText");
+ }
}
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestFacets.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestFacets.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestFacets.java 2010-08-19 17:25:44 UTC (rev 18825)
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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 static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc at redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestFacets extends AbstracStatusTest {
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/a4jStatus/simple.xhtml");
+ }
+
+ StatusFacets facets = new StatusFacets();
+
+ @BeforeMethod
+ public void installStatusExtensions() {
+ super.installStatusExtensions();
+ }
+
+ @Test
+ public void testInterleavedChangingOfFacets() {
+ for (int i = 0; i < 13; i++) {
+ ElementLocator<?> button = (i % 2 == 0) ? button2 : buttonError;
+ IterateStatus iterateStatus = IterateStatus.values()[i % IterateStatus.values().length];
+ testChangingFacet(button, iterateStatus);
+ }
+ }
+
+ void testChangingFacet(ElementLocator<?> button, IterateStatus iterateStatus) {
+ switch (iterateStatus) {
+ case START:
+ facets.setStartText(facets.getStartText() + "*");
+ break;
+ case STOP:
+ facets.setStopText(facets.getStopText() + "*");
+ break;
+ case ERROR:
+ facets.setErrorText(facets.getErrorText() + "*");
+ break;
+ }
+
+ final String startText = facets.getStartText();
+ final String stopText = (button == buttonError) ? facets.getErrorText() : facets.getStopText();
+
+ testRequestButton(button, startText, stopText);
+ }
+
+ private static enum IterateStatus {
+ START, STOP, ERROR
+ }
+}
\ No newline at end of file
Modified: 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 2010-08-19 17:10:14 UTC (rev 18824)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestSimple.java 2010-08-19 17:25:44 UTC (rev 18825)
@@ -39,28 +39,15 @@
* @author <a href="mailto:lfryc at redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
-public class TestSimple extends AbstractMetamerTest {
+public class TestSimple extends AbstracStatusTest {
@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);
+ public void installStatusExtensions() {
+ super.installStatusExtensions();
}
@Test
@@ -86,21 +73,4 @@
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/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 2010-08-19 17:10:14 UTC (rev 18824)
+++ modules/tests/metamer/trunk/ftest-source/src/main/resources/org/richfaces/tests/metamer/ftest/a4jStatus/status-halt.js 2010-08-19 17:25:44 UTC (rev 18825)
@@ -20,12 +20,13 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
var Metamer = {
+ haltEnabled : false,
halt : false,
callback : null,
object : null,
content : null,
wait : function() {
- if (Metamer.halt) {
+ if (Metamer.haltEnabled && Metamer.halt) {
setTimeout("Metamer.wait()", 100);
} else {
Metamer.halt = false;
More information about the richfaces-svn-commits
mailing list