List of usage examples for org.springframework.validation BeanPropertyBindingResult BeanPropertyBindingResult
public BeanPropertyBindingResult(@Nullable Object target, String objectName)
From source file:com.github.javarch.persistence.orm.hibernate.BeanValidator.java
/** * Realiza a validao de um objeto atravs da JSR 303. * /*from w ww . j a v a 2 s. com*/ * @param objeto Entidade que contm anotaes da JSR 303 * * @return BindingResult Objeto que encapsula as mensagens de erros encontradas * nas validaes do objeto atravs das anotaes da JSR 303 */ public static <T> BindingResult validate(T objeto) { Assert.notNull(objeto, "No possivel aplicar regras de validao JSR-303 em um objeto nulo."); BindingResult bindingResult = new BeanPropertyBindingResult(objeto, objeto.getClass().getSimpleName()); javax.validation.Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set<ConstraintViolation<T>> constraintViolations = validator.validate(objeto); for (ConstraintViolation<T> constraint : constraintViolations) { bindingResult.rejectValue(constraint.getPropertyPath().toString(), "", constraint.getMessage()); } return bindingResult; }
From source file:org.haftrust.verifier.validator.BankValidatorTestBase.java
@Before public void setup() { bean = RegisterVerifierBeanBuilder.getValidBean(); errors = new BeanPropertyBindingResult(bean, "registerVerifierBean"); validator = new BankValidator(); }
From source file:org.openmrs.module.kenyaemr.validator.TelephoneNumberValidatorTest.java
/** * Validates the input string// w w w .j ava2 s . c o m * @param input the input * @return whether input is valid */ private static boolean invokeValidator(String input) { Validator validator = new TelephoneNumberValidator(); Errors errors = new BeanPropertyBindingResult("test", "test"); validator.validate(input, errors); return !errors.hasErrors(); }
From source file:org.openmrs.module.kenyaemr.validator.EmailAddressValidatorTest.java
/** * Validates the input string/*from ww w.ja v a 2 s .co m*/ * @param input the input * @return whether input is valid */ private static boolean invokeValidator(String input) { Validator validator = new EmailAddressValidator(); Errors errors = new BeanPropertyBindingResult("test", "test"); validator.validate(input, errors); return !errors.hasErrors(); }
From source file:com.healthcit.cacure.web.controller.UserCredentialsValidatorTest.java
@Test public void testSuccessValidation() { UserCredentials userCredentials = new UserCredentials(); userCredentials.setUserName("Testing"); userCredentials.setPassword("TestPassword"); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(userCredentialsValidator, "userCredentials"); userCredentialsValidator.validate(userCredentials, errors); Assert.assertEquals(0, errors.getErrorCount()); }
From source file:gabriel.domain.BirthdateValidatorTest.java
@Before public void setUp() { this.validator = new BirthdateValidator(); this.registration = new Registration(); this.registration.setFirstName("John"); this.registration.setLastName("Doe"); this.registration.setGender(Gender.MALE); this.registration.setRequest("request"); this.errors = new BeanPropertyBindingResult(registration, "registration"); }
From source file:es.unileon.ulebank.service.SearchClientControllerTest.java
/** * Test of onSubmit method, of class SearchClientController. *///w w w. java 2s. c om @Test public void testOnSubmit() { System.out.println("onSubmit"); DniClient dniCorrect = new DniClient(); DniClient dniIncorrect = new DniClient(); dniIncorrect.setDni("incorrect"); dniCorrect.setDni("96443956B"); BindingResult bindingResult = new BeanPropertyBindingResult(dniCorrect, "dniCorrect"); System.out.println(bindingResult.getErrorCount()); //problems with bindingResult, can not make working this test //tried to move source code to SearchManager without sucess-> at least, I can test //that piece of source code in another test file // ModelAndView result = instance.onSubmit(dniCorrect, bindingResult); // assertEquals("showClient", result.getViewName()); // result = instance.onSubmit(dniIncorrect, bindingResult); // assertEquals("searchClient", result.getViewName()); }
From source file:edu.wisc.my.stats.web.command.validation.QueryCommandValidatorTest.java
@Override protected void setUp() throws Exception { this.queryCommand = new QueryCommand(); this.queryParametersValidator = new QueryCommandValidator(); this.errors = new BeanPropertyBindingResult(this.queryCommand, "queryParameters"); }
From source file:org.sloth.validation.LoginValidatorTest.java
@Test public void testEmptyMailLogin() { LoginValidator lv = new LoginValidator(); Login l = new Login(); l.setMail(""); Errors errors = new BeanPropertyBindingResult(l, "login"); lv.validate(l, errors);// w w w . j av a 2s. c o m assertTrue(errors.hasErrors()); assertEquals(LOGIN.EMPTY_MAIL, errors.getFieldError("mail").getCode()); }
From source file:org.parancoe.basicWebApp.ValidationTest.java
public void testPersonValidation() { Person person = new Person("Lucio", "Benfante", new Date()); BindingResult result = new BeanPropertyBindingResult(person, "person"); validator.validate(person, result);/* w w w . j ava2s.c o m*/ assertFalse(result.hasErrors()); }