Package org.springframework.validation

Examples of org.springframework.validation.BindException


    public void testValidate_Valid() throws Exception {
        Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>();
        preferenceMap.put(TITLE_SUFFIX, new PortalPreferenceImpl(TITLE_SUFFIX, "- Rave unit test"));
        preferenceMap.put(PAGE_SIZE, new PortalPreferenceImpl(PAGE_SIZE, "10"));
        PortalPreferenceForm form = new PortalPreferenceForm(preferenceMap);
        Errors errors = new BindException(form, "form");
        validator.validate(form, errors);

        assertFalse(errors.hasErrors());
    }
View Full Code Here


    @Test
    public void testValidate_missingRequiredFields() throws Exception {
        Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>();
        PortalPreferenceForm form = new PortalPreferenceForm(preferenceMap);
        form.getPageSize().setValue(null);
        Errors errors = new BindException(form, "form");
        validator.validate(form, errors);

        assertEquals(2, errors.getErrorCount());
        assertNotNull(errors.getFieldError("pageSize.value"));
    }
View Full Code Here

    @Test
    public void testValidate_InvalidPageSize() throws Exception {
        Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>();
        preferenceMap.put(PAGE_SIZE, new PortalPreferenceImpl(PAGE_SIZE, "10.5"));
        PortalPreferenceForm form = new PortalPreferenceForm(preferenceMap);
        Errors errors = new BindException(form, "form");
        validator.validate(form, errors);

        assertEquals(1, errors.getErrorCount());
        assertNotNull(errors.getFieldError("pageSize.value"));
    }
View Full Code Here

    @Override
    protected boolean onUnmarshalRequest(MessageContext messageContext, Object requestObject) throws Exception {
        Validator[] validators = getValidators();
        if (validators != null) {
            Errors errors = new BindException(requestObject, getRequestName());
            for (Validator validator : validators) {
                ValidationUtils.invokeValidator(validator, requestObject, errors);
            }
            if (errors.hasErrors()) {
                return onValidationErrors(messageContext, requestObject, errors);
            }
        }
        return true;
    }
View Full Code Here

        BeanValidator validator = new BeanValidator();
        validator.setErrorCodeConverter(new DefaultErrorCodeConverter());
        validator.setConfigurationLoader(loader);

        Person person = new Person("Uri");
        BindException errors = new BindException(person, "person");

        validator.validate(person, errors);

        assertTrue(errors.hasFieldErrors("name"));
        assertTrue(errors.hasGlobalErrors());
        assertEquals(1, errors.getFieldErrorCount("name"));
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals("Person[minLength]", errors.getGlobalError().getCode());
        assertEquals("Person.name[minLength]", errors.getFieldError("name").getCode());

    }
View Full Code Here

        validator.setErrorCodeConverter(new DefaultErrorCodeConverter());
        validator.setConfigurationLoader(loader);

        Person person = new Person("Uri");
        BindException errors = new BindException(person, "person");

        validator.validate(person, errors);

        assertTrue(errors.hasGlobalErrors());
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals("Person[bad]", errors.getGlobalError().getCode());
    }
View Full Code Here

        validator.setErrorCodeConverter(new DefaultErrorCodeConverter());

        Person person = new Person("Uri");
        person.setHomeless(false);
        person.setAddress(new Address(null, "Amsterdam"));
        BindException errors = new BindException(person, "person");

        validator.validate(person, errors);

        assertTrue(errors.hasGlobalErrors());
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals(1, errors.getFieldErrorCount());
        assertEquals("Person[bad]", errors.getGlobalError().getCode());
        assertEquals("Address.street[not.null]", errors.getFieldError("address.street").getCode());
    }
View Full Code Here

    public void testBeanValidator_WithApplicationContext() throws Exception {
        ClassPathXmlApplicationContext context =
            new ClassPathXmlApplicationContext("org/springmodules/validation/bean/beanValidator-tests.xml");

        Person person = new Person("Uri");
        BindException errors = new BindException(person, "person");

        Validator validator = (Validator)context.getBean("validator");
        validator.validate(person, errors);

        assertTrue(errors.hasGlobalErrors());
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals("Person[bad]", errors.getGlobalError().getCode());

    }
View Full Code Here

        ClassPathXmlApplicationContext context =
            new ClassPathXmlApplicationContext("org/springmodules/validation/bean/beanValidator-tests.xml");

        Person person = new Person("Uri");
        person.setPhone("1234"); // should be validation error - length < 7
        BindException errors = new BindException(person, "person");

        Validator validator = (Validator)context.getBean("validator");
        validator.validate(person, errors);

        assertTrue(errors.hasFieldErrors("phone"));
        assertEquals(1, errors.getFieldErrorCount("phone"));
        assertEquals("Person.phone[min.length]", errors.getFieldError("phone").getCode());
    }
View Full Code Here

        person.setAge(-1);
        person.setEmail("uri@b");
        person.setPassword("pa");
        person.setConfirmPassword("pa1");

        BindException errors = new BindException(person, "person");
        BeanValidator validator = new BeanValidator(loader);
        validator.validate(person, errors);

        assertEquals(1, errors.getGlobalErrorCount());

    }
View Full Code Here

TOP

Related Classes of org.springframework.validation.BindException

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.