Search in sources :

Example 6 with MessageFormatter

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

the class MinTest method large_enough.

@Test
public void large_enough() throws Exception {
    Field field = mockField();
    MessageFormatter formatter = mockMessageFormatter();
    Long constraint = 50L;
    Min validator = new Min(null, mockHtml5Support());
    replay();
    for (int value = 50; value < 52; value++) validator.validate(field, constraint, formatter, value);
    verify();
}
Also used : Field(org.apache.tapestry5.Field) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) Test(org.testng.annotations.Test)

Example 7 with MessageFormatter

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

the class MinTest method value_too_small.

@Test
public void value_too_small() throws Exception {
    String label = "My Field";
    Field field = mockFieldWithLabel(label);
    MessageFormatter formatter = mockMessageFormatter();
    String message = "{message}";
    Long constraint = 100l;
    Number value = 99;
    train_format(formatter, message, constraint, label);
    Min validator = new Min(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 8 with MessageFormatter

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

the class RegexpTest method matching_pattern.

@Test
public void matching_pattern() throws Exception {
    Field field = mockField();
    MessageFormatter formatter = mockMessageFormatter();
    Pattern constraint = Pattern.compile("\\d{4}");
    replay();
    Regexp validator = new Regexp(null);
    validator.validate(field, constraint, formatter, "1234");
    verify();
}
Also used : Field(org.apache.tapestry5.Field) Pattern(java.util.regex.Pattern) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) Test(org.testng.annotations.Test)

Example 9 with MessageFormatter

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

the class RequiredTest method blank_value.

@Test
public void blank_value() {
    MessageFormatter formatter = mockMessageFormatter();
    Field field = mockFieldWithLabel("My Field");
    train_format(formatter, "{message}", "My Field");
    Html5Support html5Support = mockHtml5Support();
    replay();
    try {
        new Required(null, html5Support).validate(field, null, formatter, "");
        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 10 with MessageFormatter

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

the class RequiredTest method empty_collection_value.

@Test
public void empty_collection_value() {
    MessageFormatter formatter = mockMessageFormatter();
    Field field = mockFieldWithLabel("My Field");
    train_format(formatter, "{message}", "My Field");
    Html5Support html5Support = mockHtml5Support();
    replay();
    try {
        new Required(null, html5Support).validate(field, null, formatter, Arrays.asList());
        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)

Aggregations

MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)37 Test (org.testng.annotations.Test)35 Field (org.apache.tapestry5.Field)25 FieldValidator (org.apache.tapestry5.FieldValidator)14 Validator (org.apache.tapestry5.Validator)14 Messages (org.apache.tapestry5.commons.Messages)14 FormSupport (org.apache.tapestry5.services.FormSupport)14 ComponentResources (org.apache.tapestry5.ComponentResources)10 ValidationException (org.apache.tapestry5.ValidationException)9 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)9 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)9 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)9 Html5Support (org.apache.tapestry5.services.Html5Support)7 FieldTranslator (org.apache.tapestry5.FieldTranslator)5 MarkupWriter (org.apache.tapestry5.MarkupWriter)5 Translator (org.apache.tapestry5.Translator)5 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)5 TranslatorSource (org.apache.tapestry5.services.TranslatorSource)5 Locale (java.util.Locale)4 Map (java.util.Map)4