Package org.springframework.validation

Examples of org.springframework.validation.Validator.validate()


    public void testApplyCustomValidator() throws Exception {
        Object object = new Object();

        MockControl customValidatorControl = MockControl.createControl(Validator.class);
        Validator customValidator = (Validator)customValidatorControl.getMock();
        customValidator.validate(object, errors);
        configurationControl.expectAndReturn(configuration.getCustomValidator(), customValidator);

        replay();
        validator.applyCustomValidator(configuration, object, errors);
        verify();
View Full Code Here


     */
    protected void applyCustomValidator(BeanValidationConfiguration configuration, Object obj, Errors errors) {
        Validator validator = configuration.getCustomValidator();
        if (validator != null) {
            if (validator.supports(obj.getClass())) {
                validator.validate(obj, errors);
            } else {
                if (logger.isWarnEnabled()) {
                    logger.warn("Validator: " + validator + " was extracted from the configuration of object: " +
                        obj + " but it is not applied for it does not support this object type: " +
                        obj.getClass().getName());
View Full Code Here

        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

        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

        Validator[] validators = getValidators();
        for (int i=0; i<validators.length; i++) {
            Validator validator = validators[i];
            if (validator instanceof PageAware) {
                if (((PageAware)validator).getPage() == page) {
                    validator.validate(command, errors);
                }
            }
        }
    }
}
View Full Code Here

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("appCtxt.xml", getClass());
        Validator validator = (Validator)context.getBean("validator");

        TeztBean2 bean = new TeztBean2();
        BindException errors = new BindException(bean, "bean");
        validator.validate(bean, errors);
        assertTrue(errors.hasErrors());
        assertTrue(errors.hasFieldErrors("name"));

        bean = new TeztBean2("test");
        errors = new BindException(bean, "bean");
View Full Code Here

        assertTrue(errors.hasErrors());
        assertTrue(errors.hasFieldErrors("name"));

        bean = new TeztBean2("test");
        errors = new BindException(bean, "bean");
        validator.validate(bean, errors);
        assertFalse(errors.hasErrors());

    }

    public void testConditionRef_WhenNotDeployedInApplicationContext() throws Exception {
View Full Code Here

    public void testApplyCustomValidator() throws Exception {
        Object object = new Object();

        MockControl customValidatorControl = MockControl.createControl(Validator.class);
        Validator customValidator = (Validator) customValidatorControl.getMock();
        customValidator.validate(object, errors);
        configurationControl.expectAndReturn(configuration.getCustomValidator(), customValidator);

        replay();
        validator.applyCustomValidator(configuration, object, errors);
        verify();
View Full Code Here

        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

        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

TOP
Copyright © 2018 www.massapi.com. 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.