@SuppressWarnings("unchecked") @Test public void multiple_validators_via_specification() throws Exception { Validator required = mockValidator(); Validator minLength = mockValidator(); TypeCoercer coercer = mockTypeCoercer(); FieldComponent field = newFieldComponent(); Messages messages = mockMessages(); MessageFormatter requiredFormatter = mockMessageFormatter(); MessageFormatter minLengthFormatter = mockMessageFormatter(); Object inputValue = "input value"; ComponentResources resources = mockComponentResources(); Messages containerMessages = mockMessages(); Integer fifteen = 15; FormSupport fs = mockFormSupport(); Messages globalMessages = mockMessages(); Map<String, Validator> map = newMap(); map.put("required", required); map.put("minLength", minLength); train_getFormValidationId(fs, "myform"); train_getConstraintType(required, null); train_getConstraintType(minLength, Integer.class); train_getComponentResources(field, resources); train_getId(resources, "fred"); train_getContainerMessages(resources, containerMessages); train_contains(containerMessages, "myform-fred-required-message", false); train_contains(containerMessages, "fred-required-message", false); train_getMessageKey(required, "required"); train_getMessageFormatter(globalMessages, "required", requiredFormatter); train_contains(containerMessages, "myform-fred-minLength-message", false); train_contains(containerMessages, "fred-minLength-message", false); train_getMessageKey(minLength, "min-length"); train_getMessageFormatter(globalMessages, "min-length", minLengthFormatter); train_coerce(coercer, "15", Integer.class, fifteen); train_isRequired(required, true); train_getValueType(required, Object.class); required.validate(field, null, requiredFormatter, inputValue); train_isRequired(minLength, false); train_getValueType(minLength, String.class); minLength.validate(field, fifteen, minLengthFormatter, inputValue); ValidatorMacro macro = mockValidatorMacro(); train_alwaysNull(macro); replay(); FieldValidatorSource source = new FieldValidatorSourceImpl(globalMessages, coercer, fs, map, macro); FieldValidator fieldValidator = source.createValidators(field, "required,minLength=15"); fieldValidator.validate(inputValue); verify(); }
public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); } }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); } FieldValidatorSourceImpl(Messages globalMessages, TypeCoercer typeCoercer,
                                    FormSupport formSupport, Map<String, Validator> validators, ValidatorMacro validatorMacro); }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); } FieldValidatorSourceImpl(Messages globalMessages, TypeCoercer typeCoercer,
                                    FormSupport formSupport, Map<String, Validator> validators, ValidatorMacro validatorMacro); FieldValidator createValidator(Field field, String validatorType, String constraintValue); FieldValidator createValidator(Field field, String validatorType, String constraintValue, String overrideId,
                                          Messages overrideMessages, Locale locale); FieldValidator createValidators(Field field, String specification); }
FieldValidatorSourceImpl implements FieldValidatorSource { public FieldValidator createValidators(Field field, String specification) { List<ValidatorSpecification> specs = toValidatorSpecifications(specification); List<FieldValidator> fieldValidators = CollectionFactory.newList(); for (ValidatorSpecification spec : specs) { fieldValidators.add(createValidator(field, spec.getValidatorType(), spec.getConstraintValue())); } if (fieldValidators.size() == 1) return fieldValidators.get(0); return new CompositeFieldValidator(fieldValidators); } FieldValidatorSourceImpl(Messages globalMessages, TypeCoercer typeCoercer,
                                    FormSupport formSupport, Map<String, Validator> validators, ValidatorMacro validatorMacro); FieldValidator createValidator(Field field, String validatorType, String constraintValue); FieldValidator createValidator(Field field, String validatorType, String constraintValue, String overrideId,
                                          Messages overrideMessages, Locale locale); FieldValidator createValidators(Field field, String specification);  }