Search in sources :

Example 1 with ValidationConstraintGenerator

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) Locale(java.util.Locale) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) Field(org.apache.tapestry5.Field) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldValidator(org.apache.tapestry5.FieldValidator) FieldValidatorDefaultSource(org.apache.tapestry5.services.FieldValidatorDefaultSource) Test(org.testng.annotations.Test)

Example 2 with ValidationConstraintGenerator

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) Locale(java.util.Locale) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) Field(org.apache.tapestry5.Field) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldValidator(org.apache.tapestry5.FieldValidator) FieldValidatorDefaultSource(org.apache.tapestry5.services.FieldValidatorDefaultSource) Test(org.testng.annotations.Test)

Example 3 with ValidationConstraintGenerator

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) Locale(java.util.Locale) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) Field(org.apache.tapestry5.Field) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldValidatorDefaultSource(org.apache.tapestry5.services.FieldValidatorDefaultSource) FieldValidator(org.apache.tapestry5.FieldValidator) Test(org.testng.annotations.Test)

Example 4 with ValidationConstraintGenerator

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();
}
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 5 with ValidationConstraintGenerator

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();
}
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)

Aggregations

ValidationConstraintGenerator (org.apache.tapestry5.services.ValidationConstraintGenerator)7 Test (org.testng.annotations.Test)7 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)4 Locale (java.util.Locale)3 Field (org.apache.tapestry5.Field)3 FieldValidator (org.apache.tapestry5.FieldValidator)3 Validate (org.apache.tapestry5.beaneditor.Validate)3 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)3 Messages (org.apache.tapestry5.commons.Messages)3 FieldValidatorDefaultSource (org.apache.tapestry5.services.FieldValidatorDefaultSource)3 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)3 PrimitiveFieldConstraintGenerator (org.apache.tapestry5.internal.beaneditor.PrimitiveFieldConstraintGenerator)1 ValidateAnnotationConstraintGenerator (org.apache.tapestry5.internal.beaneditor.ValidateAnnotationConstraintGenerator)1