/** * Creates an User with roles. * * @param login The user login. * @return The User. */ protected TestUser makeUser(String login) { TestUser user = new TestUser(); user.setEmail(login); int adminID = ps.queryFirst(TestRole.class, "select tr from TestRole tr where tr.name = 'admin'").getId(); int userID = ps.queryFirst(TestRole.class, "select tr from TestRole tr where tr.name = 'user'").getId(); Map<String, int[]> associations = new HashMap<String, int[]>(); associations.put("roles", new int[] {adminID, userID}); assertTrue(userService.persist(user, associations, "password")); return user; }
/** * Performs validation on the User class by passing the User object from the form submission to * the {@link UserService#validate(User,Map,boolean,String,String)} method. In order to accomodate * the username and email variations on the {@link DefaultUser} class, this checks the * configuration to see if the {@link UserConfiguration#isUsernameSameAsEmail()} method returns * true and if it does, it assumes that the form only has a field for the username and copies that * value from the username property to the email property. */ @SuppressWarnings("unchecked") @ValidateMethod public void validate() { // It is okay to create the user as a side-effect because it will be empty if (user == null) { user = new DefaultUser(); } if (userConfiguration.isUsernameSameAsEmail()) { user.setUsername(user.getEmail()); } ErrorList errors = userService.validate(user, associations, user.getId() != null, password, passwordConfirm); if (!errors.isEmpty()) { for (net.java.error.Error error : errors) { PropertyError pe = (PropertyError) error; messageStore.addFieldError(MessageScope.REQUEST, pe.getProperty(), pe.getMessage()); } } }