當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalValidatorFactoryBean.afterPropertiesSet方法代碼示例

本文整理匯總了Java中org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalValidatorFactoryBean.afterPropertiesSet方法的具體用法?Java LocalValidatorFactoryBean.afterPropertiesSet怎麽用?Java LocalValidatorFactoryBean.afterPropertiesSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.validation.beanvalidation.LocalValidatorFactoryBean的用法示例。


在下文中一共展示了LocalValidatorFactoryBean.afterPropertiesSet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSimpleValidationWithCustomProvider

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Test
public void testSimpleValidationWithCustomProvider() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setProviderClass(HibernateValidator.class);
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}
	validator.destroy();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ValidatorFactoryTests.java

示例2: testSpringValidationWithClassLevel

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Test
public void testSpringValidationWithClassLevel() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	person.setName("Juergen");
	person.getAddress().setStreet("Juergen's Street");
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(1, result.getErrorCount());
	ObjectError globalError = result.getGlobalError();
	List<String> errorCodes = Arrays.asList(globalError.getCodes());
	assertEquals(2, errorCodes.size());
	assertTrue(errorCodes.contains("NameAddressValid.person"));
	assertTrue(errorCodes.contains("NameAddressValid"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ValidatorFactoryTests.java

示例3: testSpringValidationWithErrorInListElement

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Test
public void testSpringValidationWithErrorInListElement() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	person.getAddressList().add(new ValidAddress());
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(3, result.getErrorCount());
	FieldError fieldError = result.getFieldError("name");
	assertEquals("name", fieldError.getField());
	fieldError = result.getFieldError("address.street");
	assertEquals("address.street", fieldError.getField());
	fieldError = result.getFieldError("addressList[0].street");
	assertEquals("addressList[0].street", fieldError.getField());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ValidatorFactoryTests.java

示例4: testSpringValidationWithErrorInSetElement

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Test
public void testSpringValidationWithErrorInSetElement() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	person.getAddressSet().add(new ValidAddress());
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(3, result.getErrorCount());
	FieldError fieldError = result.getFieldError("name");
	assertEquals("name", fieldError.getField());
	fieldError = result.getFieldError("address.street");
	assertEquals("address.street", fieldError.getField());
	fieldError = result.getFieldError("addressSet[].street");
	assertEquals("addressSet[].street", fieldError.getField());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ValidatorFactoryTests.java

示例5: setUp

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Before
public void setUp(){
 
 currentUser.setProxyUser("admin", "test", new String[] {"VIEW_ENTITY", "CREATE_ENTITY"});
 
 assertNotNull(headOfHouseholdService);
 
    localValidatorFactory = new LocalValidatorFactoryBean();
    localValidatorFactory.setProviderClass(HibernateValidator.class);
    localValidatorFactory.afterPropertiesSet();
    
    oldHoh = genericDao.findByProperty(Individual.class, "extId", "NBAS1I"); 
    newHoh = genericDao.findByProperty(Individual.class, "extId", "BJOH1J");
 visit = genericDao.findByProperty(Visit.class, "extId", "VLOCMBI11J");
 fieldWorker = genericDao.findByProperty(FieldWorker.class, "extId", "FWEK1D");
 socialGroup = genericDao.findByProperty(SocialGroup.class, "extId", "MBI1", false);
    
 assertNotNull(oldHoh);
 assertNotNull(newHoh);
 assertNotNull(visit);
 assertNotNull(fieldWorker);
 assertNotNull(socialGroup);
}
 
開發者ID:OpenHDS,項目名稱:openhds-server,代碼行數:24,代碼來源:HeadOfHouseholdTest.java

示例6: setup

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Before
public void setup() {
    job = new Job();
    localValidatorFactory = new LocalValidatorFactoryBean();
    localValidatorFactory.setProviderClass(HibernateValidator.class);
    localValidatorFactory.afterPropertiesSet();
}
 
開發者ID:blacklabelops,項目名稱:crow,代碼行數:8,代碼來源:ValidationTest.java

示例7: initBinder

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@SuppressWarnings("unused")
@InitBinder
private void initBinder(WebDataBinder binder) {
	binder.initBeanPropertyAccess();
	binder.setRequiredFields("sex");
	LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
	vf.afterPropertiesSet();
	binder.setValidator(vf);
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:13,代碼來源:ServletAnnotationControllerTests.java

示例8: createBinder

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Override
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();
	WebDataBinder dataBinder = new WebDataBinder(target, objectName);
	dataBinder.setValidator(validator);
	return dataBinder;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:9,代碼來源:HttpEntityMethodProcessorTests.java

示例9: createBinder

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Override
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();
	WebDataBinder dataBinder = new WebDataBinder(target, objectName);
	dataBinder.setValidator(validator);
	return dataBinder;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:9,代碼來源:RequestPartMethodArgumentResolverTests.java

示例10: getBinder

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
private RelaxedDataBinder getBinder(Object target, String namePrefix) {
	RelaxedDataBinder binder = new RelaxedDataBinder(target, namePrefix);
	binder.setIgnoreUnknownFields(false);
	LocalValidatorFactoryBean validatorFactoryBean = new LocalValidatorFactoryBean();
	validatorFactoryBean.afterPropertiesSet();
	binder.setValidator(validatorFactoryBean);
	binder.setConversionService(this.conversionService);
	return binder;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:RelaxedDataBinderTests.java

示例11: testSimpleValidationWithClassLevel

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Test
public void testSimpleValidationWithClassLevel() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();
	ValidPerson person = new ValidPerson();
	person.setName("Juergen");
	person.getAddress().setStreet("Juergen's Street");
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(1, result.size());
	Iterator<ConstraintViolation<ValidPerson>> iterator = result.iterator();
	ConstraintViolation<?> cv = iterator.next();
	assertEquals("", cv.getPropertyPath().toString());
	assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NameAddressValid);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:ValidatorFactoryTests.java

示例12: testSpringValidationFieldType

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Test
public void testSpringValidationFieldType() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	person.setName("Phil");
	person.getAddress().setStreet("Phil's Street");
	BeanPropertyBindingResult errors = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, errors);
	assertEquals(1, errors.getErrorCount());
	assertThat("Field/Value type mismatch", errors.getFieldError("address").getRejectedValue(),
			instanceOf(ValidAddress.class));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:ValidatorFactoryTests.java

示例13: createValidator

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
public static Validator createValidator() {
  LocaleContextHolder.setLocale(Locale.ENGLISH);
  ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
  messageSource.setFallbackToSystemLocale(false);
  messageSource.setBasenames("validation");
  messageSource.setDefaultEncoding("utf8");

  LocalValidatorFactoryBean localValidator = new LocalValidatorFactoryBean();
  localValidator.setValidationMessageSource(messageSource);
  localValidator.afterPropertiesSet();
  return localValidator;
}
 
開發者ID:puncha,項目名稱:petclinic,代碼行數:13,代碼來源:TestUtil.java

示例14: testInnerBeanValidation

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Test
public void testInnerBeanValidation() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	MainBean mainBean = new MainBean();
	Errors errors = new BeanPropertyBindingResult(mainBean, "mainBean");
	validator.validate(mainBean, errors);
	Object rejected = errors.getFieldValue("inner.value");
	assertNull(rejected);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:ValidatorFactoryTests.java

示例15: testValidationWithOptionalField

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入方法依賴的package包/類
@Test
public void testValidationWithOptionalField() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	MainBeanWithOptional mainBean = new MainBeanWithOptional();
	Errors errors = new BeanPropertyBindingResult(mainBean, "mainBean");
	validator.validate(mainBean, errors);
	Object rejected = errors.getFieldValue("inner.value");
	assertNull(rejected);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:ValidatorFactoryTests.java


注:本文中的org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。