use of org.apache.tapestry5.internal.beaneditor.ValidateAnnotationConstraintGenerator 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.internal.beaneditor.ValidateAnnotationConstraintGenerator 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();
}
use of org.apache.tapestry5.internal.beaneditor.ValidateAnnotationConstraintGenerator in project tapestry-5 by apache.
the class ValidateAnnotationConstraintGeneratorTest method single_constraint.
@Test
public void single_constraint() {
PropertyConduit conduit = mockPropertyConduit();
Validate validate = newValidate("required");
train_getAnnotation(conduit, Validate.class, validate);
replay();
ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator();
assertEquals(gen.buildConstraints(Object.class, conduit), Arrays.asList("required"));
verify();
}
use of org.apache.tapestry5.internal.beaneditor.ValidateAnnotationConstraintGenerator in project tapestry-5 by apache.
the class ValidateAnnotationConstraintGeneratorTest method no_annotation.
@Test
public void no_annotation() {
PropertyConduit conduit = mockPropertyConduit();
train_getAnnotation(conduit, Validate.class, null);
replay();
ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator();
assertNull(gen.buildConstraints(Object.class, conduit));
verify();
}
use of org.apache.tapestry5.internal.beaneditor.ValidateAnnotationConstraintGenerator in project tapestry-5 by apache.
the class TapestryModule method contributeValidationConstraintGenerator.
/**
* Adds built-in constraint generators:
* <ul>
* <li>PrimtiveField -- primitive fields are always required
* <li>ValidateAnnotation -- adds constraints from a {@link Validate} annotation
* </ul>
*/
public static void contributeValidationConstraintGenerator(OrderedConfiguration<ValidationConstraintGenerator> configuration) {
configuration.add("PrimitiveField", new PrimitiveFieldConstraintGenerator());
configuration.add("ValidateAnnotation", new ValidateAnnotationConstraintGenerator());
configuration.addInstance("Messages", MessagesConstraintGenerator.class);
}
Aggregations