Search in sources :

Example 21 with Validate

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

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

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

Example 24 with Validate

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

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();
}
Also used : FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) FieldComponent(org.apache.tapestry5.root.FieldComponent) Component(org.apache.tapestry5.runtime.Component) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)16 Field (org.apache.tapestry5.Field)7 ValidationException (org.apache.tapestry5.ValidationException)5 Validate (org.apache.tapestry5.beaneditor.Validate)5 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)5 UploadedFile (org.apache.tapestry5.upload.services.UploadedFile)5 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)4 Html5Support (org.apache.tapestry5.services.Html5Support)4 ValidationConstraintGenerator (org.apache.tapestry5.services.ValidationConstraintGenerator)4 Messages (org.apache.tapestry5.commons.Messages)3 MultipartDecoder (org.apache.tapestry5.upload.services.MultipartDecoder)3 FieldValidator (org.apache.tapestry5.FieldValidator)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 BeanValidationContextImpl (org.apache.tapestry5.internal.BeanValidationContextImpl)2 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)2 Heartbeat (org.apache.tapestry5.services.Heartbeat)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1