// Path: core/src/main/java/com/premiumminds/webapp/wicket/validators/HibernateValidatorProperty.java
// public class HibernateValidatorProperty implements IValidator<Object> {
// 	private static final long serialVersionUID = -4761422631335653016L;
// 
// 	private IModel<?> beanModel;
// 	private String propertyName;
// 
// 	public static final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
// 	
// 	public HibernateValidatorProperty(IModel<?> beanModel, String propertyName){
// 		this.beanModel = beanModel;
// 		this.propertyName = propertyName;
// 	}
// 	
// 	public void validate(IValidatable<Object> validatable) {
// 		Validator validator = HibernateValidatorProperty.validatorFactory.getValidator();
// 		
// 		@SuppressWarnings("unchecked")
// 		Set<ConstraintViolation<Object>> violations = validator.validateValue((Class<Object>)beanModel.getObject().getClass(), propertyName, validatable.getValue());
// 		
// 		if(!violations.isEmpty()){
// 			for(ConstraintViolation<?> violation : violations){
// 				ValidationError error = new ValidationError(violation.getMessage());
// 				
// 				String key = violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName();
// 				if(getValidatorPrefix()!=null) key = getValidatorPrefix()+"."+key;
// 				
// 				error.addKey(key);
// 				error.setVariables(new HashMap<String, Object>(violation.getConstraintDescriptor().getAttributes()));
// 				
// 				//remove garbage from the attributes
// 				error.getVariables().remove("payload");
// 				error.getVariables().remove("message");
// 				error.getVariables().remove("groups");
// 				
// 				validatable.error(error);
// 			}
// 		}
// 	}
// 	
// 	protected String getValidatorPrefix(){
// 		return null;
// 	}
// 	
// }


import com.premiumminds.webapp.wicket.validators.HibernateValidatorProperty;
import static org.junit.Assert.*;
import java.io.Serializable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.wicket.model.Model;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.Validatable;
import org.apache.wicket.validation.ValidationError;
import org.junit.Test;
	public void testSuccess(){
		IValidator<Object> validator = new HibernateValidatorProperty(new Model<TestBean>(new TestBean("aaa", "aaa")), "a");
		
		Validatable<Object> validatable = new Validatable<Object>("bb");
		validator.validate(validatable);
		
		assertEquals(0, validatable.getErrors().size());
	}
	
	@Test
	public void testMessageParameters(){
		IValidator<Object> validator = new HibernateValidatorProperty(new Model<TestBean>(new TestBean("aaa", "aaa")), "b");
		
		Validatable<Object> validatable = new Validatable<Object>("a");
		validator.validate(validatable);
		
		assertEquals(1, validatable.getErrors().size());
		assertEquals("Size", getError(validatable).getKeys().get(0));
		
		assertEquals(2, getError(validatable).getVariables().size());
		assertEquals(2, getError(validatable).getVariables().get("min"));
		assertEquals(4, getError(validatable).getVariables().get("max"));
	}
	
	private ValidationError getError(Validatable<?> validatable)
	{
		return (ValidationError)validatable.getErrors().get(0);
	}	
	
	public class TestBean implements Serializable {
// Path: core/src/main/java/com/premiumminds/webapp/wicket/validators/HibernateValidatorProperty.java
// public class HibernateValidatorProperty implements IValidator<Object> {
// 	private static final long serialVersionUID = -4761422631335653016L;
// 
// 	private IModel<?> beanModel;
// 	private String propertyName;
// 
// 	public static final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
// 	
// 	public HibernateValidatorProperty(IModel<?> beanModel, String propertyName){
// 		this.beanModel = beanModel;
// 		this.propertyName = propertyName;
// 	}
// 	
// 	public void validate(IValidatable<Object> validatable) {
// 		Validator validator = HibernateValidatorProperty.validatorFactory.getValidator();
// 		
// 		@SuppressWarnings("unchecked")
// 		Set<ConstraintViolation<Object>> violations = validator.validateValue((Class<Object>)beanModel.getObject().getClass(), propertyName, validatable.getValue());
// 		
// 		if(!violations.isEmpty()){
// 			for(ConstraintViolation<?> violation : violations){
// 				ValidationError error = new ValidationError(violation.getMessage());
// 				
// 				String key = violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName();
// 				if(getValidatorPrefix()!=null) key = getValidatorPrefix()+"."+key;
// 				
// 				error.addKey(key);
// 				error.setVariables(new HashMap<String, Object>(violation.getConstraintDescriptor().getAttributes()));
// 				
// 				//remove garbage from the attributes
// 				error.getVariables().remove("payload");
// 				error.getVariables().remove("message");
// 				error.getVariables().remove("groups");
// 				
// 				validatable.error(error);
// 			}
// 		}
// 	}
// 	
// 	protected String getValidatorPrefix(){
// 		return null;
// 	}
// 	
// }


// Path: core/src/test/java/com/premiumminds/webapp/wicket/validators/HibernateValidatorPropertyTest.java
import com.premiumminds.webapp.wicket.validators.HibernateValidatorProperty;
import static org.junit.Assert.*;
import java.io.Serializable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.wicket.model.Model;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.Validatable;
import org.apache.wicket.validation.ValidationError;
import org.junit.Test;

	public void testSuccess(){
		IValidator<Object> validator = new HibernateValidatorProperty(new Model<TestBean>(new TestBean("aaa", "aaa")), "a");
		
		Validatable<Object> validatable = new Validatable<Object>("bb");
		validator.validate(validatable);
		
		assertEquals(0, validatable.getErrors().size());
	}
	
	@Test
	public void testMessageParameters(){
		IValidator<Object> validator = new HibernateValidatorProperty(new Model<TestBean>(new TestBean("aaa", "aaa")), "b");
		
		Validatable<Object> validatable = new Validatable<Object>("a");
		validator.validate(validatable);
		
		assertEquals(1, validatable.getErrors().size());
		assertEquals("Size", getError(validatable).getKeys().get(0));
		
		assertEquals(2, getError(validatable).getVariables().size());
		assertEquals(2, getError(validatable).getVariables().get("min"));
		assertEquals(4, getError(validatable).getVariables().get("max"));
	}
	
	private ValidationError getError(Validatable<?> validatable)
	{
		return (ValidationError)validatable.getErrors().get(0);
	}	
	
	public class TestBean implements Serializable {
		private static final long serialVersionUID = -6112030970184764376L;