Testing setRequired(true) behavior of PasswordTestField fails -------------------------------------------------------------
Key: WICKET-768 URL: https://issues.apache.org/jira/browse/WICKET-768 Project: Wicket Issue Type: Bug Components: wicket Affects Versions: 1.3.0-beta2 Environment: any Reporter: David Rosenstrauch Priority: Minor When testing a PasswordTextField (using Junit and WicketTester), the testing fails - incorrectly, I believe. I created a simple page and form with a PasswordTextField on it, then used WicketTester/FormTester to test the setRequired() behavior. If I leave the field blank before I submit the form, then that should generate a validation error that the field is required. Instead, I get none, the form submits correctly, and the password value that gets delivered to the model is a bizarre value: XPauhDrxdC0 Interesting to note: * This problem does not appear to happen in a live application. In a live application, the "required" message is generated correctly. It only appears to happen when under test. * This behavior does not happen if I switch the PasswordTextField to become a regular RequiredTextField. When using a RequiredTextField with the exact same code, the error message is generated correctly. Code to reproduce follows: TestPasswordRequired.java ------------------------- import junit.framework.TestCase; import org.apache.wicket.feedback.FeedbackMessage; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTester; public class TestPasswordRequired extends TestCase { public void testPasswordRequired() { WicketTester tester = new WicketTester(); Class pageClass = PasswordPage.class; tester.startPage(pageClass); tester.assertRenderedPage(pageClass); tester.assertNoErrorMessage(); FormTester formTester = tester.newFormTester(PasswordPage.FORM_NAME); formTester.submit(); assertEquals(1, tester.getMessages(FeedbackMessage.ERROR).size()); } } PasswordPage.java ----------------- import java.io.Serializable; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.PasswordTextField; import org.apache.wicket.markup.html.form.RequiredTextField; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.model.CompoundPropertyModel; import org.apache.wicket.model.Model; public class PasswordPage extends WebPage { public PasswordPage() { add(new FeedbackPanel("errors")); add(new PasswordRequiredForm(FORM_NAME)); } private static class PasswordRequiredForm extends Form { public PasswordRequiredForm(String formName) { super(formName, new CompoundPropertyModel(new PasswordHolder())); passwordField = new PasswordTextField(PASSWORD_FIELD_NAME); // passwordField = new RequiredTextField(PASSWORD_FIELD_NAME); add(passwordField); } protected void onSubmit() { System.out.println("submit successful; password field value: "+passwordField.getValue()); } private TextField passwordField; } private static class PasswordHolder implements Serializable { public String getPassword() { return password; } public void setPassword(String password) { System.out.println("set password: "+password); this.password = password; } private String password; } public static final String FORM_NAME = "form"; public static final String PASSWORD_FIELD_NAME = "password"; } PasswordPage.html ----------------- <html> <head><title>Password required test page</title></head> <body> <span wicket:id="errors"/> <form wicket:id="form"> <input type="password" wicket:id="password"/> <!--<input type="text" wicket:id="password"/>--> </form> </body> </html> -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.