Search in sources :

Example 21 with Validator

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

the class FieldValidatorImplTest method null_value_skipped.

@SuppressWarnings("unchecked")
@Test
public void null_value_skipped() throws Exception {
    Field field = mockField();
    MessageFormatter formatter = mockMessageFormatter();
    Validator validator = mockValidator();
    train_isRequired(validator, false);
    replay();
    FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator, null);
    fv.validate(null);
    verify();
}
Also used : Field(org.apache.tapestry5.Field) FieldValidator(org.apache.tapestry5.FieldValidator) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) FieldValidator(org.apache.tapestry5.FieldValidator) Validator(org.apache.tapestry5.Validator) Test(org.testng.annotations.Test)

Example 22 with Validator

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

the class FieldValidatorImplTest method nonmatching_value_type_skipped.

@SuppressWarnings("unchecked")
@Test
public void nonmatching_value_type_skipped() throws Exception {
    Field field = mockField();
    MessageFormatter formatter = mockMessageFormatter();
    Validator validator = mockValidator();
    Integer value = 15;
    train_isRequired(validator, true);
    train_getValueType(validator, String.class);
    replay();
    FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator, null);
    fv.validate(value);
    verify();
}
Also used : Field(org.apache.tapestry5.Field) FieldValidator(org.apache.tapestry5.FieldValidator) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) FieldValidator(org.apache.tapestry5.FieldValidator) Validator(org.apache.tapestry5.Validator) Test(org.testng.annotations.Test)

Example 23 with Validator

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

the class FieldValidatorSourceImplTest method single_validator_via_specification.

@SuppressWarnings("unchecked")
@Test
public void single_validator_via_specification() throws Exception {
    Validator validator = mockValidator();
    TypeCoercer coercer = mockTypeCoercer();
    FieldComponent field = newFieldComponent();
    Messages messages = mockMessages();
    MessageFormatter formatter = mockMessageFormatter();
    Object inputValue = new Object();
    ComponentResources resources = mockComponentResources();
    Messages containerMessages = mockMessages();
    FormSupport fs = mockFormSupport();
    Messages globalMessages = mockMessages();
    Map<String, Validator> map = singletonMap("required", validator);
    train_getFormValidationId(fs, "myform");
    train_getConstraintType(validator, null);
    train_getComponentResources(field, resources);
    train_getId(resources, "fred");
    train_getContainerMessages(resources, containerMessages);
    train_contains(containerMessages, "myform-fred-required-message", false);
    train_contains(containerMessages, "fred-required-message", false);
    train_getMessageKey(validator, "key");
    train_getMessageFormatter(globalMessages, "key", formatter);
    train_isRequired(validator, false);
    train_getValueType(validator, Object.class);
    validator.validate(field, null, formatter, inputValue);
    ValidatorMacro macro = mockValidatorMacro();
    train_alwaysNull(macro);
    replay();
    FieldValidatorSource source = new FieldValidatorSourceImpl(globalMessages, coercer, fs, map, macro);
    FieldValidator fieldValidator = source.createValidators(field, "required");
    fieldValidator.validate(inputValue);
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) FieldValidator(org.apache.tapestry5.FieldValidator) ValidatorMacro(org.apache.tapestry5.validator.ValidatorMacro) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) FormSupport(org.apache.tapestry5.services.FormSupport) ComponentResources(org.apache.tapestry5.ComponentResources) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) FieldValidator(org.apache.tapestry5.FieldValidator) Validator(org.apache.tapestry5.Validator) Test(org.testng.annotations.Test)

Example 24 with Validator

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

the class FieldValidatorSourceImplTest method constraint_value_from_message_catalog_per.

@SuppressWarnings("unchecked")
@Test
public void constraint_value_from_message_catalog_per() throws Exception {
    Validator validator = mockValidator();
    TypeCoercer coercer = mockTypeCoercer();
    FieldComponent field = newFieldComponent();
    MessageFormatter formatter = mockMessageFormatter();
    Object inputValue = new Object();
    ComponentResources resources = mockComponentResources();
    Messages containerMessages = mockMessages();
    Messages globalMessages = mockMessages();
    FormSupport fs = mockFormSupport();
    Map<String, Validator> map = singletonMap("minlength", validator);
    train_getConstraintType(validator, Integer.class);
    train_getFormValidationId(fs, "myform");
    train_getComponentResources(field, resources);
    train_getId(resources, "fred");
    train_contains(containerMessages, "myform-fred-minlength", false);
    train_contains(containerMessages, "fred-minlength", true);
    train_get(containerMessages, "fred-minlength", "5");
    train_coerce(coercer, "5", Integer.class, 5);
    train_getContainerMessages(resources, containerMessages);
    train_contains(containerMessages, "myform-fred-minlength-message", false);
    train_contains(containerMessages, "fred-minlength-message", false);
    train_getMessageKey(validator, "key");
    train_getMessageFormatter(globalMessages, "key", formatter);
    train_isRequired(validator, false);
    train_getValueType(validator, Object.class);
    validator.validate(field, 5, formatter, inputValue);
    ValidatorMacro macro = mockValidatorMacro();
    train_alwaysNull(macro);
    replay();
    FieldValidatorSource source = new FieldValidatorSourceImpl(globalMessages, coercer, fs, map, macro);
    FieldValidator fieldValidator = source.createValidators(field, "minlength");
    fieldValidator.validate(inputValue);
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) FieldValidator(org.apache.tapestry5.FieldValidator) ValidatorMacro(org.apache.tapestry5.validator.ValidatorMacro) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) FormSupport(org.apache.tapestry5.services.FormSupport) ComponentResources(org.apache.tapestry5.ComponentResources) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) FieldValidator(org.apache.tapestry5.FieldValidator) Validator(org.apache.tapestry5.Validator) Test(org.testng.annotations.Test)

Example 25 with Validator

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

the class FieldValidatorSourceImplTest method constraint_value_from_message_catalog_per_form.

@SuppressWarnings("unchecked")
@Test
public void constraint_value_from_message_catalog_per_form() throws Exception {
    Validator validator = mockValidator();
    TypeCoercer coercer = mockTypeCoercer();
    FieldComponent field = newFieldComponent();
    Messages globalMessages = mockMessages();
    MessageFormatter formatter = mockMessageFormatter();
    Object inputValue = new Object();
    ComponentResources resources = mockComponentResources();
    Messages containerMessages = mockMessages();
    FormSupport fs = mockFormSupport();
    Map<String, Validator> map = singletonMap("minlength", validator);
    train_getConstraintType(validator, Integer.class);
    train_getFormValidationId(fs, "myform");
    train_getComponentResources(field, resources);
    train_getId(resources, "fred");
    train_contains(containerMessages, "myform-fred-minlength", true);
    train_get(containerMessages, "myform-fred-minlength", "5");
    train_coerce(coercer, "5", Integer.class, 5);
    train_getContainerMessages(resources, containerMessages);
    train_contains(containerMessages, "myform-fred-minlength-message", false);
    train_contains(containerMessages, "fred-minlength-message", false);
    train_getMessageKey(validator, "key");
    train_getMessageFormatter(globalMessages, "key", formatter);
    train_isRequired(validator, false);
    train_getValueType(validator, Object.class);
    validator.validate(field, 5, formatter, inputValue);
    ValidatorMacro macro = mockValidatorMacro();
    train_alwaysNull(macro);
    replay();
    FieldValidatorSource source = new FieldValidatorSourceImpl(globalMessages, coercer, fs, map, macro);
    FieldValidator fieldValidator = source.createValidators(field, "minlength");
    fieldValidator.validate(inputValue);
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) FieldValidator(org.apache.tapestry5.FieldValidator) ValidatorMacro(org.apache.tapestry5.validator.ValidatorMacro) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) FormSupport(org.apache.tapestry5.services.FormSupport) ComponentResources(org.apache.tapestry5.ComponentResources) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) FieldValidator(org.apache.tapestry5.FieldValidator) Validator(org.apache.tapestry5.Validator) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)32 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)26 FieldValidator (org.apache.tapestry5.FieldValidator)21 Field (org.apache.tapestry5.Field)16 Validator (org.apache.tapestry5.Validator)16 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)13 ComponentResources (org.apache.tapestry5.ComponentResources)12 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)12 FormSupport (org.apache.tapestry5.services.FormSupport)12 Messages (org.apache.tapestry5.commons.Messages)11 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)11 ValidationException (org.apache.tapestry5.ValidationException)7 Pattern (java.util.regex.Pattern)2 Validator (javax.validation.Validator)2 PropertyDescriptor (javax.validation.metadata.PropertyDescriptor)2 Request (org.apache.tapestry5.http.services.Request)2 BeanValidationContext (org.apache.tapestry5.internal.BeanValidationContext)2 Html5Support (org.apache.tapestry5.services.Html5Support)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1