@Test public void testGoodValidation() { HashMap<String, Serializable> formData = new HashMap<String, Serializable>(); formData.put(PersonModelView.TITILE_KEY, ValidationTestHelper.generateString(Person.MAX_TITLE_LENGTH)); formData.put(PersonModelView.PREFERREDNAME_KEY, ValidationTestHelper .generateString(UpdatePersonValidation.DEFAULT_MAX_STRING_LENGTH)); formData.put(PersonModelView.DESCRIPTION_KEY, ValidationTestHelper .generateString(Person.MAX_JOB_DESCRIPTION_LENGTH)); formData.put(PersonModelView.WORKPHONE_KEY, ValidationTestHelper.generateString(Person.MAX_PHONE_NUMBER_LENGTH)); formData.put(PersonModelView.EMAIL_KEY, "email@email.com"); formData.put(PersonModelView.SKILLS_KEY, ValidationTestHelper .generateString(BackgroundItem.MAX_BACKGROUND_ITEM_NAME_LENGTH)); final ServiceActionContext currentContext = new ServiceActionContext(formData, principalMock); sut.validate(currentContext); }
@SuppressWarnings({ "unchecked", "deprecation" }) @Override public void validate(final ServiceActionContext inActionContext) throws ValidationException { HashMap<String, Serializable> personData = (HashMap<String, Serializable>) inActionContext.getParams(); ValidationHelper vHelper = new ValidationHelper(); ValidationException ve = new ValidationException(); String title = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.TITILE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.TITILE_KEY, title, ve, "Title is required.", Person.MAX_TITLE_LENGTH, Person.TITLE_MESSAGE, null, null); String perferredName = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.PREFERREDNAME_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.PREFERREDNAME_KEY, perferredName, ve, PREFERREDNAME_MESSAGE, +DEFAULT_MAX_STRING_LENGTH, PREFERREDNAME_MESSAGE, "^[a-zA-Z\\'\\`\\ \\-]+$", "Display Name has invalid characters."); String description = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.DESCRIPTION_KEY, description, ve, null, Person.MAX_JOB_DESCRIPTION_LENGTH, Person.JOB_DESCRIPTION_MESSAGE, null, null); String workNumber = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.WORKPHONE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.WORKPHONE_KEY, workNumber, ve, null, Person.MAX_PHONE_NUMBER_LENGTH, Person.PHONE_NUMBER_MESSAGE, null, null); String email = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.EMAIL_KEY, true, ve); if (vHelper.stringMeetsRequirments(PersonModelView.EMAIL_KEY, email, ve, EMAIL_REQUIRED_MESSAGE, DEFAULT_MAX_STRING_LENGTH, EMAIL_LENGTH_MESSAGE, null, null) && StringUtils.isNotBlank(email)) { try { emailValidator.validate(email); } catch (ValidationException ex) { ve.addError(PersonModelView.EMAIL_KEY, ex.getMessage()); } } String skills = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.SKILLS_KEY, true, ve); if (skills != null) { if (!vHelper.validBackgroundItems(skills)) { ve.addError(PersonModelView.SKILLS_KEY, PersonModelView.SKILLS_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } }
UpdatePersonValidation implements ValidationStrategy<ServiceActionContext> { @SuppressWarnings({ "unchecked", "deprecation" }) @Override public void validate(final ServiceActionContext inActionContext) throws ValidationException { HashMap<String, Serializable> personData = (HashMap<String, Serializable>) inActionContext.getParams(); ValidationHelper vHelper = new ValidationHelper(); ValidationException ve = new ValidationException(); String title = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.TITILE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.TITILE_KEY, title, ve, "Title is required.", Person.MAX_TITLE_LENGTH, Person.TITLE_MESSAGE, null, null); String perferredName = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.PREFERREDNAME_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.PREFERREDNAME_KEY, perferredName, ve, PREFERREDNAME_MESSAGE, +DEFAULT_MAX_STRING_LENGTH, PREFERREDNAME_MESSAGE, "^[a-zA-Z\\'\\`\\ \\-]+$", "Display Name has invalid characters."); String description = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.DESCRIPTION_KEY, description, ve, null, Person.MAX_JOB_DESCRIPTION_LENGTH, Person.JOB_DESCRIPTION_MESSAGE, null, null); String workNumber = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.WORKPHONE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.WORKPHONE_KEY, workNumber, ve, null, Person.MAX_PHONE_NUMBER_LENGTH, Person.PHONE_NUMBER_MESSAGE, null, null); String email = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.EMAIL_KEY, true, ve); if (vHelper.stringMeetsRequirments(PersonModelView.EMAIL_KEY, email, ve, EMAIL_REQUIRED_MESSAGE, DEFAULT_MAX_STRING_LENGTH, EMAIL_LENGTH_MESSAGE, null, null) && StringUtils.isNotBlank(email)) { try { emailValidator.validate(email); } catch (ValidationException ex) { ve.addError(PersonModelView.EMAIL_KEY, ex.getMessage()); } } String skills = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.SKILLS_KEY, true, ve); if (skills != null) { if (!vHelper.validBackgroundItems(skills)) { ve.addError(PersonModelView.SKILLS_KEY, PersonModelView.SKILLS_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } } }
UpdatePersonValidation implements ValidationStrategy<ServiceActionContext> { @SuppressWarnings({ "unchecked", "deprecation" }) @Override public void validate(final ServiceActionContext inActionContext) throws ValidationException { HashMap<String, Serializable> personData = (HashMap<String, Serializable>) inActionContext.getParams(); ValidationHelper vHelper = new ValidationHelper(); ValidationException ve = new ValidationException(); String title = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.TITILE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.TITILE_KEY, title, ve, "Title is required.", Person.MAX_TITLE_LENGTH, Person.TITLE_MESSAGE, null, null); String perferredName = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.PREFERREDNAME_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.PREFERREDNAME_KEY, perferredName, ve, PREFERREDNAME_MESSAGE, +DEFAULT_MAX_STRING_LENGTH, PREFERREDNAME_MESSAGE, "^[a-zA-Z\\'\\`\\ \\-]+$", "Display Name has invalid characters."); String description = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.DESCRIPTION_KEY, description, ve, null, Person.MAX_JOB_DESCRIPTION_LENGTH, Person.JOB_DESCRIPTION_MESSAGE, null, null); String workNumber = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.WORKPHONE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.WORKPHONE_KEY, workNumber, ve, null, Person.MAX_PHONE_NUMBER_LENGTH, Person.PHONE_NUMBER_MESSAGE, null, null); String email = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.EMAIL_KEY, true, ve); if (vHelper.stringMeetsRequirments(PersonModelView.EMAIL_KEY, email, ve, EMAIL_REQUIRED_MESSAGE, DEFAULT_MAX_STRING_LENGTH, EMAIL_LENGTH_MESSAGE, null, null) && StringUtils.isNotBlank(email)) { try { emailValidator.validate(email); } catch (ValidationException ex) { ve.addError(PersonModelView.EMAIL_KEY, ex.getMessage()); } } String skills = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.SKILLS_KEY, true, ve); if (skills != null) { if (!vHelper.validBackgroundItems(skills)) { ve.addError(PersonModelView.SKILLS_KEY, PersonModelView.SKILLS_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } } UpdatePersonValidation(final EmailAddressValidator inEmailValidator); }
UpdatePersonValidation implements ValidationStrategy<ServiceActionContext> { @SuppressWarnings({ "unchecked", "deprecation" }) @Override public void validate(final ServiceActionContext inActionContext) throws ValidationException { HashMap<String, Serializable> personData = (HashMap<String, Serializable>) inActionContext.getParams(); ValidationHelper vHelper = new ValidationHelper(); ValidationException ve = new ValidationException(); String title = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.TITILE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.TITILE_KEY, title, ve, "Title is required.", Person.MAX_TITLE_LENGTH, Person.TITLE_MESSAGE, null, null); String perferredName = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.PREFERREDNAME_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.PREFERREDNAME_KEY, perferredName, ve, PREFERREDNAME_MESSAGE, +DEFAULT_MAX_STRING_LENGTH, PREFERREDNAME_MESSAGE, "^[a-zA-Z\\'\\`\\ \\-]+$", "Display Name has invalid characters."); String description = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.DESCRIPTION_KEY, description, ve, null, Person.MAX_JOB_DESCRIPTION_LENGTH, Person.JOB_DESCRIPTION_MESSAGE, null, null); String workNumber = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.WORKPHONE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.WORKPHONE_KEY, workNumber, ve, null, Person.MAX_PHONE_NUMBER_LENGTH, Person.PHONE_NUMBER_MESSAGE, null, null); String email = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.EMAIL_KEY, true, ve); if (vHelper.stringMeetsRequirments(PersonModelView.EMAIL_KEY, email, ve, EMAIL_REQUIRED_MESSAGE, DEFAULT_MAX_STRING_LENGTH, EMAIL_LENGTH_MESSAGE, null, null) && StringUtils.isNotBlank(email)) { try { emailValidator.validate(email); } catch (ValidationException ex) { ve.addError(PersonModelView.EMAIL_KEY, ex.getMessage()); } } String skills = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.SKILLS_KEY, true, ve); if (skills != null) { if (!vHelper.validBackgroundItems(skills)) { ve.addError(PersonModelView.SKILLS_KEY, PersonModelView.SKILLS_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } } UpdatePersonValidation(final EmailAddressValidator inEmailValidator); @SuppressWarnings({ "unchecked", "deprecation" }) @Override void validate(final ServiceActionContext inActionContext); }
UpdatePersonValidation implements ValidationStrategy<ServiceActionContext> { @SuppressWarnings({ "unchecked", "deprecation" }) @Override public void validate(final ServiceActionContext inActionContext) throws ValidationException { HashMap<String, Serializable> personData = (HashMap<String, Serializable>) inActionContext.getParams(); ValidationHelper vHelper = new ValidationHelper(); ValidationException ve = new ValidationException(); String title = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.TITILE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.TITILE_KEY, title, ve, "Title is required.", Person.MAX_TITLE_LENGTH, Person.TITLE_MESSAGE, null, null); String perferredName = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.PREFERREDNAME_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.PREFERREDNAME_KEY, perferredName, ve, PREFERREDNAME_MESSAGE, +DEFAULT_MAX_STRING_LENGTH, PREFERREDNAME_MESSAGE, "^[a-zA-Z\\'\\`\\ \\-]+$", "Display Name has invalid characters."); String description = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.DESCRIPTION_KEY, description, ve, null, Person.MAX_JOB_DESCRIPTION_LENGTH, Person.JOB_DESCRIPTION_MESSAGE, null, null); String workNumber = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.WORKPHONE_KEY, true, ve); vHelper.stringMeetsRequirments(PersonModelView.WORKPHONE_KEY, workNumber, ve, null, Person.MAX_PHONE_NUMBER_LENGTH, Person.PHONE_NUMBER_MESSAGE, null, null); String email = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.EMAIL_KEY, true, ve); if (vHelper.stringMeetsRequirments(PersonModelView.EMAIL_KEY, email, ve, EMAIL_REQUIRED_MESSAGE, DEFAULT_MAX_STRING_LENGTH, EMAIL_LENGTH_MESSAGE, null, null) && StringUtils.isNotBlank(email)) { try { emailValidator.validate(email); } catch (ValidationException ex) { ve.addError(PersonModelView.EMAIL_KEY, ex.getMessage()); } } String skills = (String) vHelper.getAndCheckStringFieldExist(personData, PersonModelView.SKILLS_KEY, true, ve); if (skills != null) { if (!vHelper.validBackgroundItems(skills)) { ve.addError(PersonModelView.SKILLS_KEY, PersonModelView.SKILLS_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } } UpdatePersonValidation(final EmailAddressValidator inEmailValidator); @SuppressWarnings({ "unchecked", "deprecation" }) @Override void validate(final ServiceActionContext inActionContext);  }