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