From richfaces-svn-commits at lists.jboss.org Wed Jun 1 11:18:22 2011 Content-Type: multipart/mixed; boundary="===============1004017072473329294==" MIME-Version: 1.0 From: richfaces-svn-commits at lists.jboss.org To: richfaces-svn-commits at lists.jboss.org Subject: [richfaces-svn-commits] JBoss Rich Faces SVN: r22520 - modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSlider. Date: Wed, 01 Jun 2011 11:18:22 -0400 Message-ID: <201106011518.p51FIMFm017163@svn01.web.mwc.hst.phx2.redhat.com> --===============1004017072473329294== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: jjamrich Date: 2011-06-01 11:18:22 -0400 (Wed, 01 Jun 2011) New Revision: 22520 Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tes= ts/metamer/ftest/richInputNumberSlider/TestRichSliderWithJSR303.java Log: Add selenium tests for rich:inputNumberSlider with JSR303 validation Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces= /tests/metamer/ftest/richInputNumberSlider/TestRichSliderWithJSR303.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richInputNumberSlider/TestRichSliderWithJSR303.java = (rev 0) +++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richInputNumberSlider/TestRichSliderWithJSR303.java 2011-= 06-01 15:18:22 UTC (rev 22520) @@ -0,0 +1,211 @@ +/*************************************************************************= ****** + * JBoss, Home of Professional Open Source + * Copyright 2010-2011, 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.richInputNumberSlider; + +import java.net.URL; +import org.jboss.test.selenium.dom.Event; +import org.jboss.test.selenium.geometry.Point; +import org.jboss.test.selenium.locator.JQueryLocator; +import org.jboss.test.selenium.utils.URLUtils; +import org.richfaces.tests.metamer.ftest.AbstractMetamerTest; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * Test for faces/components/richInputNumberSpinner/jsr303.xhtml page + * + * @author Jan Jamrich + * @version $Revision$ + */ +public class TestRichSliderWithJSR303 extends AbstractMetamerTest { + = + /** Wrong value for input validated to min value */ + public static final String WRONG_MIN_VAL =3D "1"; + /** Wrong value for input validated to max value */ + public static final String WRONG_MAX_VAL =3D "5"; + /** Wrong value for input validated to custom value */ + public static final String WRONG_CUSTOM_VAL =3D "-1"; + = + /** Wrong value for input validated to min value */ + public static final String CORRECT_MIN_VAL =3D "3"; + /** Wrong value for input validated to max value */ + public static final String CORRECT_MAX_VAL =3D "1"; + /** Wrong value for input validated to custom value */ + public static final String CORRECT_CUSTOM_VAL =3D "5"; + = + = + /** validation message for input validated to min value */ + public static final String MSG_MIN =3D "must be greater than or equal = to 2"; + /** validation message for input validated to max value */ + public static final String MSG_MAX =3D "must be less than or equal to = 2"; + /** validation message for input validated to custom value */ + public static final String MSG_CUSTOM =3D "must be a positive number"; + = + private JQueryLocator inputFormat =3D pjq("span[id$=3D:slider{0}] span= .rf-insl-inp-cntr > input"); + private JQueryLocator msgFormat =3D pjq("span.rf-msg[id$=3D:inputMsg{0= }] span.rf-msg-det"); + private JQueryLocator outputFormat =3D pjq("span[id$=3D:output{0}]"); + private JQueryLocator sliderFormat =3D pjq("span[id$=3D:slider{0}] spa= n.rf-insl-trc"); + = + private JQueryLocator hCommandBtn =3D pjq("input[id$=3D:hButton]"); + private JQueryLocator a4jCommandBtn =3D pjq("input[id$=3D:a4jButton]"); + = + /** Codes for inputs */ + private enum ID { + /** input validated to min val */ + MIN(1), + /** input validated to max val */ + MAX(2), + /** input validated to custom (positive) val */ + CUSTOM(3); + = + private int id; + private ID(int i) { + this.id =3D i; + } + public int val() { + return id; + } + } + = + /** Position coordinates for slider. = + * Width is 200px, positions are relative to this = + */ + private enum POSITION { + LESS_THAN_ZERO(10), + ZERO(100), + MORE_THAN_TWO(150); + = + private int position; + private POSITION(int position) { + this.position =3D position; + } + public int val(){ + return position; + } + } + = + private void setAllCorrect() { + selenium.type(inputFormat.format(ID.MIN.val()), CORRECT_MIN_VAL); + selenium.fireEvent(inputFormat.format(ID.MIN.val()), Event.BLUR); + selenium.type(inputFormat.format(ID.MAX.val()), CORRECT_MAX_VAL); + selenium.fireEvent(inputFormat.format(ID.MAX.val()), Event.BLUR); + selenium.type(inputFormat.format(ID.CUSTOM.val()), CORRECT_CUSTOM_= VAL); + selenium.fireEvent(inputFormat.format(ID.CUSTOM.val()), Event.BLUR= ); + } + = + private void setAllWrong() { + selenium.type(inputFormat.format(ID.MIN.val()), WRONG_MIN_VAL); + selenium.fireEvent(inputFormat.format(ID.MIN.val()), Event.BLUR); + selenium.type(inputFormat.format(ID.MAX.val()), WRONG_MAX_VAL); + selenium.fireEvent(inputFormat.format(ID.MAX.val()), Event.BLUR); + selenium.type(inputFormat.format(ID.CUSTOM.val()), WRONG_CUSTOM_VA= L); + selenium.fireEvent(inputFormat.format(ID.CUSTOM.val()), Event.BLUR= ); + = + // wait until validation appears on last input before go ahead (e.= g. submit form) + waitGui.until(textEquals.text(MSG_CUSTOM).locator(msgFormat.format= (ID.CUSTOM.val()))); + } + = + @Override + public URL getTestUrl() { + return URLUtils.buildUrl(contextPath, "faces/components/richInputN= umberSlider/jsr303.xhtml"); + } + = + @Test + public void testMin() { + selenium.type(inputFormat.format(ID.MIN.val()), WRONG_MIN_VAL); + selenium.fireEvent(inputFormat.format(ID.MIN.val()), Event.BLUR); + waitGui.until(textEquals.locator(msgFormat.format(ID.MIN.val())).t= ext(MSG_MIN)); + } + = + @Test + public void testSlideToMin() { = + setAllCorrect(); + = + selenium.mouseDownAt(sliderFormat.format(ID.MIN.val()), new Point(= POSITION.ZERO.val(), 0)); + waitGui.until(textEquals.locator(msgFormat.format(ID.MIN.val())).t= ext(MSG_MIN)); = + } + = + @Test + public void testMax() { + selenium.type(inputFormat.format(ID.MAX.val()), WRONG_MAX_VAL); + selenium.fireEvent(inputFormat.format(ID.MAX.val()), Event.BLUR); + waitGui.until(textEquals.locator(msgFormat.format(ID.MAX.val())).t= ext(MSG_MAX)); + } + = + @Test + public void testSlideToMax() { = + setAllCorrect(); + = + selenium.mouseDownAt(sliderFormat.format(ID.MAX.val()), new Point(= POSITION.MORE_THAN_TWO.val(), 0)); + waitGui.until(textEquals.locator(msgFormat.format(ID.MAX.val())).t= ext(MSG_MAX)); + } + = + @Test + public void testCustom() { + selenium.type(inputFormat.format(ID.CUSTOM.val()), WRONG_CUSTOM_VA= L); + selenium.fireEvent(inputFormat.format(ID.CUSTOM.val()), Event.BLUR= ); + waitGui.until(textEquals.text(MSG_CUSTOM).locator(msgFormat.format= (ID.CUSTOM.val()))); + } + = + @Test + public void testSlideToNegative() { + setAllCorrect(); + = + selenium.mouseDownAt(sliderFormat.format(ID.CUSTOM.val()), new Poi= nt(POSITION.LESS_THAN_ZERO.val(), 0)); + waitGui.until(textEquals.locator(msgFormat.format(ID.CUSTOM.val())= ).text(MSG_CUSTOM)); + } + = + @Test = + public void testAllCorrect() { + = + setAllCorrect(); + = + waitGui.until(textEquals.text(CORRECT_MIN_VAL) + .locator(outputFormat.format(ID.MIN.val()))); + Assert.assertEquals(selenium.getText(outputFormat.format(ID.MAX.va= l())), CORRECT_MAX_VAL); + Assert.assertEquals(selenium.getText(outputFormat.format(ID.CUSTOM= .val())), CORRECT_CUSTOM_VAL); + = + } + = + @Test + public void testAllWrong() { + = + setAllCorrect(); + setAllWrong(); + = + selenium.click(hCommandBtn); + = + waitGui.until(textEquals.locator(msgFormat.format(ID.MIN.val())).t= ext(MSG_MIN)); + Assert.assertEquals(selenium.getText(msgFormat.format(ID.MAX.val()= )), MSG_MAX); + Assert.assertEquals(selenium.getText(msgFormat.format(ID.CUSTOM.va= l())), MSG_CUSTOM); + = + setAllCorrect(); + setAllWrong(); + = + selenium.click(a4jCommandBtn); + = + waitGui.until(textEquals.locator(msgFormat.format(ID.MIN.val())).t= ext(MSG_MIN)); + Assert.assertEquals(selenium.getText(msgFormat.format(ID.MAX.val()= )), MSG_MAX); + Assert.assertEquals(selenium.getText(msgFormat.format(ID.CUSTOM.va= l())), MSG_CUSTOM); + } + +} --===============1004017072473329294==--