@Test public void testValidateValid() { UserGroup obj = new UserGroup(); obj.setName("Group 1"); obj.setDescription("Description 1"); UserAuthority auth1 = new UserAuthority(); auth1.setAuthority("AUTH_1"); UserAuthority auth2 = new UserAuthority(); auth2.setAuthority("AUTH_2"); obj.addAuthority(auth1); obj.addAuthority(auth2); BindException errors = new BindException(obj, "userGroup"); userGroupValidator.validate(obj, errors); assertTrue(errors.getAllErrors().size() == 0); }
public void validate(Object object, Errors errors) { UserGroup userGroup = (UserGroup) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.required", new Object[]{"Name"}); UserGroup lookFor = new UserGroup(); lookFor.setName(userGroup.getName()); List<UserGroup> groups = userGroupService.findByExample(lookFor); if(groups != null && !groups.isEmpty()) { if(userGroup.isNew()) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } else { UserGroup found = groups.get(0); if(!found.getId().equals(userGroup.getId())) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } } } }
UserGroupValidator implements Validator { public void validate(Object object, Errors errors) { UserGroup userGroup = (UserGroup) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.required", new Object[]{"Name"}); UserGroup lookFor = new UserGroup(); lookFor.setName(userGroup.getName()); List<UserGroup> groups = userGroupService.findByExample(lookFor); if(groups != null && !groups.isEmpty()) { if(userGroup.isNew()) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } else { UserGroup found = groups.get(0); if(!found.getId().equals(userGroup.getId())) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } } } } }
UserGroupValidator implements Validator { public void validate(Object object, Errors errors) { UserGroup userGroup = (UserGroup) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.required", new Object[]{"Name"}); UserGroup lookFor = new UserGroup(); lookFor.setName(userGroup.getName()); List<UserGroup> groups = userGroupService.findByExample(lookFor); if(groups != null && !groups.isEmpty()) { if(userGroup.isNew()) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } else { UserGroup found = groups.get(0); if(!found.getId().equals(userGroup.getId())) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } } } }  }
UserGroupValidator implements Validator { public void validate(Object object, Errors errors) { UserGroup userGroup = (UserGroup) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.required", new Object[]{"Name"}); UserGroup lookFor = new UserGroup(); lookFor.setName(userGroup.getName()); List<UserGroup> groups = userGroupService.findByExample(lookFor); if(groups != null && !groups.isEmpty()) { if(userGroup.isNew()) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } else { UserGroup found = groups.get(0); if(!found.getId().equals(userGroup.getId())) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } } } }  @SuppressWarnings("rawtypes") boolean supports(Class clazz); void validate(Object object, Errors errors); }
UserGroupValidator implements Validator { public void validate(Object object, Errors errors) { UserGroup userGroup = (UserGroup) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.required", new Object[]{"Name"}); UserGroup lookFor = new UserGroup(); lookFor.setName(userGroup.getName()); List<UserGroup> groups = userGroupService.findByExample(lookFor); if(groups != null && !groups.isEmpty()) { if(userGroup.isNew()) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } else { UserGroup found = groups.get(0); if(!found.getId().equals(userGroup.getId())) { errors.reject("error.user-group.duplicate", new Object[]{userGroup.getName()},userGroup.getName()); } } } }  @SuppressWarnings("rawtypes") boolean supports(Class clazz); void validate(Object object, Errors errors);  }