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/tests/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
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.java 2011-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 <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
+ * @version $Revision$
+ */
+public class TestRichSpinnerWithJSR303 extends AbstractMetamerTest {
+
+ /** Code for input validated to min value */
+ public static final int MIN_ID = 1;
+ /** Code for input validated to max value */
+ public static final int MAX_ID = 2;
+ /** Code for input validated to custom condition */
+ public static final int CUSTOM_ID = 3;
+
+ /** Wrong value for input validated to min value */
+ public static final String WRONG_MIN_VAL = "1";
+ /** Wrong value for input validated to max value */
+ public static final String WRONG_MAX_VAL = "5";
+ /** Wrong value for input validated to custom value */
+ public static final String WRONG_CUSTOM_VAL = "-1";
+
+ /** Wrong value for input validated to min value */
+ public static final String CORRECT_MIN_VAL = "3";
+ /** Wrong value for input validated to max value */
+ public static final String CORRECT_MAX_VAL = "1";
+ /** Wrong value for input validated to custom value */
+ public static final String CORRECT_CUSTOM_VAL = "5";
+
+
+ /** validation message for input validated to min value */
+ public static final String MSG_MIN = "must be greater than or equal to 2";
+ /** validation message for input validated to max value */
+ public static final String MSG_MAX = "must be less than or equal to 2";
+ /** validation message for input validated to custom value */
+ public static final String MSG_CUSTOM = "must be a positive number";
+
+ private JQueryLocator inputFormat = pjq("span[id$=:input{0}] > input");
+ private JQueryLocator msgFormat = pjq("span.rf-msg[id$=:inputMsg{0}]
span.rf-msg-det");
+ private JQueryLocator outputFormat = pjq("span[id$=:output{0}]");
+
+ private JQueryLocator hCommandBtn = pjq("input[id$=:hButton]");
+ private JQueryLocator a4jCommandBtn = pjq("input[id$=: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/richInputNumberSpinner/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(MSG_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(MSG_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(MSG_MIN));
+ Assert.assertEquals(selenium.getText(msgFormat.format(MAX_ID)), MSG_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(MSG_MIN));
+ Assert.assertEquals(selenium.getText(msgFormat.format(MAX_ID)), MSG_MAX);
+ Assert.assertEquals(selenium.getText(msgFormat.format(CUSTOM_ID)), MSG_CUSTOM);
+ }
+
+}