Search in sources :

Example 1 with Validate

use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.

the class MessagesAnnotationConstraintGeneratorTest method pushAndTrainEnvironmentalObjects.

private void pushAndTrainEnvironmentalObjects(Environment e, boolean hasProperty, String propertyValue) {
    Messages messages = mockMessages();
    train_contains(messages, "testProperty-validate", hasProperty);
    if (hasProperty) {
        train_get(messages, "testProperty-validate", propertyValue);
    }
    EnvironmentMessages em = new EnvironmentMessages(messages, "testProperty");
    e.push(EnvironmentMessages.class, em);
    replay();
}
Also used : Messages(org.apache.tapestry5.commons.Messages)

Example 2 with Validate

use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.

the class UploadTest method process_submission_extracts_value_from_decoder.

@SuppressWarnings({ "unchecked" })
@Test
public void process_submission_extracts_value_from_decoder() throws Exception {
    MultipartDecoder decoder = mockMultipartDecoder();
    UploadedFile uploadedFile = mockUploadedFile();
    ComponentResources resources = mockComponentResources();
    FieldValidationSupport support = mockFieldValidationSupport();
    FieldValidator validate = mockFieldValidator();
    Upload component = new Upload(null, validate, decoder, null, resources, support);
    expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
    expect(uploadedFile.getFileName()).andReturn("foo").anyTimes();
    support.validate(uploadedFile, resources, validate);
    replay();
    component.processSubmission("test");
    verify();
    assertSame(component.getValue(), uploadedFile);
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 3 with Validate

use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.

the class UploadTest method process_submission_ignores_null_value.

@SuppressWarnings({ "unchecked" })
@Test
public void process_submission_ignores_null_value() throws Exception {
    MultipartDecoder decoder = mockMultipartDecoder();
    UploadedFile uploadedFile = mockUploadedFile();
    ComponentResources resources = mockComponentResources();
    FieldValidationSupport support = mockFieldValidationSupport();
    FieldValidator validate = mockFieldValidator();
    Upload component = new Upload(null, validate, decoder, null, resources, support);
    expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
    expect(uploadedFile.getFileName()).andReturn("").atLeastOnce();
    support.validate(null, resources, validate);
    replay();
    component.processSubmission("test");
    verify();
    assertNull(component.getValue());
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 4 with Validate

use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.

the class UploadTest method process_submission_tracks_validator_errors.

@SuppressWarnings({ "unchecked", "ThrowableInstanceNeverThrown" })
@Test
public void process_submission_tracks_validator_errors() throws Exception {
    MultipartDecoder decoder = mockMultipartDecoder();
    UploadedFile uploadedFile = mockUploadedFile();
    FieldValidator<Object> validate = mockFieldValidator();
    ValidationTracker tracker = mockValidationTracker();
    ComponentResources resources = mockComponentResources();
    FieldValidationSupport support = mockFieldValidationSupport();
    Upload component = new Upload(null, validate, decoder, tracker, resources, support);
    expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
    expect(uploadedFile.getFileName()).andReturn("test").atLeastOnce();
    support.validate(uploadedFile, resources, validate);
    expectLastCall().andThrow(new ValidationException("an error"));
    tracker.recordError(component, "an error");
    replay();
    component.processSubmission("test");
    verify();
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 5 with Validate

use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.

the class PropertyConduitSourceImplTest method field_annotations_are_visible.

@Test
public void field_annotations_are_visible() {
    PropertyConduit conduit = source.create(CompositeBean.class, "simple.firstName");
    Validate annotation = conduit.getAnnotation(Validate.class);
    assertNotNull(annotation);
    assertEquals(annotation.value(), "required");
}
Also used : Validate(org.apache.tapestry5.beaneditor.Validate) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) InternalPropertyConduit(org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit) PropBindingFactoryTest(org.apache.tapestry5.internal.bindings.PropBindingFactoryTest) 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