use of org.springframework.validation.BeanPropertyBindingResult in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitAddAdminUserForm.
/**
* Test of submitAddUserForm method, of class UserManagementController.
*/
public void testSubmitAddAdminUserForm() throws Exception {
System.out.println("SubmitAddAdminUserForm");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, true, true, false, false);
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.setSiteUrl("http://www.newSite.com/");
createUserCommand.setEmail("newUser@test.com");
createUserCommand.setPassword("P4sSw0rD");
createUserCommand.setConfirmPassword("P4sSw0rD");
createUserCommand.setAdmin(true);
createUserCommand.setActivated(true);
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
assertFalse(bindingResult.hasErrors());
assertTrue(bindingResult.getFieldErrors().isEmpty());
assertEquals(2, model.asMap().size());
assertEquals("newUser@test.com", model.asMap().get(TgolKeyStore.ADDED_USER_NAME_KEY));
assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
use of org.springframework.validation.BeanPropertyBindingResult in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitAddUserForm.
/**
* Test of submitAddUserForm method, of class UserManagementController.
*/
public void testSubmitAddUserForm() throws Exception {
System.out.println("submitAddUserForm");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, true, false, false, false);
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.setSiteUrl("http://www.newSite.com/");
createUserCommand.setEmail("newUser@test.com");
createUserCommand.setPassword("P4sSw0rD");
createUserCommand.setConfirmPassword("P4sSw0rD");
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
assertFalse(bindingResult.hasErrors());
assertTrue(bindingResult.getFieldErrors().isEmpty());
assertEquals(2, model.asMap().size());
assertEquals("newUser@test.com", model.asMap().get(TgolKeyStore.ADDED_USER_NAME_KEY));
assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
use of org.springframework.validation.BeanPropertyBindingResult in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitEditUserChangeToExistingUserForm.
/**
* Test of submitEditUserForm method, of class UserManagementController.
*/
public void testSubmitEditUserChangeToExistingUserForm() throws Exception {
System.out.println("SubmitEditUserChangeToExistingUserForm");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, false, false, false, false);
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.setSiteUrl("http://www.newSite.com/");
createUserCommand.setEmail("admin@test.com");
MockHttpServletRequest request = new MockHttpServletRequest();
request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, Long.valueOf(5));
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitEditUserForm(createUserCommand, bindingResult, request, model);
assertEquals(TgolKeyStore.EDIT_USER_VIEW_NAME, result);
assertTrue(bindingResult.hasErrors());
assertEquals(1, bindingResult.getFieldErrors().size());
assertNotNull(bindingResult.getFieldErrors("email"));
assertEquals(1, bindingResult.getFieldErrors("email").size());
assertEquals("sign-up.existingAccountWithEmail", bindingResult.getFieldErrors("email").get(0).getCode());
}
use of org.springframework.validation.BeanPropertyBindingResult in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitAddUserFormWithErrors.
/**
* Test of submitAddUserForm method, of class UserManagementController.
*/
public void testSubmitAddUserFormWithErrors() throws Exception {
System.out.println("SubmitAddUserFormWithErrors");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, false, false, false, false);
setUpMockAuthenticationContext();
instance.setUserDataService(mockUserDataService);
CreateUserFormValidator createUserFormValidator = new CreateUserFormValidator();
createUserFormValidator.setUserDataService(mockUserDataService);
instance.setCreateUserFormValidator(createUserFormValidator);
// First the form is sent back empty
CreateUserCommand createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
assertEquals(TgolKeyStore.ADD_USER_VIEW_NAME, result);
assertTrue(bindingResult.hasErrors());
assertEquals(3, bindingResult.getFieldErrors().size());
assertNotNull(bindingResult.getFieldErrors("email"));
assertEquals(1, bindingResult.getFieldErrors("email").size());
assertEquals("sign-up.missingEmail", bindingResult.getFieldErrors("email").get(0).getCode());
assertNotNull(bindingResult.getFieldErrors("password"));
assertEquals(1, bindingResult.getFieldErrors("password").size());
assertEquals("sign-up.missingPassword", bindingResult.getFieldErrors("password").get(0).getCode());
assertNotNull(bindingResult.getFieldErrors("generalErrorMsg"));
assertEquals(1, bindingResult.getFieldErrors("generalErrorMsg").size());
assertEquals("sign-up.mandatoryField", bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode());
// First the form is sent back with passwords that don't match
createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
createUserCommand.setEmail("user@test.com");
createUserCommand.setPassword("password");
createUserCommand.setConfirmPassword("confirmation");
bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
model = new ExtendedModelMap();
result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
assertEquals(TgolKeyStore.ADD_USER_VIEW_NAME, result);
assertTrue(bindingResult.hasErrors());
assertEquals(3, bindingResult.getFieldErrors().size());
assertNotNull(bindingResult.getFieldErrors("email"));
assertEquals(1, bindingResult.getFieldErrors("email").size());
assertEquals("sign-up.existingAccountWithEmail", bindingResult.getFieldErrors("email").get(0).getCode());
assertNotNull(bindingResult.getFieldErrors("password"));
assertEquals(1, bindingResult.getFieldErrors("password").size());
assertEquals("sign-up.passwordNotIdentical", bindingResult.getFieldErrors("password").get(0).getCode());
assertNotNull(bindingResult.getFieldErrors("generalErrorMsg"));
assertEquals(1, bindingResult.getFieldErrors("generalErrorMsg").size());
assertEquals("sign-up.mandatoryField", bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode());
// Then the url is not conform but in this context it is not tested, so ignored
// The Email1 is not conform regardin the pattern EMAIL_CHECKER_REGEXP
// The passwords match but don't respect the constraints
createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
createUserCommand.setEmail("null");
createUserCommand.setPassword("password");
createUserCommand.setConfirmPassword("password");
bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
model = new ExtendedModelMap();
result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
assertEquals(TgolKeyStore.ADD_USER_VIEW_NAME, result);
assertTrue(bindingResult.hasErrors());
assertEquals(3, bindingResult.getFieldErrors().size());
assertNotNull(bindingResult.getFieldErrors("email"));
assertEquals(1, bindingResult.getFieldErrors("email").size());
assertEquals("sign-up.invalidEmail", bindingResult.getFieldErrors("email").get(0).getCode());
assertNotNull(bindingResult.getFieldErrors("password"));
assertEquals(1, bindingResult.getFieldErrors("password").size());
assertEquals("sign-up.invalidPassword", bindingResult.getFieldErrors("password").get(0).getCode());
assertNotNull(bindingResult.getFieldErrors("generalErrorMsg"));
assertEquals(1, bindingResult.getFieldErrors("generalErrorMsg").size());
assertEquals("sign-up.mandatoryField", bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode());
}
use of org.springframework.validation.BeanPropertyBindingResult in project spring-framework by spring-projects.
the class ModelResultMatchersTests method setUp.
@Before
public void setUp() throws Exception {
this.matchers = new ModelResultMatchers();
ModelAndView mav = new ModelAndView("view", "good", "good");
BindingResult bindingResult = new BeanPropertyBindingResult("good", "good");
mav.addObject(BindingResult.MODEL_KEY_PREFIX + "good", bindingResult);
this.mvcResult = getMvcResult(mav);
Date date = new Date();
BindingResult bindingResultWithError = new BeanPropertyBindingResult(date, "date");
bindingResultWithError.rejectValue("time", "error");
ModelAndView mavWithError = new ModelAndView("view", "good", "good");
mavWithError.addObject("date", date);
mavWithError.addObject(BindingResult.MODEL_KEY_PREFIX + "date", bindingResultWithError);
this.mvcResultWithError = getMvcResult(mavWithError);
}
Aggregations