use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class RelaxedMethodParameterConstraintsTest method allowParameterConstraintsAddedInSubType.
/**
* The converse of disallowParameterConstraintsAddedInSubType,
* relaxes constraint.
*/
@Test
public void allowParameterConstraintsAddedInSubType() {
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
configuration.allowOverridingMethodAlterParameterConstraint(true);
ValidatorFactory factory = configuration.buildValidatorFactory();
Validator validator = factory.getValidator();
Set<? extends ConstraintViolation<?>> violations = validator.forExecutables().validateParameters(new RealizationWithMethodParameterConstraint(), RealizationWithMethodParameterConstraint.class.getDeclaredMethods()[0], new Object[] { "foo" });
ConstraintViolationAssert.assertNoViolations(violations);
configuration.allowOverridingMethodAlterParameterConstraint(false);
}
use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class IgnoreAnnotationConfiguredConstructorValidationTest method setUp.
@BeforeTest
public void setUp() {
final Configuration<?> configuration = ValidatorUtil.getConfiguration();
configuration.addMapping(IgnoreAnnotationConfiguredConstructorValidationTest.class.getResourceAsStream("constructor-validation-ignore-annotations.xml"));
final ValidatorFactory validatorFactory = configuration.buildValidatorFactory();
this.validator = validatorFactory.getValidator();
}
use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class PropertyNodeNameProviderTest method hibernateValidatorCanUseCustomPropertyNodeNameProvider.
@Test
public void hibernateValidatorCanUseCustomPropertyNodeNameProvider() {
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure().propertyNodeNameProvider(new AnnotationPropertyNodeNameProvider(PropertyName.class)).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.brand_name");
}
use of jakarta.validation.ValidatorFactory in project hibernate-validator by hibernate.
the class PropertyNodeNameProviderTest method defaultProviderUsesDefaultPropertyNodeNameProvider.
@Test
public void defaultProviderUsesDefaultPropertyNodeNameProvider() {
ValidatorFactory validatorFactory = Validation.byDefaultProvider().configure().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 PropertyNodeNameProviderTest method hibernateValidatorUsesDefaultPropertyNodeProvider.
@Test
public void hibernateValidatorUsesDefaultPropertyNodeProvider() {
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure().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");
}
Aggregations