Author: lfryc(a)redhat.com
Date: 2009-09-03 07:13:01 -0400 (Thu, 03 Sep 2009)
New Revision: 15445
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/beanValidator/BeanValidatorTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/beanValidator/locators.properties
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/beanValidator/messages.properties
Log:
- refactored Bean Validator test cases to follow conventions
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/beanValidator/BeanValidatorTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/beanValidator/BeanValidatorTestCase.java 2009-09-03
06:45:41 UTC (rev 15444)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/beanValidator/BeanValidatorTestCase.java 2009-09-03
11:13:01 UTC (rev 15445)
@@ -1,6 +1,27 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces
+ *
+ * Copyright (C) 2009 Red Hat, Inc.
+ *
+ * This code 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 code 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 test suite; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.jboss.richfaces.integrationTest.beanValidator;
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
@@ -8,143 +29,208 @@
* @version $Revision$
*/
public class BeanValidatorTestCase extends AbstractSeleniumRichfacesTestCase {
- /**
- * Opens specified page
- */
- public void openPage() {
- selenium.open(contextPath
- + "/richfaces/beanValidator.jsf?c=beanValidator&tab=usage");
- scrollIntoView(header, true);
- }
- private String header = getLoc("bean-validator--header");
- private String buttonSubmit = getLoc("bean-validator--button--submit");
- private String inputName = getLoc("bean-validator--input--name");
- private String inputEmail = getLoc("bean-validator--input--email");
- private String inputAge = getLoc("bean-validator--input--age");
- private String relativeValidationMessage =
getLoc("bean-validator--relative--validation-message");
+ private String LOC_FIELDSET_HEADER = getLoc("FIELDSET_HEADER");
+ private String LOC_BUTTON_SUBMIT = getLoc("BUTTON_SUBMIT");
+ private String LOC_VALIDATION_MESSAGE_RELATIVE =
getLoc("VALIDATION_MESSAGE_RELATIVE");
+ private String LOC_INPUT_HIBERNATE_NAME = getLoc("INPUT_HIBERNATE_NAME");
+ private String LOC_INPUT_HIBERNATE_AGE = getLoc("INPUT_HIBERNATE_AGE");
+ private String LOC_INPUT_HIBERNATE_EMAIL = getLoc("INPUT_HIBERNATE_EMAIL");
- private void typeAndSubmit(String locator, String value) {
- selenium.type(locator, value);
- selenium.click(buttonSubmit);
- }
+ private final String MSG_INPUT_VALUE_IS_LESS_THAN_MINIMUM =
getMsg("INPUT_VALUE_IS_LESS_THAN_MINIMUM");
+ private final String MSG_INPUT_VALUE_IS_GREATER_THAN_MAXIMUM =
getMsg("INPUT_VALUE_IS_GREATER_THAN_MAXIMUM");
+ private final String MSG_INPUT_VALID_NAME = getMsg("INPUT_VALID_NAME");
+ private final String MSG_INPUT_MUST_BE_GREATER_THAN_OR_EQUAL =
getMsg("INPUT_MUST_BE_GREATER_THAN_OR_EQUAL");
+ private final String MSG_INPUT_MUST_BE_LESS_THAN_OR_EQUAL =
getMsg("INPUT_MUST_BE_LESS_THAN_OR_EQUAL");
+ private final String MSG_INPUT_IS_NOT_NUMBER = getMsg("INPUT_IS_NOT_NUMBER");
+ private final String MSG_INPUT_VALID_AGE = getMsg("INPUT_VALID_AGE");
+ private final String MSG_INPUT_NOT_WELL_FORMED_EMAIL_1 =
getMsg("INPUT_NOT_WELL_FORMED_EMAIL_1");
+ private final String MSG_INPUT_NOT_WELL_FORMED_EMAIL_2 =
getMsg("INPUT_NOT_WELL_FORMED_EMAIL_2");
+ private final String MSG_INPUT_WELL_FORMED_EMAIL =
getMsg("INPUT_WELL_FORMED_EMAIL");
+ private final String MSG_OUTPUT_LENGTH_MUST_BE_BETWEEN =
getMsg("OUTPUT_LENGTH_MUST_BE_BETWEEN");
+ private final String MSG_OUTPUT_STRING_CONTAIN_ONLY_SPACES =
getMsg("OUTPUT_STRING_CONTAIN_ONLY_SPACES");
+ private final String MSG_OUTPUT_MAY_NOT_BE_NULL =
getMsg("OUTPUT_MAY_NOT_BE_NULL");
+ private final String MSG_OUTPUT_MUST_BE_GREATER_THAN_OR_EQUAL =
getMsg("OUTPUT_MUST_BE_GREATER_THAN_OR_EQUAL");
+ private final String MSG_OUTPUT_MUST_BE_LESS_THAN_OR_EQUAL =
getMsg("OUTPUT_MUST_BE_LESS_THAN_OR_EQUAL");
+ private final String MSG_OUTPUT_MUST_BE_A_NUMBER =
getMsg("OUTPUT_MUST_BE_A_NUMBER");
+ private final String MSG_OUTPUT_MAY_NOT_BE_NULL_OR_EMPTY =
getMsg("OUTPUT_MAY_NOT_BE_NULL_OR_EMPTY");
+ private final String MSG_OUTPUT_NOT_WELL_FORMED_EMAIL =
getMsg("OUTPUT_NOT_WELL_FORMED_EMAIL");
- public String getMessageFor(String locator) {
- return format(relativeValidationMessage, locator);
+ /**
+ * Try type no chars in input name and checks that value required message
+ * will appear.
+ */
+ @Test
+ public void testNameValueRequired() {
+ final String validationMessage = format(MSG_OUTPUT_MAY_NOT_BE_NULL_OR_EMPTY,
LOC_INPUT_HIBERNATE_NAME);
+ typeAndSubmit(LOC_INPUT_HIBERNATE_NAME, "");
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_NAME), validationMessage);
}
+ /**
+ * Try type string of length less than minimum length in name input and
+ * checks that validation message will appear.
+ */
@Test
- public void nameValueRequired() {
- openPage();
- typeAndSubmit(inputName, "");
- waitForTextEquals(getMessageFor(inputName),
- getMess("may-not-be-null-or-empty"));
+ public void testNameMinimumLength() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_NAME, MSG_INPUT_VALUE_IS_LESS_THAN_MINIMUM);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_NAME),
MSG_OUTPUT_LENGTH_MUST_BE_BETWEEN);
}
+ /**
+ * Try type string of length greater than maximum length in name input and
+ * checks that validation message will appear.
+ */
@Test
- public void nameMinimumLength() {
- openPage();
- typeAndSubmit(inputName, getMess("less-than-minimum--enter"));
- waitForTextEquals(getMessageFor(inputName),
- getMess("bean-name--length"));
+ public void testNameMaximumLength() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_NAME, MSG_INPUT_VALUE_IS_GREATER_THAN_MAXIMUM);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_NAME),
MSG_OUTPUT_LENGTH_MUST_BE_BETWEEN);
}
+ /**
+ * Enter only one space to name input and checks that validation message
+ * will appear.
+ */
@Test
- public void nameMaximumLength() {
- openPage();
- typeAndSubmit(inputName, getMess("greater-than-maximum--enter"));
- waitForTextEquals(getMessageFor(inputName),
- getMess("bean-name--length"));
+ public void testNameOnlySpacesPattern() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_NAME, " ");
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_NAME),
MSG_OUTPUT_STRING_CONTAIN_ONLY_SPACES);
}
+ /**
+ * Try type the invalid name input and checks that after typing valid input
+ * will validation message disappear.
+ */
@Test
- public void nameOnlySpacesPattern() {
- openPage();
- typeAndSubmit(inputName, " ");
- waitForTextEquals(getMessageFor(inputName),
- getMess("bean-name--not-empty"));
+ public void testNameMessageDisappers() {
+ // first violate validation error
+ testNameValueRequired();
+ // then try valid input
+ typeAndSubmit(LOC_INPUT_HIBERNATE_NAME, MSG_INPUT_VALID_NAME);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_NAME), "");
}
+ /**
+ * Try type no chars in age input and checks that the validation message
+ * value required will appear.
+ */
@Test
- public void nameMessageDisappers() {
- nameValueRequired();
- typeAndSubmit(inputName, getMess("bean-name--valid-input"));
- waitForTextEquals(getMessageFor(inputName), "");
+ public void testAgeValueRequired() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_AGE, "");
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_AGE), MSG_OUTPUT_MAY_NOT_BE_NULL);
}
+ /**
+ * Try input age less than minimum and checks that the validation message
+ * will appear.
+ */
@Test
- public void ageValueRequired() {
- openPage();
- typeAndSubmit(inputAge, "");
- waitForTextEquals(getMessageFor(inputAge), getMess("may-not-be-null"));
+ public void testAgeMinimumValue() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_AGE, MSG_INPUT_MUST_BE_LESS_THAN_OR_EQUAL);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_AGE),
MSG_OUTPUT_MUST_BE_LESS_THAN_OR_EQUAL);
}
+ /**
+ * Try input age greater than maximum and checks that the validation message
+ * will appear.
+ */
@Test
- public void ageMinimumValue() {
- openPage();
- typeAndSubmit(inputAge, getMess("long-range--bellow"));
- waitForTextEquals(getMessageFor(inputAge), getMess("bean-age--min"));
+ public void testAgeMaximumValue() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_AGE, MSG_INPUT_MUST_BE_GREATER_THAN_OR_EQUAL);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_AGE),
MSG_OUTPUT_MUST_BE_GREATER_THAN_OR_EQUAL);
}
+ /**
+ * Try input age as non-Integer (alphabetical chars) and checks that
+ * validation message will appear.
+ */
@Test
- public void ageMaximumValue() {
- openPage();
- typeAndSubmit(inputAge, getMess("bean-age--max--enter"));
- waitForTextEquals(getMessageFor(inputAge), getMess("bean-age--max"));
+ public void testAgeIntegerOnly() {
+ final String validationMessage = format(MSG_OUTPUT_MUST_BE_A_NUMBER,
LOC_INPUT_HIBERNATE_AGE);
+ typeAndSubmit(LOC_INPUT_HIBERNATE_AGE, MSG_INPUT_IS_NOT_NUMBER);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_AGE), validationMessage);
}
+ /**
+ * Try input no input first and wait for validation message appears and then
+ * type a valid input and checks that validation message will disappear.
+ */
@Test
- public void ageIntegerOnly() {
- openPage();
- typeAndSubmit(inputAge, formatMess("age-integer-only--enter", inputAge));
- waitForTextEquals(getMessageFor(inputAge), formatMess(
- "bean-age--integer-only", selenium.getAttribute(format(
- "{0}/@id", inputAge))));
+ public void testAgeMessageDisappers() {
+ // first violate validation error
+ testAgeValueRequired();
+ // then try valid input
+ typeAndSubmit(LOC_INPUT_HIBERNATE_AGE, MSG_INPUT_VALID_AGE);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_AGE), "");
}
+ /**
+ * Try to enter empty email address and checks that validation message
+ * appears.
+ */
@Test
- public void ageMessageDisappers() {
- ageValueRequired();
- typeAndSubmit(inputAge, getMess("valid-age"));
- waitForTextEquals(getMessageFor(inputAge), "");
+ public void testEmailMayNotBeNullOrEmpty() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_EMAIL, "");
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_EMAIL),
MSG_OUTPUT_MAY_NOT_BE_NULL_OR_EMPTY);
}
+ /**
+ * Try to enter one space like a email address and checks that validation
+ * message appears.
+ */
@Test
- public void emailMayNotBeNullOrEmpty() {
- openPage();
- typeAndSubmit(inputEmail, "");
- waitForTextEquals(getMessageFor(inputEmail),
- getMess("may-not-be-null-or-empty"));
+ public void testEmailOnlySpaces() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_EMAIL, " ");
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_EMAIL),
MSG_OUTPUT_NOT_WELL_FORMED_EMAIL);
}
+ /**
+ * Enter bad email address (only domain name suffix) and checks that
+ * validation message appears.
+ */
@Test
- public void emailOnlySpaces() {
- openPage();
- typeAndSubmit(inputEmail, " ");
- waitForTextEquals(getMessageFor(inputEmail),
- getMess("not-well-formed-email"));
+ public void testEmailBad1() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_EMAIL, MSG_INPUT_NOT_WELL_FORMED_EMAIL_1);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_EMAIL),
MSG_OUTPUT_NOT_WELL_FORMED_EMAIL);
}
+ /**
+ * Enter bad email address (only @ char with domain name suffix) and checks
+ * that testValidation message appears.
+ */
@Test
- public void emailBad1() {
- openPage();
- typeAndSubmit(inputEmail, getMess("bad-email-1"));
- waitForTextEquals(getMessageFor(inputEmail),
- getMess("not-well-formed-email"));
+ public void testEmailBad2() {
+ typeAndSubmit(LOC_INPUT_HIBERNATE_EMAIL, MSG_INPUT_NOT_WELL_FORMED_EMAIL_2);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_EMAIL),
MSG_OUTPUT_NOT_WELL_FORMED_EMAIL);
}
+ /**
+ * Enter bad email address, wait for validation message appear and then try
+ * to enter valid email address and checks that validation message appear.
+ */
@Test
- public void emailBad2() {
- openPage();
- typeAndSubmit(inputEmail, getMess("bad-email-2"));
- waitForTextEquals(getMessageFor(inputEmail),
- getMess("not-well-formed-email"));
+ public void testEmailMessageDisappers() {
+ // first violate validation error
+ testEmailMayNotBeNullOrEmpty();
+ // then try valid input
+ typeAndSubmit(LOC_INPUT_HIBERNATE_EMAIL, MSG_INPUT_WELL_FORMED_EMAIL);
+ waitForTextEquals(getMessageFor(LOC_INPUT_HIBERNATE_EMAIL), "");
}
+
+ private void typeAndSubmit(String locator, String value) {
+ selenium.type(locator, value);
+ selenium.click(LOC_BUTTON_SUBMIT);
+ }
- @Test
- public void emailMessageDisappers() {
- emailMayNotBeNullOrEmpty();
- typeAndSubmit(inputEmail, getMess("well-formed-email"));
- waitForTextEquals(getMessageFor(inputEmail), "");
+ private String getMessageFor(String locator) {
+ return format(LOC_VALIDATION_MESSAGE_RELATIVE, locator);
}
+
+ @SuppressWarnings("unused")
+ @BeforeMethod
+ private void loadPage() {
+ openComponent("Bean Validator");
+
+ scrollIntoView(LOC_FIELDSET_HEADER, true);
+ }
}
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/beanValidator/locators.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/beanValidator/locators.properties 2009-09-03
06:45:41 UTC (rev 15444)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/beanValidator/locators.properties 2009-09-03
11:13:01 UTC (rev 15445)
@@ -1,6 +1,6 @@
-bean-validator--header=//legend[text()\='Title']
-bean-validator--input--name=//input[@id\='beanValidatorForm\:name']
-bean-validator--input--email=//input[@id\='beanValidatorForm\:email']
-bean-validator--input--age=//input[@id\='beanValidatorForm\:age']
-bean-validator--relative--validation-message={0}/../../td[3]/*[1][@class\='rich-message']
-bean-validator--button--submit=//input[@type\='button' and
@value\='Submit']
\ No newline at end of file
+FIELDSET_HEADER=//legend[text()\='Title']
+BUTTON_SUBMIT=//input[@type\='button' and @value\='Submit']
+VALIDATION_MESSAGE_RELATIVE=//input[@id\='{0}']/../../td[3]/*[1][(a)class\='rich-message']
+INPUT_HIBERNATE_NAME=beanValidatorForm\:name
+INPUT_HIBERNATE_AGE=beanValidatorForm\:age
+INPUT_HIBERNATE_EMAIL=beanValidatorForm\:email
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/beanValidator/messages.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/beanValidator/messages.properties 2009-09-03
06:45:41 UTC (rev 15444)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/beanValidator/messages.properties 2009-09-03
11:13:01 UTC (rev 15445)
@@ -1,18 +1,18 @@
-may-not-be-null-or-empty=may not be null or empty
-less-than-minimum--enter=12
-bean-name--length=length must be between 3 and 12
-greater-than-maximum--enter=1234567890123
-bean-name--not-empty=This string contain only spaces
-bean-name--valid-input=Sam Hawkings
-may-not-be-null=may not be null
-long-range--bellow=17
-bean-age--min=must be greater than or equal to 18
-bean-age--max--enter=101
-bean-age--max=must be less than or equal to 100
-age-integer-only--enter=abc
-bean-age--integer-only={0}\: 'abc' must be a number between -2147483648 and
2147483647 Example\: 9346
-valid-age=18
-bad-email-1=corporation.com
-bad-email-2=(a)corporation.com
-well-formed-email=email(a)corporation.com
-not-well-formed-email=not a well-formed email address
+INPUT_VALUE_IS_LESS_THAN_MINIMUM=12
+INPUT_VALUE_IS_GREATER_THAN_MAXIMUM=1234567890123
+INPUT_IS_NOT_NUMBER=abc
+INPUT_VALID_AGE=18
+INPUT_VALID_NAME=Sam Hawkings
+INPUT_NOT_WELL_FORMED_EMAIL_1=corporation.com
+INPUT_NOT_WELL_FORMED_EMAIL_2=(a)corporation.com
+INPUT_WELL_FORMED_EMAIL=email(a)corporation.com
+INPUT_MUST_BE_GREATER_THAN_OR_EQUAL=17
+INPUT_MUST_BE_LESS_THAN_OR_EQUAL=101
+OUTPUT_STRING_CONTAIN_ONLY_SPACES=This string contain only spaces
+OUTPUT_LENGTH_MUST_BE_BETWEEN=length must be between 3 and 12
+OUTPUT_MAY_NOT_BE_NULL=may not be null
+OUTPUT_MUST_BE_GREATER_THAN_OR_EQUAL=must be greater than or equal to 18
+OUTPUT_MUST_BE_LESS_THAN_OR_EQUAL=must be less than or equal to 100
+OUTPUT_MUST_BE_A_NUMBER={0}\: 'abc' must be a number between -2147483648 and
2147483647 Example\: 9346
+OUTPUT_MAY_NOT_BE_NULL_OR_EMPTY=may not be null or empty
+OUTPUT_NOT_WELL_FORMED_EMAIL=not a well-formed email address