use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class PropertyNodeNameProviderTest method hibernateValidatorFallsBackToDefaultPropertyNodeNameProvider.
@Test
public void hibernateValidatorFallsBackToDefaultPropertyNodeNameProvider() {
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure().propertyNodeNameProvider(null).buildValidatorFactory();
Validator val = validatorFactory.getValidator();
Car testInstance = new Car(INVALID_BRAND_NAME);
Set<ConstraintViolation<Car>> violations = val.validate(testInstance);
ConstraintViolation<Car> violation = violations.iterator().next();
assertEquals(violation.getPropertyPath().toString(), "brand.name");
}
use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class JacksonAnnotationPropertyNodeNameProviderTest method setUp.
@BeforeMethod
public void setUp() {
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure().propertyNodeNameProvider(new JacksonAnnotationPropertyNodeNameProvider()).buildValidatorFactory();
validator = validatorFactory.getValidator();
}
use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class LocaleResolverTest method testLanguageRangeSupport.
@Test
public void testLanguageRangeSupport() throws NoSuchMethodException, SecurityException {
ValidatorFactory validatorFactory = getValidatorFactoryWithInitializedLocales(Locale.FRANCE, new Locale("es", "ES"));
MessageInterpolator messageInterpolator = validatorFactory.getMessageInterpolator();
StaticFieldLocaleResolver.acceptLanguage = "fr-FR,fr;q=0.9";
assertThat(messageInterpolator.interpolate("{jakarta.validation.constraints.AssertFalse.message}", new TestContext())).isEqualTo("doit avoir la valeur faux");
}
use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class PredefinedScopeConstraintDefinitionContributorTest method setUp.
@BeforeMethod
public void setUp() {
validator = getValidator();
Set<Class<?>> beanMetaDataToInitialize = new HashSet<>();
beanMetaDataToInitialize.add(Foo.class);
beanMetaDataToInitialize.add(Quz.class);
ValidatorFactory validatorFactory = Validation.byProvider(PredefinedScopeHibernateValidator.class).configure().initializeBeanMetaData(beanMetaDataToInitialize).buildValidatorFactory();
validator = validatorFactory.getValidator();
}
use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class PredefinedScopeValidatorFactoryTest method testBeanMetaDataClassNormalizerNoNormalizer.
@Test
public void testBeanMetaDataClassNormalizerNoNormalizer() {
// In this case, as we haven't registered any metadata for the hierarchy, even if we have constraints,
// we won't have any violations.
Set<ConstraintViolation<Bean>> violations = getValidator().validate(new BeanProxy());
assertNoViolations(violations);
// Now let's register the metadata for Bean and see how it goes
Set<Class<?>> beanMetaDataToInitialize = new HashSet<>();
beanMetaDataToInitialize.add(Bean.class);
ValidatorFactory validatorFactory = Validation.byProvider(PredefinedScopeHibernateValidator.class).configure().initializeBeanMetaData(beanMetaDataToInitialize).locales(Collections.singleton(Locale.getDefault())).buildValidatorFactory();
// As we don't have any metadata for BeanProxy, we consider it is not constrained at all.
violations = validatorFactory.getValidator().validate(new BeanProxy());
assertNoViolations(violations);
}
Aggregations