package org.richfaces.validator;

import java.util.Locale;
import java.util.ResourceBundle;

import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;

public class BeanValidatorTest extends AbstractAjax4JsfTestCase {

	public BeanValidatorTest(String name) {
		super(name);
	}

	public void testValidate() {
		
	}
	
	public void setUp() throws Exception {
    	super.setUp();
    }

    public void tearDown() throws Exception {
    	super.tearDown();
    }
	
	public void testGetValidator() throws Exception {
		BeanValidator beanValidator = BeanValidator.createInstance();
		ClassValidator<? extends Object> validator = beanValidator.getValidator(ValidableBean.class,Locale.ENGLISH);
		assertNotNull(validator);
		assertTrue(validator.hasValidationRules());
		validator = beanValidator.getValidator(String.class,Locale.getDefault());
		assertNotNull(validator);
		assertFalse(validator.hasValidationRules());
	}

	public void testValidateClass() throws Exception {
		BeanValidator beanValidator = BeanValidator.createInstance();
		InvalidValue[] invalidValues = beanValidator.validateClass(ValidableBean.class, "integerProperty", new Integer(3),Locale.getDefault());
		assertNotNull(invalidValues);
		assertEquals(0, invalidValues.length);
		invalidValues = beanValidator.validateClass(ValidableBean.class, "integerProperty", new Integer(-1),Locale.getDefault());
		assertNotNull(invalidValues);
		assertEquals(1, invalidValues.length);
		invalidValues = beanValidator.validateClass(UnValidableBean.class, "integerProperty", new Integer(-1),Locale.getDefault());
		assertNotNull(invalidValues);
		assertEquals(0, invalidValues.length);
		invalidValues = beanValidator.validateClass(ValidableBean.class, "nonExistentProperty", new Integer(-1),Locale.getDefault());
		assertNotNull(invalidValues);
		assertEquals(0, invalidValues.length);

	}
	
	public void testValidateBean() throws Exception {
		BeanValidator beanValidator = BeanValidator.createInstance();
		InvalidValue[] invalidValues = beanValidator.validateBean(new ValidableBean(), "integerProperty", new Integer(-1),Locale.getDefault());
		assertNotNull(invalidValues);
		assertEquals(1, invalidValues.length);
	}
}
