use of javax.validation.ValidatorFactory in project tomee by apache.
the class BeanValidationTest method lookupValidatorFactory.
@Test
public void lookupValidatorFactory() throws Exception {
final ValidatorFactory validatorFactory = (ValidatorFactory) new InitialContext().lookup("java:comp/ValidatorFactory");
assertNotNull(validatorFactory);
}
use of javax.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 javax.validation.Configuration<?> configuration = Validation.byDefaultProvider().configure();
configuration.messageInterpolator(messageInterpolator);
ValidatorFactory vf = configuration.buildValidatorFactory();
cfg.getProperties().put("javax.persistence.validation.factory", vf);
cfg.setProperty("javax.persistence.validation.mode", "AUTO");
}
use of javax.validation.ValidatorFactory in project hibernate-orm by hibernate.
the class BeanValidationEventListener method initialize.
public void initialize(Map settings, ClassLoaderService classLoaderService) {
if (!initialized) {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
init(factory, settings, classLoaderService);
}
}
use of javax.validation.ValidatorFactory in project keywhiz by square.
the class ValidX500NameValidatorTest method setUp.
@BeforeClass
public static void setUp() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
}
use of javax.validation.ValidatorFactory in project wildfly by wildfly.
the class BootStrapValidationTestCase method testCustomConstraintValidatorFactory.
@Test
public void testCustomConstraintValidatorFactory() {
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
assertNotNull(configuration);
ValidatorFactory factory = configuration.buildValidatorFactory();
Validator validator = factory.getValidator();
Employee emp = new Employee();
// create employee
emp.setEmpId("M1234");
emp.setFirstName("MADHUMITA");
emp.setLastName("SADHUKHAN");
emp.setEmail("madhu@redhat.com");
Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);
assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
assertEquals("Created by default factory", constraintViolations.iterator().next().getMessage());
// get a new factory using a custom configuration
configuration.constraintValidatorFactory(new CustomConstraintValidatorFactory(configuration.getDefaultConstraintValidatorFactory()));
factory = configuration.buildValidatorFactory();
validator = factory.getValidator();
constraintViolations = validator.validate(emp);
assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
assertEquals("Created by custom factory", constraintViolations.iterator().next().getMessage());
}
Aggregations