From richfaces-svn-commits at lists.jboss.org Tue May 31 11:19:05 2011 Content-Type: multipart/mixed; boundary="===============1382981493550640071==" 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: r22517 - modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner. Date: Tue, 31 May 2011 11:19:05 -0400 Message-ID: <201105311519.p4VFJ5XE018255@svn01.web.mwc.hst.phx2.redhat.com> --===============1382981493550640071== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: jjamrich Date: 2011-05-31 11:19:04 -0400 (Tue, 31 May 2011) New Revision: 22517 Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tes= ts/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.java Log: Cover JSR303 validation on rich:inputNumberSpinner by selenium tests. Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces= /tests/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.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/richInputNumberSpinner/TestRichSpinnerWithJSR303.java = (rev 0) +++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.java 201= 1-05-31 15:19:04 UTC (rev 22517) @@ -0,0 +1,156 @@ +/*************************************************************************= ****** + * 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.richInputNumberSpinner; + +import java.net.URL; + +import org.jboss.test.selenium.dom.Event; +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 TestRichSpinnerWithJSR303 extends AbstractMetamerTest { + = + /** Code for input validated to min value */ + public static final int MIN_ID =3D 1; + /** Code for input validated to max value */ + public static final int MAX_ID =3D 2; + /** Code for input validated to custom condition */ + public static final int CUSTOM_ID =3D 3; + = + /** 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:input{0}] > inp= ut"); + 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 hCommandBtn =3D pjq("input[id$=3D:hButton]"); + private JQueryLocator a4jCommandBtn =3D pjq("input[id$=3D:a4jButton]"); + = + private void setAllCorrect() { + selenium.type(inputFormat.format(MIN_ID), CORRECT_MIN_VAL); + selenium.fireEvent(inputFormat.format(MIN_ID), Event.BLUR); + selenium.type(inputFormat.format(MAX_ID), CORRECT_MAX_VAL); + selenium.fireEvent(inputFormat.format(MAX_ID), Event.BLUR); + selenium.type(inputFormat.format(CUSTOM_ID), CORRECT_CUSTOM_VAL); + selenium.fireEvent(inputFormat.format(CUSTOM_ID), Event.BLUR); = = + } + = + private void setAllWrong() { + selenium.type(inputFormat.format(MIN_ID), WRONG_MIN_VAL); + selenium.fireEvent(inputFormat.format(MIN_ID), Event.BLUR); + selenium.type(inputFormat.format(MAX_ID), WRONG_MAX_VAL); + selenium.fireEvent(inputFormat.format(MAX_ID), Event.BLUR); + selenium.type(inputFormat.format(CUSTOM_ID), WRONG_CUSTOM_VAL); + selenium.fireEvent(inputFormat.format(CUSTOM_ID), Event.BLUR); + = + // wait until validation appears on last input before go ahead (e.= g. submit form) + waitGui.until(textEquals.locator(msgFormat.format(CUSTOM_ID)).text= (MSG_CUSTOM)); + } + + @Override + public URL getTestUrl() { + return URLUtils.buildUrl(contextPath, "faces/components/richInputN= umberSpinner/jsr303.xhtml"); + } + = + @Test + public void testMin() { + selenium.type(inputFormat.format(MIN_ID), WRONG_MIN_VAL); + selenium.fireEvent(inputFormat.format(MIN_ID), Event.BLUR); + waitGui.until(textEquals.locator(msgFormat.format(MIN_ID)).text(MS= G_MIN)); + } + = + @Test + public void testMax() { + selenium.type(inputFormat.format(MAX_ID), WRONG_MAX_VAL); + selenium.fireEvent(inputFormat.format(MAX_ID), Event.BLUR); + waitGui.until(textEquals.locator(msgFormat.format(MAX_ID)).text(MS= G_MAX)); + } + = + @Test + public void testCustom() { + selenium.type(inputFormat.format(CUSTOM_ID), WRONG_CUSTOM_VAL); + selenium.fireEvent(inputFormat.format(CUSTOM_ID), Event.BLUR); + waitGui.until(textEquals.locator(msgFormat.format(CUSTOM_ID)).text= (MSG_CUSTOM)); + } + = + @Test = + public void testAllCorrect() { + = + setAllCorrect(); + = + waitGui.until(textEquals.locator(outputFormat.format(MIN_ID)).text= (CORRECT_MIN_VAL)); + Assert.assertEquals(selenium.getText(outputFormat.format(MAX_ID)),= CORRECT_MAX_VAL); + Assert.assertEquals(selenium.getText(outputFormat.format(CUSTOM_ID= )), CORRECT_CUSTOM_VAL); + } + = + @Test + public void testAllWrong() { + = + setAllCorrect(); + setAllWrong(); + = + selenium.click(hCommandBtn); + = + waitGui.until(textEquals.locator(msgFormat.format(MIN_ID)).text(MS= G_MIN)); + Assert.assertEquals(selenium.getText(msgFormat.format(MAX_ID)), MS= G_MAX); + Assert.assertEquals(selenium.getText(msgFormat.format(CUSTOM_ID)),= MSG_CUSTOM); + = + setAllCorrect(); + setAllWrong(); + = + selenium.click(a4jCommandBtn); + = + waitGui.until(textEquals.locator(msgFormat.format(MIN_ID)).text(MS= G_MIN)); + Assert.assertEquals(selenium.getText(msgFormat.format(MAX_ID)), MS= G_MAX); + Assert.assertEquals(selenium.getText(msgFormat.format(CUSTOM_ID)),= MSG_CUSTOM); + } + +} --===============1382981493550640071==--