use of org.apache.tapestry5.services.ValidationConstraintGenerator in project tapestry-5 by apache.
the class FieldValidatorDefaultSourceImplTest method invokes_all_constraint_generators.
@SuppressWarnings("unchecked")
@Test
public void invokes_all_constraint_generators() throws Exception {
getMocksControl().checkOrder(true);
ValidationConstraintGenerator gen = mockValidationConstraintGenerator();
FieldValidator fv1 = mockFieldValidator();
FieldValidator fv2 = mockFieldValidator();
FieldValidatorSource source = mockFieldValidatorSource();
Class propertyType = Integer.class;
AnnotationProvider provider = mockAnnotationProvider();
String overrideId = "overrideId";
Messages overrideMessages = mockMessages();
Field field = mockField();
Locale locale = Locale.ENGLISH;
String value = "*VALUE*";
train_buildConstraints(gen, propertyType, provider, "cons1", "cons2");
train_createValidator(source, field, "cons1", null, overrideId, overrideMessages, locale, fv1);
train_createValidator(source, field, "cons2", null, overrideId, overrideMessages, locale, fv2);
fv1.validate(value);
fv2.validate(value);
replay();
FieldValidatorDefaultSource fieldValidatorSource = new FieldValidatorDefaultSourceImpl(gen, source);
FieldValidator composite = fieldValidatorSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, provider);
composite.validate(value);
verify();
}
use of org.apache.tapestry5.services.ValidationConstraintGenerator in project tapestry-5 by apache.
the class FieldValidatorDefaultSourceImplTest method validator_with_constraint.
@SuppressWarnings("unchecked")
@Test
public void validator_with_constraint() throws Exception {
ValidationConstraintGenerator gen = mockValidationConstraintGenerator();
FieldValidator fv = mockFieldValidator();
FieldValidatorSource source = mockFieldValidatorSource();
Class propertyType = Integer.class;
AnnotationProvider provider = mockAnnotationProvider();
String overrideId = "overrideId";
Messages overrideMessages = mockMessages();
Field field = mockField();
Locale locale = Locale.ENGLISH;
train_buildConstraints(gen, propertyType, provider, "foo=bar");
train_createValidator(source, field, "foo", "bar", overrideId, overrideMessages, locale, fv);
replay();
FieldValidatorDefaultSource fieldValidatorSource = new FieldValidatorDefaultSourceImpl(gen, source);
FieldValidator composite = fieldValidatorSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, provider);
assertSame(composite, fv);
verify();
}
use of org.apache.tapestry5.services.ValidationConstraintGenerator in project tapestry-5 by apache.
the class FieldValidatorDefaultSourceImplTest method no_validators_at_all.
@SuppressWarnings("unchecked")
@Test
public void no_validators_at_all() throws Exception {
ValidationConstraintGenerator gen = mockValidationConstraintGenerator();
FieldValidatorSource source = mockFieldValidatorSource();
Class propertyType = Integer.class;
AnnotationProvider provider = mockAnnotationProvider();
String overrideId = "overrideId";
Messages overrideMessages = mockMessages();
Field field = mockField();
Locale locale = Locale.ENGLISH;
String value = "*VALUE*";
train_buildConstraints(gen, propertyType, provider);
replay();
FieldValidatorDefaultSource fieldValidatorSource = new FieldValidatorDefaultSourceImpl(gen, source);
FieldValidator composite = fieldValidatorSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, provider);
composite.validate(value);
verify();
}
use of org.apache.tapestry5.services.ValidationConstraintGenerator in project tapestry-5 by apache.
the class ValidateAnnotationConstraintGeneratorTest method multiple_constraints.
@Test
public void multiple_constraints() {
PropertyConduit conduit = mockPropertyConduit();
Validate validate = newValidate("required,minlength=3,regexp=^([a-zA-Z0-9]{2,4})+$");
train_getAnnotation(conduit, Validate.class, validate);
replay();
ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator();
assertEquals(gen.buildConstraints(null, conduit), Arrays.asList("required", "minlength=3", "regexp=^([a-zA-Z0-9]{2,4})+$"));
verify();
}
use of org.apache.tapestry5.services.ValidationConstraintGenerator in project tapestry-5 by apache.
the class ValidateAnnotationConstraintGeneratorTest method regex_ranges_constraints.
@Test
public void regex_ranges_constraints() {
PropertyConduit conduit = mockPropertyConduit();
Validate validate = newValidate("regexp=^([a]{50,125}[0-9]{2,4})+$,required,567matcher,regexp=a\\,b,regexp=a{1,}");
train_getAnnotation(conduit, Validate.class, validate);
replay();
ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator();
assertEquals(gen.buildConstraints(null, conduit), Arrays.asList("regexp=^([a]{50,125}[0-9]{2,4})+$", "required", "567matcher", "regexp=a\\,b", "regexp=a{1,}"));
verify();
}
Aggregations