Search in sources :

Example 36 with Validator

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

the class MaxLengthTest method long_value.

@Test
public void long_value() throws Exception {
    String label = "My Field";
    Field field = mockFieldWithLabel(label);
    MessageFormatter formatter = mockMessageFormatter();
    String value = "Now the student has become the master.";
    String message = "{message}";
    Integer constraint = value.length() - 1;
    train_format(formatter, message, constraint, label);
    replay();
    MaxLength validator = new MaxLength(null);
    try {
        validator.validate(field, constraint, formatter, value);
        unreachable();
    } catch (ValidationException ex) {
        assertEquals(ex.getMessage(), message);
    }
    verify();
}
Also used : Field(org.apache.tapestry5.Field) ValidationException(org.apache.tapestry5.ValidationException) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) Test(org.testng.annotations.Test)

Example 37 with Validator

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

the class MaxTest method value_too_large.

@Test
public void value_too_large() throws Exception {
    String label = "My Field";
    Field field = mockFieldWithLabel(label);
    MessageFormatter formatter = mockMessageFormatter();
    String message = "{message}";
    Long constraint = 100l;
    Number value = 101;
    train_format(formatter, message, constraint, label);
    Max validator = new Max(null, mockHtml5Support());
    replay();
    try {
        validator.validate(field, constraint, formatter, value);
        unreachable();
    } catch (ValidationException ex) {
        assertEquals(ex.getMessage(), message);
    }
    verify();
}
Also used : Field(org.apache.tapestry5.Field) ValidationException(org.apache.tapestry5.ValidationException) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) Test(org.testng.annotations.Test)

Example 38 with Validator

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

the class MinLengthTest method long_enough.

@Test
public void long_enough() throws Exception {
    Field field = mockField();
    MessageFormatter formatter = mockMessageFormatter();
    String value = "Now the student has become the master.";
    replay();
    MinLength validator = new MinLength(null);
    validator.validate(field, value.length(), formatter, value);
    verify();
}
Also used : Field(org.apache.tapestry5.Field) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) Test(org.testng.annotations.Test)

Example 39 with Validator

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

the class RegexpTest method input_mismatch.

@Test
public void input_mismatch() throws Exception {
    String label = "My Field";
    Field field = mockFieldWithLabel(label);
    MessageFormatter formatter = mockMessageFormatter();
    String message = "{message}";
    Pattern constraint = Pattern.compile("\\d{4}");
    String value = "abc";
    train_format(formatter, message, constraint.toString(), label);
    replay();
    Regexp validator = new Regexp(null);
    try {
        validator.validate(field, constraint, formatter, value);
        unreachable();
    } catch (ValidationException ex) {
        assertEquals(ex.getMessage(), message);
    }
    verify();
}
Also used : Field(org.apache.tapestry5.Field) Pattern(java.util.regex.Pattern) ValidationException(org.apache.tapestry5.ValidationException) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) 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