Search in sources :

Example 1 with ValidateAnnotationConstraintGenerator

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) Validate(org.apache.tapestry5.beaneditor.Validate) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) Test(org.testng.annotations.Test)

Example 2 with ValidateAnnotationConstraintGenerator

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) Validate(org.apache.tapestry5.beaneditor.Validate) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) Test(org.testng.annotations.Test)

Example 3 with ValidateAnnotationConstraintGenerator

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) Validate(org.apache.tapestry5.beaneditor.Validate) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) Test(org.testng.annotations.Test)

Example 4 with ValidateAnnotationConstraintGenerator

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) Test(org.testng.annotations.Test)

Example 5 with ValidateAnnotationConstraintGenerator

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);
}
Also used : ValidateAnnotationConstraintGenerator(org.apache.tapestry5.internal.beaneditor.ValidateAnnotationConstraintGenerator) PrimitiveFieldConstraintGenerator(org.apache.tapestry5.internal.beaneditor.PrimitiveFieldConstraintGenerator)

Aggregations

PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)4 ValidationConstraintGenerator (org.apache.tapestry5.services.ValidationConstraintGenerator)4 Test (org.testng.annotations.Test)4 Validate (org.apache.tapestry5.beaneditor.Validate)3 PrimitiveFieldConstraintGenerator (org.apache.tapestry5.internal.beaneditor.PrimitiveFieldConstraintGenerator)1 ValidateAnnotationConstraintGenerator (org.apache.tapestry5.internal.beaneditor.ValidateAnnotationConstraintGenerator)1