Author: sergeyhalipov
Date: 2008-05-29 14:42:06 -0400 (Thu, 29 May 2008)
New Revision: 8832
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/InputNumberSliderBean.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/inputNumberSlider/
trunk/test-applications/seleniumTest/src/main/webapp/pages/inputNumberSlider/inputNumberSliderTest.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/InputNumberSliderTest.java
Modified:
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
Log:
Input number slider test.
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/InputNumberSliderBean.java
===================================================================
---
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/InputNumberSliderBean.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/InputNumberSliderBean.java 2008-05-29
18:42:06 UTC (rev 8832)
@@ -0,0 +1,55 @@
+/* License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.bean;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+
+public class InputNumberSliderBean {
+ private int value;
+
+ public InputNumberSliderBean() {
+ value = 40;
+ }
+
+ public void validate(FacesContext context, UIComponent component,
+ Object value) throws ValidatorException {
+ if (((Integer)value).intValue() > 90) {
+ throw new ValidatorException(new FacesMessage("Fake validation. Value is more
than 90."));
+ }
+ }
+
+ public String action() {
+ this.value += 10;
+ return null;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+}
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-05-29
16:50:08 UTC (rev 8831)
+++
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-05-29
18:42:06 UTC (rev 8832)
@@ -113,5 +113,10 @@
<managed-bean-name>dataTableBean</managed-bean-name>
<managed-bean-class>org.ajax4jsf.bean.DataTableBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
+ <managed-bean-name>sliderBean</managed-bean-name>
+ <managed-bean-class>org.ajax4jsf.bean.InputNumberSliderBean</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/src/main/webapp/pages/inputNumberSlider/inputNumberSliderTest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/pages/inputNumberSlider/inputNumberSliderTest.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/webapp/pages/inputNumberSlider/inputNumberSliderTest.xhtml 2008-05-29
18:42:06 UTC (rev 8832)
@@ -0,0 +1,30 @@
+<!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="component">
+ <h:form id="_form">
+ <rich:inputNumberSlider id="slider"
+ minValue="0"
+ maxValue="100"
+ value="#{sliderBean.value}"
+ barStyle="width: 1000px;"
+ validator="#{sliderBean.validate}" />
+
+ <h:panelGrid columns="2" >
+ <a4j:commandButton value="Ajax Command" id="ajax"
reRender="slider,output,messages" action="#{sliderBean.action}" />
+ <h:commandButton value="Server Command" id="server"
action="#{sliderBean.action}" />
+ </h:panelGrid>
+ <h:panelGrid columns="2" >
+ <h:outputText value="#{sliderBean.value}" id="output" />
+ <rich:messages id="messages" />
+ </h:panelGrid>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java 2008-05-29
16:50:08 UTC (rev 8831)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java 2008-05-29
18:42:06 UTC (rev 8832)
@@ -42,7 +42,7 @@
protected static final String serverPort = "8085";
- private static final String WINDOW_JS_RESOLVER =
"selenium.browserbot.getCurrentWindow().";
+ protected static final String WINDOW_JS_RESOLVER =
"selenium.browserbot.getCurrentWindow().";
/** Parent component id */
private String parentId;
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/InputNumberSliderTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/InputNumberSliderTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/InputNumberSliderTest.java 2008-05-29
18:42:06 UTC (rev 8832)
@@ -0,0 +1,142 @@
+/* License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.testng;
+
+import org.richfaces.RichSeleniumTest;
+import org.richfaces.SeleniumTestBase;
+import org.richfaces.Templates;
+import org.testng.Assert;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+public class InputNumberSliderTest extends SeleniumTestBase implements RichSeleniumTest
{
+ private static final int BAR_SCALE = 10;
+
+ public InputNumberSliderTest() {
+ super("http", "localhost", serverPort);
+ }
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeTest
+ @Parameters( { "browser" })
+ public void startSelenium(String browser) {
+ super.startSelenium(browser);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ super.stopSelenium();
+ }
+
+ @Test
+ public void testInputNumberSliderComponent() throws Exception {
+ _testInputNumberSlider(Templates.SIMPLE);
+ _testInputNumberSlider(Templates.DATATABLE);
+ //_testInputNumberSlider(Templates.MODALPANEL);
+ }
+
+ private void _testInputNumberSlider(Templates template) {
+ renderPage(template);
+
+ String parentId = getParentId() + "_form:";
+ String slider = parentId + "slider";
+
+ String input = slider + "Input";
+ String tip = slider + "Tip";
+ String track = slider + "Track";
+
+ String ajax = parentId + "ajax";
+ String server = parentId + "server";
+ String output = parentId + "output";
+
+ writeStatus("Checking initial rendering");
+ Assert.assertFalse(isVisibleById(tip));
+ checkSliderVisualState(slider, 40);
+ AssertTextEquals(output, "40");
+
+ writeStatus("Checking if tip is visible during click");
+ selenium.mouseDownAt("id=" + track, "800,1");
+ Assert.assertTrue(isVisibleById(tip));
+ selenium.mouseUpAt("id=" + track, "800,1");
+ Assert.assertFalse(isVisibleById(tip));
+
+ writeStatus("Checking if value is changed with previous click");
+ checkSliderVisualState(slider, 80);
+
+ writeStatus("Checking if value is changed with input field");
+ selenium.runScript("var input = $('" + input + "');
input.focus(); input.value = 22; input.blur();");
+ checkSliderVisualState(slider, 22);
+
+ writeStatus("Checking if slider is properly re-rendered and submitted with
ajax");
+ clickById(ajax);
+ waitForAjaxCompletion();
+ checkSliderVisualState(slider, 32);
+ AssertTextEquals(output, "32");
+
+ writeStatus("Checking if slider is properly submitted");
+ clickCommandAndWait(server);
+ checkSliderVisualState(slider, 42);
+ AssertTextEquals(output, "42");
+
+ writeStatus("Checking validation");
+ selenium.mouseDownAt("id=" + track, "950,1");
+ selenium.mouseUpAt("id=" + track, "950,1");
+ clickById(ajax);
+ waitForAjaxCompletion();
+ checkSliderVisualState(slider, 95);
+ AssertTextEquals(output, "42");
+
+ selenium.mouseDownAt("id=" + track, "300,1");
+ selenium.mouseUpAt("id=" + track, "300,1");
+ clickById(ajax);
+ waitForAjaxCompletion();
+ checkSliderVisualState(slider, 40);
+ AssertTextEquals(output, "40");
+ }
+
+ private void checkSliderVisualState(String id, int value) {
+ writeStatus("Checking value in input field");
+ AssertValueEquals(id + "Input", new Integer(value).toString());
+ AssertTextEquals(id + "Tip", new Integer(value).toString());
+
+ writeStatus("Checking tip and tracker position");
+ String actualHandle = selenium.getEval(WINDOW_JS_RESOLVER +
"document.getElementById('" + id + "Handle').style.left");
+ String actualTip = selenium.getEval(WINDOW_JS_RESOLVER +
"document.getElementById('" + id + "Tip').style.left");
+
+ Assert.assertEquals(actualHandle, actualTip);
+ Assert.assertTrue(actualTip.endsWith("px"));
+
+ int actual = new Integer(actualTip.replace("px", "")).intValue();
+ int expected = BAR_SCALE*value;
+ Assert.assertTrue(Math.abs(actual - expected) <= BAR_SCALE, "Handle position is
not syncronized with slider value!");
+ }
+
+ public String getTestUrl() {
+ return "/faces/pages/inputNumberSlider/inputNumberSliderTest.xhtml";
+ }
+}