public void testTextboxControlMinMaxValidation() throws Exception {
//Basic
MockHttpServletRequest correctValueRequest = new MockHttpServletRequest();
correctValueRequest.addParameter("myTextBox", "i love me");
TextControl tc = new TextControl();
tc._getComponent().init(new MockEnviroment());
tc.setMinLength(new Long(5));
tc.setMaxLength(new Long(20));
MockUiLibUtil.emulateHandleRequest(tc, "myTextBox", correctValueRequest);
tc.convertAndValidate();
assertTrue("Textbox control must be valid.", tc.isValid());
assertTrue("Textbox control value must be 'i love me'.", ((String) tc.getRawValue()).equals("i love me"));
//Too short
MockHttpServletRequest tooShortValueRequest = new MockHttpServletRequest();
tooShortValueRequest.addParameter("myTextBox", "boo");
MockUiLibUtil.emulateHandleRequest(tc, "myTextBox", tooShortValueRequest);
tc.convertAndValidate();
assertTrue("Textbox control mustn't be valid.", !tc.isValid());
//Too long
MockHttpServletRequest tooLongValueRequest = new MockHttpServletRequest();
tooLongValueRequest.addParameter("myTextBox", "i love myself and others very very much");
MockUiLibUtil.emulateHandleRequest(tc, "myTextBox", tooLongValueRequest);
tc.convertAndValidate();
assertTrue("Textbox control mustn't be valid.", !tc.isValid());
//min=max correct
tc.setMinLength(new Long(10));
tc.setMaxLength(new Long(10));
correctValueRequest = new MockHttpServletRequest();
correctValueRequest.addParameter("myTextBox", "1234567890");
MockUiLibUtil.emulateHandleRequest(tc, "myTextBox", correctValueRequest);
tc.convertAndValidate();
assertTrue("Textbox control must be valid.", tc.isValid());
assertTrue("Textbox control value must be '1234567890'.", ((String) tc.getRawValue()).equals("1234567890"));
//min=max too short
tooShortValueRequest.addParameter("myTextBox", "123456789");
MockUiLibUtil.emulateHandleRequest(tc, "myTextBox", tooShortValueRequest);
tc.convertAndValidate();
assertTrue("Textbox control mustn't be valid.", !tc.isValid());
//min=max too long
tooShortValueRequest.addParameter("myTextBox", "12345678901");
MockUiLibUtil.emulateHandleRequest(tc, "myTextBox", tooShortValueRequest);
tc.convertAndValidate();
assertTrue("Textbox control mustn't be valid.", !tc.isValid());
tc._getComponent().destroy();
}