use of org.apache.tapestry5.beaneditor.Validate 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.beaneditor.Validate 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.beaneditor.Validate in project tapestry-5 by apache.
the class ValidateAnnotationConstraintGeneratorTest method newValidate.
private Validate newValidate(String value) {
Validate annotation = newMock(Validate.class);
expect(annotation.value()).andReturn(value).atLeastOnce();
return annotation;
}
use of org.apache.tapestry5.beaneditor.Validate 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.beaneditor.Validate in project tapestry-5 by apache.
the class ValidateBindingFactoryTest method not_a_field.
@Test
public void not_a_field() {
FieldValidatorSource source = mockFieldValidatorSource();
ComponentResources container = mockComponentResources();
ComponentResources component = mockComponentResources();
Component instance = mockComponent();
Location l = mockLocation();
train_getComponent(component, instance);
train_getCompleteId(component, "foo.Bar:baz");
replay();
BindingFactory factory = new ValidateBindingFactory(source, interner);
try {
factory.newBinding("descrip", container, component, "zip,zoom", l);
} catch (TapestryException ex) {
assertEquals(ex.getMessage(), "Component 'foo.Bar:baz' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.");
assertSame(ex.getLocation(), l);
}
verify();
}
Aggregations