public void testValidatorReference() throws Exception {
HtmlForm form;
HtmlSubmitInput submit;
HtmlAnchor link;
HtmlTextInput input;
HtmlPage page;
page = getPage("/faces/methodref01.jsp");
form = getFormById(page, "form");
submit = (HtmlSubmitInput)
form.getInputByName("form" + NamingContainer.SEPARATOR_CHAR +
"validate");
// press the button with no value, see that no value appears in
// the "toValidate" textField.
page = (HtmlPage) submit.click();
form = getFormById(page, "form");
input = (HtmlTextInput)
form.getInputByName("form" + NamingContainer.SEPARATOR_CHAR +
"toValidate");
int fieldLen = input.asText().length();
assertTrue("Input does not have expected value", 0 == fieldLen);
// fill in an incorrect value, see that still no value appears
// in the text field.
input = (HtmlTextInput)
form.getInputByName("form" + NamingContainer.SEPARATOR_CHAR +
"toValidate");
input.setValueAttribute("aoeuaoeu");
submit = (HtmlSubmitInput)
form.getInputByName("form" + NamingContainer.SEPARATOR_CHAR +
"validate");
page = (HtmlPage) submit.click();
form = getFormById(page, "form");
input = (HtmlTextInput)
form.getInputByName("form" + NamingContainer.SEPARATOR_CHAR +
"toValidate");
fieldLen = input.asText().length();
assertTrue("Input does not have expected value", 8 == fieldLen);
// fill in the correct value, see that finally we have a value
input = (HtmlTextInput)
form.getInputByName("form" + NamingContainer.SEPARATOR_CHAR +
"toValidate");
input.setValueAttribute("batman");
submit = (HtmlSubmitInput)
form.getInputByName("form" + NamingContainer.SEPARATOR_CHAR +
"validate");
page = (HtmlPage) submit.click();
form = getFormById(page, "form");
input = (HtmlTextInput)
form.getInputByName("form" + NamingContainer.SEPARATOR_CHAR +
"toValidate");
assertEquals("Input does not have expected value",
"batman", input.asText());
}