@Test(expected = ValidationException.class) public void validateParamsNoRequiredFields() { final HashMap<String, Serializable> formData = new HashMap<String, Serializable>(); context.checking(new Expectations() { { allowing(actionContext).getParams(); will(returnValue(formData)); } }); try { sut.validate(actionContext); } catch (ValidationException ve) { context.assertIsSatisfied(); assertEquals(6, ve.getErrors().size()); throw ve; } context.assertIsSatisfied(); }
@SuppressWarnings("unchecked") @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.ID_KEY, true, ve); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); String url = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.URL_KEY, false, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.URL_KEY, url, ve, null, null, null, CompositeEntity.URL_REGEX_PATTERN, DomainGroup.WEBSITE_MESSAGE); if (fields.containsKey(DomainGroupModelView.PRIVACY_KEY)) { throw new ValidationException(ValidationHelper.UNEXPECTED_DATA_ERROR_MESSAGE); } Set coordinators = (Set) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.COORDINATORS_KEY, true, ve); if (coordinators == null || coordinators.isEmpty()) { ve.addError(DomainGroupModelView.COORDINATORS_KEY, DomainGroup.MIN_COORDINATORS_MESSAGE); } String name = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (name == null || name.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, name, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String description = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, description, ve, null, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); String keywords = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.KEYWORDS_KEY, true, ve); if (keywords != null) { if (!vHelper.validBackgroundItems(keywords)) { ve.addError(DomainGroupModelView.KEYWORDS_KEY, DomainGroupModelView.KEYWORD_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } }
UpdateGroupValidation implements ValidationStrategy<PrincipalActionContext> { @SuppressWarnings("unchecked") @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.ID_KEY, true, ve); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); String url = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.URL_KEY, false, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.URL_KEY, url, ve, null, null, null, CompositeEntity.URL_REGEX_PATTERN, DomainGroup.WEBSITE_MESSAGE); if (fields.containsKey(DomainGroupModelView.PRIVACY_KEY)) { throw new ValidationException(ValidationHelper.UNEXPECTED_DATA_ERROR_MESSAGE); } Set coordinators = (Set) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.COORDINATORS_KEY, true, ve); if (coordinators == null || coordinators.isEmpty()) { ve.addError(DomainGroupModelView.COORDINATORS_KEY, DomainGroup.MIN_COORDINATORS_MESSAGE); } String name = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (name == null || name.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, name, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String description = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, description, ve, null, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); String keywords = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.KEYWORDS_KEY, true, ve); if (keywords != null) { if (!vHelper.validBackgroundItems(keywords)) { ve.addError(DomainGroupModelView.KEYWORDS_KEY, DomainGroupModelView.KEYWORD_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } } }
UpdateGroupValidation implements ValidationStrategy<PrincipalActionContext> { @SuppressWarnings("unchecked") @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.ID_KEY, true, ve); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); String url = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.URL_KEY, false, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.URL_KEY, url, ve, null, null, null, CompositeEntity.URL_REGEX_PATTERN, DomainGroup.WEBSITE_MESSAGE); if (fields.containsKey(DomainGroupModelView.PRIVACY_KEY)) { throw new ValidationException(ValidationHelper.UNEXPECTED_DATA_ERROR_MESSAGE); } Set coordinators = (Set) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.COORDINATORS_KEY, true, ve); if (coordinators == null || coordinators.isEmpty()) { ve.addError(DomainGroupModelView.COORDINATORS_KEY, DomainGroup.MIN_COORDINATORS_MESSAGE); } String name = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (name == null || name.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, name, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String description = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, description, ve, null, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); String keywords = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.KEYWORDS_KEY, true, ve); if (keywords != null) { if (!vHelper.validBackgroundItems(keywords)) { ve.addError(DomainGroupModelView.KEYWORDS_KEY, DomainGroupModelView.KEYWORD_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } }  }
UpdateGroupValidation implements ValidationStrategy<PrincipalActionContext> { @SuppressWarnings("unchecked") @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.ID_KEY, true, ve); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); String url = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.URL_KEY, false, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.URL_KEY, url, ve, null, null, null, CompositeEntity.URL_REGEX_PATTERN, DomainGroup.WEBSITE_MESSAGE); if (fields.containsKey(DomainGroupModelView.PRIVACY_KEY)) { throw new ValidationException(ValidationHelper.UNEXPECTED_DATA_ERROR_MESSAGE); } Set coordinators = (Set) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.COORDINATORS_KEY, true, ve); if (coordinators == null || coordinators.isEmpty()) { ve.addError(DomainGroupModelView.COORDINATORS_KEY, DomainGroup.MIN_COORDINATORS_MESSAGE); } String name = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (name == null || name.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, name, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String description = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, description, ve, null, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); String keywords = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.KEYWORDS_KEY, true, ve); if (keywords != null) { if (!vHelper.validBackgroundItems(keywords)) { ve.addError(DomainGroupModelView.KEYWORDS_KEY, DomainGroupModelView.KEYWORD_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } }  @SuppressWarnings("unchecked") @Override void validate(final PrincipalActionContext inActionContext); }
UpdateGroupValidation implements ValidationStrategy<PrincipalActionContext> { @SuppressWarnings("unchecked") @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.ID_KEY, true, ve); vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); String url = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.URL_KEY, false, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.URL_KEY, url, ve, null, null, null, CompositeEntity.URL_REGEX_PATTERN, DomainGroup.WEBSITE_MESSAGE); if (fields.containsKey(DomainGroupModelView.PRIVACY_KEY)) { throw new ValidationException(ValidationHelper.UNEXPECTED_DATA_ERROR_MESSAGE); } Set coordinators = (Set) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.COORDINATORS_KEY, true, ve); if (coordinators == null || coordinators.isEmpty()) { ve.addError(DomainGroupModelView.COORDINATORS_KEY, DomainGroup.MIN_COORDINATORS_MESSAGE); } String name = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (name == null || name.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, name, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String description = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, description, ve, null, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); String keywords = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.KEYWORDS_KEY, true, ve); if (keywords != null) { if (!vHelper.validBackgroundItems(keywords)) { ve.addError(DomainGroupModelView.KEYWORDS_KEY, DomainGroupModelView.KEYWORD_MESSAGE); } } if (!ve.getErrors().isEmpty()) { throw ve; } }  @SuppressWarnings("unchecked") @Override void validate(final PrincipalActionContext inActionContext);  }