use of jakarta.validation.ValidatorFactory in project minijax by minijax.
the class ValidationTest method setUpValidator.
@BeforeAll
public static void setUpValidator() {
// tag::setUpValidator[]
final ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
// end::setUpValidator[]
}
use of jakarta.validation.ValidatorFactory in project hibernate-orm by hibernate.
the class BeanValidationProvidedFactoryTest method configure.
@Override
protected void configure(Configuration cfg) {
super.configure(cfg);
final MessageInterpolator messageInterpolator = new MessageInterpolator() {
public String interpolate(String s, Context context) {
return "Oops";
}
public String interpolate(String s, Context context, Locale locale) {
return interpolate(s, context);
}
};
final jakarta.validation.Configuration<?> configuration = Validation.byDefaultProvider().configure();
configuration.messageInterpolator(messageInterpolator);
ValidatorFactory vf = configuration.buildValidatorFactory();
cfg.getProperties().put("jakarta.persistence.validation.factory", vf);
cfg.setProperty("javax.persistence.validation.mode", "AUTO");
}
use of jakarta.validation.ValidatorFactory in project hibernate-orm by hibernate.
the class TypeSafeActivator method activate.
@SuppressWarnings("UnusedDeclaration")
public static void activate(ActivationContext activationContext) {
final ValidatorFactory factory;
try {
factory = getValidatorFactory(activationContext);
} catch (IntegrationException e) {
if (activationContext.getValidationModes().contains(ValidationMode.CALLBACK)) {
throw new IntegrationException("Bean Validation provider was not available, but 'callback' validation was requested", e);
}
if (activationContext.getValidationModes().contains(ValidationMode.DDL)) {
throw new IntegrationException("Bean Validation provider was not available, but 'ddl' validation was requested", e);
}
LOG.debug("Unable to acquire Bean Validation ValidatorFactory, skipping activation");
return;
}
applyRelationalConstraints(factory, activationContext);
applyCallbackListeners(factory, activationContext);
}
use of jakarta.validation.ValidatorFactory in project hibernate-orm by hibernate.
the class TypeSafeActivator method getValidatorFactory.
private static ValidatorFactory getValidatorFactory(ActivationContext activationContext) {
// IMPL NOTE : We can either be provided a ValidatorFactory or make one. We can be provided
// a ValidatorFactory in 2 different ways. So here we "get" a ValidatorFactory in the following order:
// 1) Look into SessionFactoryOptions.getValidatorFactoryReference()
// 2) Look into ConfigurationService
// 3) build a new ValidatorFactory
// 1 - look in SessionFactoryOptions.getValidatorFactoryReference()
ValidatorFactory factory = resolveProvidedFactory(activationContext.getSessionFactory().getSessionFactoryOptions());
if (factory != null) {
return factory;
}
// 2 - look in ConfigurationService
factory = resolveProvidedFactory(activationContext.getServiceRegistry().getService(ConfigurationService.class));
if (factory != null) {
return factory;
}
// 3 - build our own
try {
return Validation.buildDefaultValidatorFactory();
} catch (Exception e) {
LOG.infof(e, "Error calling `%s`", "jakarta.validation.Validation#buildDefaultValidatorFactory");
throw new IntegrationException("Unable to build the default ValidatorFactory", e);
}
}
use of jakarta.validation.ValidatorFactory in project gocd-groovy-dsl-config-plugin by gocd-contrib.
the class TestBase method validate.
protected static void validate(Object object, Consumer<Set<ConstraintViolation<Object>>> errorHandler) {
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
Validator validator = validatorFactory.getValidator();
Set<ConstraintViolation<Object>> violations = validator.validate(object);
if (!violations.isEmpty()) {
errorHandler.accept(violations);
}
}
Aggregations