use of org.asqatasun.webapp.command.CreateUserCommand in project Asqatasun by Asqatasun.
the class SignUpControllerTest method createValidUserSignUpCommand.
/**
* Create an valid instance (the email attribute is initialised) of
* UserSignUpCommand
*
* @return
*/
private CreateUserCommand createValidUserSignUpCommand() {
CreateUserCommand createUserCommand = new CreateUserCommand();
createUserCommand.setEmail("test@test.com");
createUserCommand.setSiteUrl("http://mysite.org");
createUserCommand.setPassword("password");
createUserCommand.setConfirmPassword("password");
return createUserCommand;
}
use of org.asqatasun.webapp.command.CreateUserCommand in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testEditUserAdminPage.
/**
* Test of editUserAdminPage method, of class UserManagementController.
*/
public void testEditUserAdminPage() {
System.out.println("editUserAdminPage");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, false, false, false, false);
setUpMockAuthenticationContext();
instance.setUserDataService(mockUserDataService);
String userId = "";
HttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
Model model = new ExtendedModelMap();
try {
instance.displayEditUserAdminPage(userId, request, response, model);
assertTrue(false);
} catch (ForbiddenUserException nue) {
assertTrue(true);
}
userId = "4";
String result = instance.displayEditUserAdminPage(userId, request, response, model);
assertEquals(TgolKeyStore.EDIT_USER_VIEW_NAME, result);
CreateUserCommand cuc = ((CreateUserCommand) model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY));
assertNotNull(cuc);
assertTrue(cuc.getActivated());
assertTrue(cuc.getAdmin());
assertEquals("admin@test.com", cuc.getEmail());
assertEquals("http://www.admin.com", cuc.getSiteUrl());
assertEquals("0123456789", cuc.getPhoneNumber());
assertEquals("nameAdmin", cuc.getLastName());
assertEquals("firstNameAdmin", cuc.getFirstName());
assertEquals(Long.valueOf(4), request.getSession().getAttribute(TgolKeyStore.USER_ID_KEY));
userId = "5";
result = instance.displayEditUserAdminPage(userId, request, response, model);
assertEquals(TgolKeyStore.EDIT_USER_VIEW_NAME, result);
cuc = ((CreateUserCommand) model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY));
assertNotNull(cuc);
assertFalse(cuc.getActivated());
assertFalse(cuc.getAdmin());
assertEquals("user@test.com", cuc.getEmail());
assertEquals("http://www.user.com", cuc.getSiteUrl());
assertEquals("9876543210", cuc.getPhoneNumber());
assertEquals("nameUser", cuc.getLastName());
assertEquals("firstNameUser", cuc.getFirstName());
assertEquals(Long.valueOf(5), request.getSession().getAttribute(TgolKeyStore.USER_ID_KEY));
}
use of org.asqatasun.webapp.command.CreateUserCommand 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.asqatasun.webapp.command.CreateUserCommand 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.asqatasun.webapp.command.CreateUserCommand in project Asqatasun by Asqatasun.
the class CreateUserCommandFactory method getNewCreateUserCommand.
public CreateUserCommand getNewCreateUserCommand() {
CreateUserCommand createUserCommand = new CreateUserCommand();
createUserCommand.setAdmin(false);
return createUserCommand;
}
Aggregations