Package org.apache.tapestry

Examples of org.apache.tapestry.Validator


    @Test
    public void unknown_validator_type()
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        Validator validator = mockValidator();
        TypeCoercer coercer = mockTypeCoercer();
        FieldComponent field = newFieldComponent();
        ComponentResources resources = mockComponentResources();
        Messages containerMessages = mockMessages();
        Map<String, Validator> map = newMap();
View Full Code Here


    @SuppressWarnings("unchecked")
    @Test
    public void validator_with_no_constraint() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        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();

        Map<String, Validator> map = singletonMap("required", validator);

        train_getConstraintType(validator, null);

        train_getComponentResources(field, resources);

        train_getId(resources, "fred");
        train_getContainerMessages(resources, containerMessages);
        train_contains(containerMessages, "fred-required-message", false);

        train_getLocale(resources, Locale.FRENCH);

        train_getValidationMessages(messagesSource, Locale.FRENCH, messages);

        train_getMessageKey(validator, "key");
        train_getMessageFormatter(messages, "key", formatter);

        train_invokeIfBlank(validator, false);
        train_getValueType(validator, Object.class);
        validator.validate(field, null, formatter, inputValue);

        replay();

        FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null,
                map);
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void component_messages_overrides_validator_messages() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        Validator validator = mockValidator();
        TypeCoercer coercer = mockTypeCoercer();
        FieldComponent field = newFieldComponent();
        MessageFormatter formatter = mockMessageFormatter();
        Object inputValue = new Object();
        ComponentResources resources = mockComponentResources();
        Messages containerMessages = mockMessages();

        Map<String, Validator> map = singletonMap("required", validator);

        train_getConstraintType(validator, null);

        train_getComponentResources(field, resources);
        train_getId(resources, "fred");
        train_getLocale(resources, Locale.ENGLISH);
        train_getContainerMessages(resources, containerMessages);
        train_contains(containerMessages, "fred-required-message", true);

        train_getMessageFormatter(containerMessages, "fred-required-message", formatter);

        train_invokeIfBlank(validator, false);
        train_getValueType(validator, Object.class);
        validator.validate(field, null, formatter, inputValue);

        replay();

        FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null,
                map);
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void constraint_value_from_message_catalog() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        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();

        Map<String, Validator> map = singletonMap("minlength", validator);

        train_getConstraintType(validator, Integer.class);

        train_getComponentResources(field, resources);
        train_getId(resources, "fred");

        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, "fred-minlength-message", false);

        train_getLocale(resources, Locale.FRENCH);

        train_getValidationMessages(messagesSource, Locale.FRENCH, messages);

        train_getMessageKey(validator, "key");
        train_getMessageFormatter(messages, "key", formatter);

        train_invokeIfBlank(validator, false);
        train_getValueType(validator, Object.class);
        validator.validate(field, 5, formatter, inputValue);

        replay();

        FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null,
                map);
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void missing_field_validator_constraint() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        Validator validator = mockValidator();
        TypeCoercer coercer = mockTypeCoercer();
        FieldComponent field = newFieldComponent();
        ComponentResources resources = mockComponentResources();
        Messages containerMessages = mockMessages();
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void single_validator_via_specification() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        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();

        Map<String, Validator> map = singletonMap("required", validator);

        train_getConstraintType(validator, null);

        train_getComponentResources(field, resources);
        train_getId(resources, "fred");
        train_getContainerMessages(resources, containerMessages);
        train_contains(containerMessages, "fred-required-message", false);

        train_getLocale(resources, Locale.FRENCH);

        train_getValidationMessages(messagesSource, Locale.FRENCH, messages);

        train_getMessageKey(validator, "key");
        train_getMessageFormatter(messages, "key", formatter);

        train_invokeIfBlank(validator, false);
        train_getValueType(validator, Object.class);
        validator.validate(field, null, formatter, inputValue);

        replay();

        FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null,
                map);
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void multiple_validators_via_specification() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        Validator required = mockValidator();
        Validator minLength = mockValidator();
        TypeCoercer coercer = mockTypeCoercer();
        FieldComponent field = newFieldComponent();
        Messages messages = mockMessages();
        MessageFormatter requiredFormatter = mockMessageFormatter();
        MessageFormatter minLengthFormatter = mockMessageFormatter();
        Object inputValue = "input value";
        ComponentResources resources = mockComponentResources();
        Messages containerMessages = mockMessages();
        Integer fifteen = 15;

        Map<String, Validator> map = newMap();

        map.put("required", required);
        map.put("minLength", minLength);

        train_getConstraintType(required, null);
        train_getConstraintType(minLength, Integer.class);

        train_getComponentResources(field, resources);
        train_getId(resources, "fred");
        train_getContainerMessages(resources, containerMessages);
        train_contains(containerMessages, "fred-required-message", false);

        train_getLocale(resources, Locale.FRENCH);

        train_getValidationMessages(messagesSource, Locale.FRENCH, messages);

        train_getMessageKey(required, "required");
        train_getMessageFormatter(messages, "required", requiredFormatter);

        train_contains(containerMessages, "fred-minLength-message", false);

        train_getMessageKey(minLength, "min-length");
        train_getMessageFormatter(messages, "min-length", minLengthFormatter);

        train_coerce(coercer, "15", Integer.class, fifteen);

        train_invokeIfBlank(required, true);
        train_getValueType(required, Object.class);
        required.validate(field, null, requiredFormatter, inputValue);

        train_invokeIfBlank(minLength, false);
        train_getValueType(minLength, String.class);
        minLength.validate(field, fifteen, minLengthFormatter, inputValue);

        replay();

        FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null,
                map);
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void validator_with_constraint() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        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();
        Integer five = 5;

        Map<String, Validator> map = singletonMap("minLength", validator);

        train_getConstraintType(validator, Integer.class);

        train_coerce(coercer, "5", Integer.class, five);

        train_getComponentResources(field, resources);
        train_getId(resources, "fred");
        train_getContainerMessages(resources, containerMessages);
        train_contains(containerMessages, "fred-minLength-message", false);

        train_getLocale(resources, Locale.FRENCH);

        train_getValidationMessages(messagesSource, Locale.FRENCH, messages);

        train_getMessageKey(validator, "key");
        train_getMessageFormatter(messages, "key", formatter);

        train_invokeIfBlank(validator, false);
        train_getValueType(validator, Object.class);
        validator.validate(field, five, formatter, inputValue);

        replay();

        FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null,
                map);
View Full Code Here

    @Test
    public void unknown_validator_type()
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        Validator validator = mockValidator();
        TypeCoercer coercer = mockTypeCoercer();
        FieldComponent field = newFieldComponent();
        ComponentResources resources = mockComponentResources();
        Messages containerMessages = mockMessages();
        Map<String, Validator> map = newMap();
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void validator_with_no_constraint() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        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();

        Map<String, Validator> map = singletonMap("required", validator);

        train_getConstraintType(validator, null);

        train_getComponentResources(field, resources);

        train_getId(resources, "fred");
        train_getContainerMessages(resources, containerMessages);
        train_contains(containerMessages, "fred-required", false);

        train_getLocale(resources, Locale.FRENCH);

        train_getValidationMessages(messagesSource, Locale.FRENCH, messages);

        train_getMessageKey(validator, "key");
        train_getMessageFormatter(messages, "key", formatter);

        train_invokeIfBlank(validator, false);
        train_getValueType(validator, Object.class);
        validator.validate(field, null, formatter, inputValue);

        replay();

        FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null, map);
View Full Code Here

TOP

Related Classes of org.apache.tapestry.Validator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.