Search in sources :

Example 16 with ValidationException

use of org.apache.tapestry5.ValidationException 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)

Example 17 with ValidationException

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

the class RequiredTest method null_value.

@Test
public void null_value() {
    Field field = mockFieldWithLabel("My Field");
    MessageFormatter formatter = mockMessageFormatter();
    train_format(formatter, "{message}", "My Field");
    Html5Support html5Support = mockHtml5Support();
    replay();
    try {
        new Required(null, html5Support).validate(field, null, formatter, null);
        unreachable();
    } catch (ValidationException ex) {
        assertEquals(ex.getMessage(), "{message}");
    }
    verify();
}
Also used : Field(org.apache.tapestry5.Field) Html5Support(org.apache.tapestry5.services.Html5Support) ValidationException(org.apache.tapestry5.ValidationException) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) Test(org.testng.annotations.Test)

Example 18 with ValidationException

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

the class TranslatorSourceImplTest method parse_client_failure.

@Test(dataProvider = "parse_client_failure_data")
public void parse_client_failure(Class type, String input, String expectedMessage) {
    Translator t = source.getByType(type);
    Field field = mockField();
    replay();
    try {
        t.parseClient(field, input, expectedMessage);
        unreachable();
    } catch (ValidationException ex) {
        assertEquals(ex.getMessage(), expectedMessage);
    }
    verify();
}
Also used : Field(org.apache.tapestry5.Field) ValidationException(org.apache.tapestry5.ValidationException) Translator(org.apache.tapestry5.Translator) Test(org.testng.annotations.Test)

Aggregations

ValidationException (org.apache.tapestry5.ValidationException)12 Test (org.testng.annotations.Test)12 Field (org.apache.tapestry5.Field)10 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)9 Html5Support (org.apache.tapestry5.services.Html5Support)4 Messages (org.apache.tapestry5.commons.Messages)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 Request (org.apache.tapestry5.http.services.Request)2 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)2 ValueEncoderSource (org.apache.tapestry5.services.ValueEncoderSource)2 UploadedFile (org.apache.tapestry5.upload.services.UploadedFile)2 EnumSelectModel (org.apache.tapestry5.util.EnumSelectModel)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Pattern (java.util.regex.Pattern)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Validator (javax.validation.Validator)1 PropertyDescriptor (javax.validation.metadata.PropertyDescriptor)1 FieldValidator (org.apache.tapestry5.FieldValidator)1 Translator (org.apache.tapestry5.Translator)1