@Test(expected = ValidationException.class) public void validateParamsWithRedundentShortname() { HashSet<Person> coordinators = new HashSet<Person>(); final HashMap<String, Serializable> formData = new HashMap<String, Serializable>(); formData.put(DomainGroupModelView.NAME_KEY, ValidationTestHelper .generateString(DomainGroup.MAX_NAME_LENGTH + 1)); formData.put(DomainGroupModelView.SHORT_NAME_KEY, ValidationTestHelper .generateString(DomainGroup.MAX_SHORT_NAME_LENGTH)); formData.put(DomainGroupModelView.DESCRIPTION_KEY, ValidationTestHelper .generateString(DomainGroup.MAX_DESCRIPTION_LENGTH)); formData.put(DomainGroupModelView.COORDINATORS_KEY, coordinators); formData.put(DomainGroupModelView.PRIVACY_KEY, true); context.checking(new Expectations() { { allowing(actionContext).getParams(); will(returnValue(formData)); oneOf(groupMapperMock).findByShortName(with(any(String.class))); } }); try { sut.validate(actionContext); } catch (ValidationException ve) { context.assertIsSatisfied(); assertEquals(3, ve.getErrors().size()); assertTrue(ve.getErrors().containsValue(CreateGroupValidation.SHORTNAME_TAKEN_MESSAGE)); throw ve; } context.assertIsSatisfied(); }
@SuppressWarnings("unchecked") @Override public void validate(final ActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); String groupName = (String) vHelper .getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (groupName == null || groupName.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, groupName, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String groupShortName = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); if (groupShortName == null || groupShortName.isEmpty()) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, DomainGroup.SHORTNAME_REQUIRED); } else if (vHelper.stringMeetsRequirments(DomainGroupModelView.SHORT_NAME_KEY, groupShortName, ve, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.MAX_SHORT_NAME_LENGTH, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.ALPHA_NUMERIC_PATTERN, DomainGroup.SHORT_NAME_CHARACTERS)) { try { if (groupMapper.findByShortName(groupShortName.toLowerCase()) != null) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, SHORTNAME_TAKEN_MESSAGE); } } catch (Exception ex) { int x = 0; } } String groupDesc = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); if (groupDesc == null || groupDesc.isEmpty()) { ve.addError(DomainGroupModelView.DESCRIPTION_KEY, DomainGroup.DESCRIPTION_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, groupDesc, ve, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); } 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); } vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.PRIVACY_KEY, true, ve); if (!ve.getErrors().isEmpty()) { throw ve; } }
CreateGroupValidation implements ValidationStrategy<ActionContext> { @SuppressWarnings("unchecked") @Override public void validate(final ActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); String groupName = (String) vHelper .getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (groupName == null || groupName.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, groupName, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String groupShortName = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); if (groupShortName == null || groupShortName.isEmpty()) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, DomainGroup.SHORTNAME_REQUIRED); } else if (vHelper.stringMeetsRequirments(DomainGroupModelView.SHORT_NAME_KEY, groupShortName, ve, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.MAX_SHORT_NAME_LENGTH, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.ALPHA_NUMERIC_PATTERN, DomainGroup.SHORT_NAME_CHARACTERS)) { try { if (groupMapper.findByShortName(groupShortName.toLowerCase()) != null) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, SHORTNAME_TAKEN_MESSAGE); } } catch (Exception ex) { int x = 0; } } String groupDesc = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); if (groupDesc == null || groupDesc.isEmpty()) { ve.addError(DomainGroupModelView.DESCRIPTION_KEY, DomainGroup.DESCRIPTION_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, groupDesc, ve, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); } 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); } vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.PRIVACY_KEY, true, ve); if (!ve.getErrors().isEmpty()) { throw ve; } } }
CreateGroupValidation implements ValidationStrategy<ActionContext> { @SuppressWarnings("unchecked") @Override public void validate(final ActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); String groupName = (String) vHelper .getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (groupName == null || groupName.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, groupName, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String groupShortName = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); if (groupShortName == null || groupShortName.isEmpty()) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, DomainGroup.SHORTNAME_REQUIRED); } else if (vHelper.stringMeetsRequirments(DomainGroupModelView.SHORT_NAME_KEY, groupShortName, ve, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.MAX_SHORT_NAME_LENGTH, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.ALPHA_NUMERIC_PATTERN, DomainGroup.SHORT_NAME_CHARACTERS)) { try { if (groupMapper.findByShortName(groupShortName.toLowerCase()) != null) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, SHORTNAME_TAKEN_MESSAGE); } } catch (Exception ex) { int x = 0; } } String groupDesc = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); if (groupDesc == null || groupDesc.isEmpty()) { ve.addError(DomainGroupModelView.DESCRIPTION_KEY, DomainGroup.DESCRIPTION_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, groupDesc, ve, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); } 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); } vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.PRIVACY_KEY, true, ve); if (!ve.getErrors().isEmpty()) { throw ve; } } CreateGroupValidation(final DomainGroupMapper inGroupMapper); }
CreateGroupValidation implements ValidationStrategy<ActionContext> { @SuppressWarnings("unchecked") @Override public void validate(final ActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); String groupName = (String) vHelper .getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (groupName == null || groupName.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, groupName, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String groupShortName = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); if (groupShortName == null || groupShortName.isEmpty()) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, DomainGroup.SHORTNAME_REQUIRED); } else if (vHelper.stringMeetsRequirments(DomainGroupModelView.SHORT_NAME_KEY, groupShortName, ve, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.MAX_SHORT_NAME_LENGTH, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.ALPHA_NUMERIC_PATTERN, DomainGroup.SHORT_NAME_CHARACTERS)) { try { if (groupMapper.findByShortName(groupShortName.toLowerCase()) != null) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, SHORTNAME_TAKEN_MESSAGE); } } catch (Exception ex) { int x = 0; } } String groupDesc = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); if (groupDesc == null || groupDesc.isEmpty()) { ve.addError(DomainGroupModelView.DESCRIPTION_KEY, DomainGroup.DESCRIPTION_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, groupDesc, ve, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); } 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); } vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.PRIVACY_KEY, true, ve); if (!ve.getErrors().isEmpty()) { throw ve; } } CreateGroupValidation(final DomainGroupMapper inGroupMapper); @SuppressWarnings("unchecked") @Override void validate(final ActionContext inActionContext); }
CreateGroupValidation implements ValidationStrategy<ActionContext> { @SuppressWarnings("unchecked") @Override public void validate(final ActionContext inActionContext) throws ValidationException { Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams(); ValidationException ve = new ValidationException(); ValidationHelper vHelper = new ValidationHelper(); String groupName = (String) vHelper .getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve); if (groupName == null || groupName.isEmpty()) { ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, groupName, ve, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE); } String groupShortName = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve); if (groupShortName == null || groupShortName.isEmpty()) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, DomainGroup.SHORTNAME_REQUIRED); } else if (vHelper.stringMeetsRequirments(DomainGroupModelView.SHORT_NAME_KEY, groupShortName, ve, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.MAX_SHORT_NAME_LENGTH, DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.ALPHA_NUMERIC_PATTERN, DomainGroup.SHORT_NAME_CHARACTERS)) { try { if (groupMapper.findByShortName(groupShortName.toLowerCase()) != null) { ve.addError(DomainGroupModelView.SHORT_NAME_KEY, SHORTNAME_TAKEN_MESSAGE); } } catch (Exception ex) { int x = 0; } } String groupDesc = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY, true, ve); if (groupDesc == null || groupDesc.isEmpty()) { ve.addError(DomainGroupModelView.DESCRIPTION_KEY, DomainGroup.DESCRIPTION_REQUIRED); } else { vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, groupDesc, ve, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null); } 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); } vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.PRIVACY_KEY, true, ve); if (!ve.getErrors().isEmpty()) { throw ve; } } CreateGroupValidation(final DomainGroupMapper inGroupMapper); @SuppressWarnings("unchecked") @Override void validate(final ActionContext inActionContext);  }