use of org.springframework.validation.BeanPropertyBindingResult in project spring-framework by spring-projects.
the class HiddenInputTagTests method withCustomBinder.
@Test
public void withCustomBinder() throws Exception {
this.tag.setPath("myFloat");
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
errors.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor());
exposeBindingResult(errors);
assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());
String output = getOutput();
assertTagOpened(output);
assertTagClosed(output);
assertContainsAttribute(output, "type", "hidden");
assertContainsAttribute(output, "value", "12.34f");
}
use of org.springframework.validation.BeanPropertyBindingResult in project spring-framework by spring-projects.
the class InputTagTests method withErrors.
@Test
public void withErrors() throws Exception {
this.tag.setPath("name");
this.tag.setCssClass("good");
this.tag.setCssErrorClass("bad");
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.rob, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default Message");
errors.rejectValue("name", "too.short", "Too Short");
exposeBindingResult(errors);
assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());
String output = getOutput();
assertTagOpened(output);
assertTagClosed(output);
assertContainsAttribute(output, "type", getType());
assertValueAttribute(output, "Rob");
assertContainsAttribute(output, "class", "bad");
}
use of org.springframework.validation.BeanPropertyBindingResult in project spring-framework by spring-projects.
the class OptionTagTests method multiBind.
@Test
public void multiBind() throws Exception {
BeanPropertyBindingResult result = new BeanPropertyBindingResult(new TestBean(), "testBean");
result.getPropertyAccessor().registerCustomEditor(TestBean.class, "friends", new FriendEditor());
exposeBindingResult(result);
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.friends", false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue(new TestBean("foo"));
this.tag.doStartTag();
this.tag.doEndTag();
assertEquals("<option value=\"foo\">foo</option>", getOutput());
}
use of org.springframework.validation.BeanPropertyBindingResult in project spring-framework by spring-projects.
the class CheckboxTagTests method collectionOfPetsWithEditor.
@Test
public void collectionOfPetsWithEditor() throws Exception {
this.tag.setPath("pets");
this.tag.setValue(new ItemPet("Rudiger"));
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
PropertyEditorSupport editor = new ItemPet.CustomEditor();
bindingResult.getPropertyEditorRegistry().registerCustomEditor(ItemPet.class, editor);
getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);
int result = this.tag.doStartTag();
assertEquals(Tag.SKIP_BODY, result);
String output = getOutput();
// wrap the output so it is valid XML
output = "<doc>" + output + "</doc>";
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(output));
Element checkboxElement = (Element) document.getRootElement().elements().get(0);
assertEquals("input", checkboxElement.getName());
assertEquals("checkbox", checkboxElement.attribute("type").getValue());
assertEquals("pets", checkboxElement.attribute("name").getValue());
assertEquals("Rudiger", checkboxElement.attribute("value").getValue());
assertEquals("checked", checkboxElement.attribute("checked").getValue());
}
use of org.springframework.validation.BeanPropertyBindingResult in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitEditCurrentUserForm.
/**
* Test of submitEditUserForm method, of class UserManagementController.
*/
public void testSubmitEditCurrentUserForm() throws Exception {
System.out.println("testSubmitEditCurrentUserForm");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, false, false, false, true);
setUpMockAuthenticationContext();
instance.setUserDataService(mockUserDataService);
CreateUserFormValidator createUserFormValidator = new CreateUserFormValidator();
createUserFormValidator.setUserDataService(mockUserDataService);
instance.setCreateUserFormValidator(createUserFormValidator);
// Finally the form is conform and the admin page is returned
CreateUserCommand createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
createUserCommand.setEmail("admin@test.com");
createUserCommand.setLastName("newName");
createUserCommand.setFirstName("newFirstName");
createUserCommand.setPhoneNumber("0102030405");
createUserCommand.setActivated(false);
createUserCommand.setAdmin(false);
MockHttpServletRequest request = new MockHttpServletRequest();
request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, Long.valueOf(4));
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitEditUserForm(createUserCommand, bindingResult, request, model);
assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
assertFalse(bindingResult.hasErrors());
assertTrue(bindingResult.getFieldErrors().isEmpty());
assertEquals(2, model.asMap().size());
assertEquals("admin@test.com", model.asMap().get(TgolKeyStore.UPDATED_USER_NAME_KEY));
assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
Aggregations