本文整理匯總了Java中org.springframework.validation.beanvalidation.LocalValidatorFactoryBean類的典型用法代碼示例。如果您正苦於以下問題:Java LocalValidatorFactoryBean類的具體用法?Java LocalValidatorFactoryBean怎麽用?Java LocalValidatorFactoryBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LocalValidatorFactoryBean類屬於org.springframework.validation.beanvalidation包,在下文中一共展示了LocalValidatorFactoryBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: entityManagerFactory
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
DataSource dataSource,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl,
LocalValidatorFactoryBean localValidatorFactoryBean) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(jpaProperties.getHibernateProperties(dataSource));
properties.put(MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties.put(MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
properties.put(MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
properties.put(JPA_VALIDATION_FACTORY, localValidatorFactoryBean);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan(JPA_PACKAGES);
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
示例2: requestMappingHandlerAdapter
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void requestMappingHandlerAdapter() throws Exception {
delegatingConfig.setConfigurers(Arrays.asList(webMvcConfigurer));
RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
ConversionService initializerConversionService = initializer.getConversionService();
assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);
verify(webMvcConfigurer).configureMessageConverters(converters.capture());
verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
verify(webMvcConfigurer).addFormatters(conversionService.capture());
verify(webMvcConfigurer).addArgumentResolvers(resolvers.capture());
verify(webMvcConfigurer).addReturnValueHandlers(handlers.capture());
verify(webMvcConfigurer).configureAsyncSupport(asyncConfigurer.capture());
assertSame(conversionService.getValue(), initializerConversionService);
assertEquals(0, resolvers.getValue().size());
assertEquals(0, handlers.getValue().size());
assertEquals(converters.getValue(), adapter.getMessageConverters());
assertNotNull(asyncConfigurer);
}
示例3: testSimpleValidation
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void testSimpleValidation() throws Exception {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
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();
}
示例4: 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();
}
示例5: 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"));
}
示例6: testSpringValidationWithAutowiredValidator
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void testSpringValidationWithAutowiredValidator() throws Exception {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
LocalValidatorFactoryBean.class);
LocalValidatorFactoryBean validator = ctx.getBean(LocalValidatorFactoryBean.class);
ValidPerson person = new ValidPerson();
person.expectsAutowiredValidator = true;
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"));
ctx.close();
}
示例7: 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());
}
示例8: 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());
}
示例9: setUp
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
EventValidator.ValidationConfig validationConfig = new EventValidator.ValidationConfig();
validationConfig.setEnvironment(Mockito.mock(Environment.class));
EventValidator.setValidationConfig(validationConfig);
this.validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
EntityFactory entityFactory = new HibEntityFactory();
EntityConverter entityConverter = new EntityConverter(entityFactory);
this.converter = new ContentConverter(entityConverter);
instanceUnderTest = new SimpleUrlContentReader(converter, null, validator, 700, instanceProvider);
}
示例10: requestMappingHandlerAdapter
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void requestMappingHandlerAdapter() throws Exception {
RequestMappingHandlerAdapter adapter = mvcConfiguration.requestMappingHandlerAdapter();
List<HttpMessageConverter<?>> expectedConverters = new ArrayList<HttpMessageConverter<?>>();
mvcConfiguration.addDefaultHttpMessageConverters(expectedConverters);
assertEquals(expectedConverters.size(), adapter.getMessageConverters().size());
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
assertNotNull(initializer);
ConversionService conversionService = initializer.getConversionService();
assertNotNull(conversionService);
assertTrue(conversionService instanceof FormattingConversionService);
Validator validator = initializer.getValidator();
assertNotNull(validator);
assertTrue(validator instanceof LocalValidatorFactoryBean);
}
示例11: 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);
}
示例12: localValidatorFactoryBean
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Bean
public LocalValidatorFactoryBean localValidatorFactoryBean() {
HibernateValidatorConfigurationStrategy strategy = Optional.ofNullable(hibernateValidatorConfigurationStrategy)
.orElseGet(() -> configuration -> {
});
List<? extends ConstraintValidator> validators = Optional.ofNullable(this.validators)
.orElseGet(Collections::emptyList);
return new CustomLocalValidatorFactoryBean(strategy, validators);
}
示例13: entityManagerFactory
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl,
LocalValidatorFactoryBean localValidatorFactoryBean) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(jpaProperties.getHibernateProperties(dataSource));
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties
.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
properties
.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
properties.put(JPA_VALIDATION_FACTORY, localValidatorFactoryBean);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan(JPA_PACKAGES);
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
示例14: validator
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
/**
* Custom validator.
* @param messageSource {@link MessageSource}
* @return de {@link Validator}
*/
@Bean
public Validator validator(MessageSource messageSource) {
LocalValidatorFactoryBean factory = new LocalValidatorFactoryBean();
factory.setValidationMessageSource(messageSource);
return factory;
}
示例15: getValidator
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Override
public Validator getValidator() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.setValidationMessageSource(messageSource);
return validator;
}