use of javax.validation.Validator in project keywhiz by square.
the class MigrationsRule method apply.
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper objectMapper = KeywhizService.customizeObjectMapper(Jackson.newObjectMapper());
KeywhizConfig config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw").build(yamlFile);
DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "db-migrations");
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setLocations(config.getMigrationsDir());
flyway.clean();
flyway.migrate();
DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
DbSeedCommand.doImport(dslContext);
base.evaluate();
}
};
}
use of javax.validation.Validator in project keywhiz by square.
the class LdapLookupConfigTest method parsesLDAPLookupCorrectly.
@Test
public void parsesLDAPLookupCorrectly() throws Exception {
File yamlFile = new File(Resources.getResource("fixtures/keywhiz-ldap-lookup-test.yaml").getFile());
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();
LdapLookupConfig lookupConfig = new ConfigurationFactory<>(LdapLookupConfig.class, validator, objectMapper, "dw").build(yamlFile);
assertThat(lookupConfig.getRequiredRoles()).containsOnly("keywhizAdmins");
assertThat(lookupConfig.getRoleBaseDN()).isEqualTo("ou=ApplicationAccess,dc=test,dc=com");
assertThat(lookupConfig.getUserBaseDN()).isEqualTo("ou=people,dc=test,dc=com");
assertThat(lookupConfig.getUserAttribute()).isEqualTo("uid");
}
use of javax.validation.Validator in project wildfly by wildfly.
the class LazyValidatorFactoryTestCase method testHibernateValidatorIsUsedAsProviderByDefault.
@Test
public void testHibernateValidatorIsUsedAsProviderByDefault() {
HibernateValidatorFactory hibernateValidatorFactory = validatorFactory.unwrap(HibernateValidatorFactory.class);
assertNotNull("LazyValidatorFactory should delegate to the HV factory by default", hibernateValidatorFactory);
Validator validator = validatorFactory.getValidator();
assertNotNull("LazyValidatorFactory should provide a validator", validator);
}
use of javax.validation.Validator in project wildfly by wildfly.
the class LazyValidatorFactoryTestCase method testSpecificProviderCanBeConfiguredInValidationXml.
@Test
@WithContextClassLoader(TestClassLoader.class)
public void testSpecificProviderCanBeConfiguredInValidationXml() {
Validator validator = validatorFactory.getValidator();
assertNotNull("LazyValidatorFactory should provide a validator", validator);
assertTrue("Validator should be of type created by XML-configured provider", validator instanceof MyValidatorImpl);
}
use of javax.validation.Validator 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