Java 类org.hibernate.validator.HibernateValidator 实例源码

项目:spring4-understanding    文件:ValidatorFactoryTests.java   
@Test
public void testSimpleValidationWithCustomProvider() throws Exception {
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    validator.setProviderClass(HibernateValidator.class);
    validator.afterPropertiesSet();
    ValidPerson person = new ValidPerson();
    Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
    assertEquals(2, result.size());
    for (ConstraintViolation<ValidPerson> cv : result) {
        String path = cv.getPropertyPath().toString();
        if ("name".equals(path) || "address.street".equals(path)) {
            assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
        }
        else {
            fail("Invalid constraint violation with path '" + path + "'");
        }
    }
    validator.destroy();
}
项目:spring4-understanding    文件:ValidatorFactoryTests.java   
@Test
public void testSimpleValidationWithCustomProvider() throws Exception {
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    validator.setProviderClass(HibernateValidator.class);
    validator.afterPropertiesSet();

    ValidPerson person = new ValidPerson();
    Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
    assertEquals(2, result.size());
    for (ConstraintViolation<ValidPerson> cv : result) {
        String path = cv.getPropertyPath().toString();
        if ("name".equals(path) || "address.street".equals(path)) {
            assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
        }
        else {
            fail("Invalid constraint violation with path '" + path + "'");
        }
    }
    validator.destroy();
}
项目:restler    文件:TestRestlerModule.java   
@Override
public RestlerConfig getConfiguration()  {
    ObjectMapper objectMapper = Jackson.newObjectMapper();

    ValidatorFactory validatorFactory = Validation
            .byProvider(HibernateValidator.class)
            .configure()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
            .buildValidatorFactory();


    final ConfigurationFactory<RestlerConfig> configurationFactory =
            new DefaultConfigurationFactoryFactory<RestlerConfig>().create(RestlerConfig.class, validatorFactory.getValidator(), objectMapper, "dw");

    try {
        return configurationFactory.build(new FileConfigurationSourceProvider(), TEST_CONFIG_FILE);
    } catch (Exception e) {
        throw new RuntimeException("Cannot get test configuration", e);
    }
}
项目:adeptj-modules    文件:BeanValidationActivator.java   
@Override
public void start(BundleContext context) throws Exception {
    HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class)
            .configure();
    configuration.parameterNameProvider(new ReflectionParameterNameProvider());
    configuration.messageInterpolator(new LocaleSpecificMessageInterpolator(configuration
            .getDefaultMessageInterpolator()));
    validatorFactory = configuration.buildValidatorFactory();
    Dictionary<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_VENDOR, "AdeptJ");
    props.put(Constants.SERVICE_DESCRIPTION, "AdeptJ ValidatorService");
    servRegValidatorService = context.registerService(ValidatorService.class,
            new OSGiBeanValidatorService(this.validatorFactory.getValidator(),
                    configuration.getBootstrapConfiguration()),
            props);
}
项目:nexus-public    文件:ValidationInterceptor.java   
public Object invoke(final MethodInvocation mi) throws Throwable {
  checkNotNull(methodValidator);

  final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(HibernateValidator.class.getClassLoader());
    final Validate validate = mi.getMethod().getAnnotation(Validate.class);

    validateParameters(mi.getThis(), mi.getMethod(), mi.getArguments(), validate.groups());

    final Object result = mi.proceed();

    validateReturnValue(mi.getThis(), mi.getMethod(), result, validate.groups());

    return result;
  }
  finally {
    Thread.currentThread().setContextClassLoader(tccl);
  }
}
项目:nest-old    文件:HibernateValidationConfigurationInitializer.java   
/**
 * create hibernate validation configuration
 * 
 * @return
 */
protected HibernateValidatorConfiguration createConfiguration() {
    HibernateValidatorConfiguration configuration = null;
    if (this.isIgnoreClassHierarchy()) {
        ValidationProviderResolver resolver = new ValidationProviderResolver() {
            /**
             * (non-Javadoc)
             * 
             * @see javax.validation.ValidationProviderResolver#getValidationProviders()
             */
            @Override
            public List<ValidationProvider<?>> getValidationProviders() {
                List<ValidationProvider<?>> providers = new ArrayList<ValidationProvider<?>>(1);
                providers.add(new HibernateValidator513());
                return providers;
            }
        };
        configuration = Validation.byProvider(HibernateValidator513.class).providerResolver(resolver).configure();
    } else {
        configuration = Validation.byProvider(HibernateValidator.class).configure();
    }
    configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(
            MESSAGES)));
    return configuration;
}
项目:javase-study    文件:SysRoleValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRole.class)
            .property("roleName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .constraint(new PatternDef().regexp("^(?!root$).+$").message(
                    "may not be root"))
            .property("roleCode", ElementType.FIELD)
            .constraint(new NotNullDef()).constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysRouteUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRoute.class)
            .property("routeId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("name", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("url", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysMenuValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysMenu.class)
            .property("menuName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .property("menuPath", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"))
            .property("parentId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("icon", ElementType.FIELD)
            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysUserUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysUser.class)
            .property("userId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("username", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(3))
            .constraint(new PatternDef().regexp("[a-zA-Z][0-9a-zA-Z_]*")
                    .message("{msg.error.validation.username.pattern}"))
            .property("password", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .property("fullName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("email", ElementType.FIELD).constraint(new EmailDef())
            .constraint(new SizeDef().max(64));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysRoleUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping.type(SysRole.class).property("roleId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("roleName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new PatternDef().regexp("^(?!root$).+$").message("may not be root"))
            .property("roleCode", ElementType.FIELD)

            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysUserValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysUser.class)
            .property("username", ElementType.FIELD)
            .constraint(new NotNullDef())
            .constraint(new SizeDef().max(16).min(3))
            .constraint(new PatternDef().regexp("[a-zA-Z][0-9a-zA-Z_]*")
                    .message("{msg.error.validation.username.pattern}"))
            .property("password", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("fullName", ElementType.FIELD)
            .constraint(new NotNullDef()).constraint(new SizeDef().max(32))
            .property("email", ElementType.FIELD)
            .constraint(new SizeDef().max(64)).constraint(new EmailDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:PasswordValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping.type(ChangePasswordVo.class)
            .property("oldpassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("newpassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("retypepassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysMenuUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysMenu.class)
            .property("menuId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("menuName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("menuPath", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"))
            .property("icon", ElementType.FIELD)
            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysRouteValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRoute.class)
            .property("name", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .property("url", ElementType.FIELD)
            .constraint(new NotNullDef())
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysJobUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping.type(SysJob.class).property("jobId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("clazzName", ElementType.FIELD).constraint(new NullDef())
            .property("jobName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("cron", ElementType.FIELD)
            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysJobValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysJob.class)
            .property("clazzName", ElementType.FIELD)
            .constraint(new NotNullDef())
            .constraint(new SizeDef().max(64))
            .constraint(new PatternDef().regexp("[a-zA-Z.]+")
                    .message("{msg.error.validation.className.pattern}"))
            .property("jobName", ElementType.FIELD)
            .constraint(new SizeDef().max(32)).constraint(new NotNullDef())
            .property("cron", ElementType.FIELD)
            .constraint(new SizeDef().max(32)).constraint(new NotNullDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysDictValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysDict.class)
            .property("dictCode", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .constraint(new PatternDef().regexp("[0-9a-zA-Z_]+").message(
                    "{msg.error.validation.dictCode.pattern}"))
            .property("dictName", ElementType.FIELD)
            .constraint(new SizeDef().max(32)).constraint(new NotNullDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:class-guard    文件:ValidatorFactoryTests.java   
@Test
public void testSimpleValidationWithCustomProvider() throws Exception {
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    validator.setProviderClass(HibernateValidator.class);
    validator.afterPropertiesSet();
    ValidPerson person = new ValidPerson();
    Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
    assertEquals(2, result.size());
    for (ConstraintViolation<ValidPerson> cv : result) {
        String path = cv.getPropertyPath().toString();
        if ("name".equals(path) || "address.street".equals(path)) {
            assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
        }
        else {
            fail("Invalid constraint violation with path '" + path + "'");
        }
    }
}
项目:jooby    文件:Hbv.java   
@Override
public void configure(final Env env, final Config config, final Binder binder) {
  HibernateValidatorConfiguration configuration = byProvider(HibernateValidator.class)
      .configure();

  if (config.hasPath("hibernate.validator")) {
    config.getConfig("hibernate.validator").root().forEach((k, v) -> {
      configuration.addProperty("hibernate.validator." + k, v.unwrapped().toString());
    });
  }

  if (configurer != null) {
    configurer.accept(configuration, config);
  }

  binder.bind(HibernateValidatorConfiguration.class).toInstance(configuration);

  binder.bind(Validator.class).toProvider(HbvFactory.class).asEagerSingleton();

  env.lifeCycle(HbvFactory.class);

  Multibinder.newSetBinder(binder, Parser.class).addBinding()
      .toInstance(new HbvParser(predicate));
}
项目:openhds-server    文件:HeadOfHouseholdTest.java   
@Before
public void setUp(){

 currentUser.setProxyUser("admin", "test", new String[] {"VIEW_ENTITY", "CREATE_ENTITY"});

 assertNotNull(headOfHouseholdService);

    localValidatorFactory = new LocalValidatorFactoryBean();
    localValidatorFactory.setProviderClass(HibernateValidator.class);
    localValidatorFactory.afterPropertiesSet();

    oldHoh = genericDao.findByProperty(Individual.class, "extId", "NBAS1I"); 
    newHoh = genericDao.findByProperty(Individual.class, "extId", "BJOH1J");
 visit = genericDao.findByProperty(Visit.class, "extId", "VLOCMBI11J");
 fieldWorker = genericDao.findByProperty(FieldWorker.class, "extId", "FWEK1D");
 socialGroup = genericDao.findByProperty(SocialGroup.class, "extId", "MBI1", false);

 assertNotNull(oldHoh);
 assertNotNull(newHoh);
 assertNotNull(visit);
 assertNotNull(fieldWorker);
 assertNotNull(socialGroup);
}
项目:syndesis    文件:IntegrationTest.java   
public IntegrationTest() {
    final DefaultConstraintMapping mapping = new DefaultConstraintMapping();
    mapping.constraintDefinition(UniqueProperty.class).validatedBy(UniqnenessValidator.class);
    final ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure()
        .addMapping(mapping).buildValidatorFactory();

    validator = validatorFactory.getValidator();
}
项目:circus-train    文件:SourceCatalogTest.java   
@Before
public void before() {
  validator.setProviderClass(HibernateValidator.class);
  validator.afterPropertiesSet();

  sourceCatalog.setName("name");
}
项目:circus-train    文件:MetastoreTunnelTest.java   
@Before
public void before() {
  validator.setProviderClass(HibernateValidator.class);
  validator.afterPropertiesSet();

  tunnel.setKnownHosts("knownHosts");
  tunnel.setPrivateKeys("privateKey");
  tunnel.setRoute("hostA -> hostB");
}
项目:circus-train    文件:SourceTableTest.java   
@Before
public void before() {
  validator.setProviderClass(HibernateValidator.class);
  validator.afterPropertiesSet();

  sourceTable.setDatabaseName("databaseName");
  sourceTable.setTableName("tableName");
}
项目:circus-train    文件:ReplicaCatalogTest.java   
@Before
public void before() {
  validator.setProviderClass(HibernateValidator.class);
  validator.afterPropertiesSet();

  replicaCatalog.setName("name");
  replicaCatalog.setHiveMetastoreUris("hiveMetastoreUris");
}
项目:spring-boot-start-current    文件:HibernateValidatorPro.java   
/**
 * 线程安全的
 *
 * @return {@link Validator}
 */
public static Validator getHibernateValidator () {
    return Validation.byProvider( HibernateValidator.class )
         .configure()
         .buildValidatorFactory()
         .getValidator();
}
项目:waggle-dance    文件:WaggleDanceConfigurationTest.java   
@Before
public void before() {
  validator.setProviderClass(HibernateValidator.class);
  validator.afterPropertiesSet();

  waggleDanceConfiguration.setPort(123);
  waggleDanceConfiguration.setVerbose(true);
  waggleDanceConfiguration.setDisconnectConnectionDelay(15);
  waggleDanceConfiguration.setDisconnectTimeUnit(TimeUnit.SECONDS);
  waggleDanceConfiguration
      .setConfigurationProperties(ImmutableMap.<String, String> builder().put("prop1", "val1").build());
}
项目:waggle-dance    文件:AbstractMetaStoreTest.java   
@Before
public void before() {
  validator.setProviderClass(HibernateValidator.class);
  validator.afterPropertiesSet();

  metaStore.setRemoteMetaStoreUris("uri");
  metaStore.setName("name");
}
项目:waggle-dance    文件:MetastoreTunnelTest.java   
@Before
public void before() {
  validator.setProviderClass(HibernateValidator.class);
  validator.afterPropertiesSet();

  tunnel.setKnownHosts("knownHosts");
  tunnel.setPrivateKeys("privateKey");
  tunnel.setRoute("hostA -> hostB");
}
项目:dremio-oss    文件:InputValidation.java   
public InputValidation() {
  this.configuration = Validation.byProvider(HibernateValidator.class).configure();
  this.constraints = configuration.createConstraintMapping();

  configureConstraints();

  this.validator = this.configuration.addMapping(constraints)
      .buildValidatorFactory()
      .getValidator();
}
项目:validator-web    文件:HibernateValidation.java   
@Override
public void initialize(ValidationContext context) {
    context.setValidatorDelegate(this);

    HibernateValidatorConfiguration configure = javax.validation.Validation.byProvider(HibernateValidator.class).configure();
    if (context instanceof ValidationContext.Accessor) {
        configure.failFast(((ValidationContext.Accessor) context).isFailFast());
    }
    ValidatorFactory factory = configure.buildValidatorFactory();
    validator = factory.getValidator();
}
项目:crow    文件:ValidationTest.java   
@Before
public void setup() {
    job = new Job();
    localValidatorFactory = new LocalValidatorFactoryBean();
    localValidatorFactory.setProviderClass(HibernateValidator.class);
    localValidatorFactory.afterPropertiesSet();
}
项目:syndesis-rest    文件:IntegrationTest.java   
public IntegrationTest() {
    final DefaultConstraintMapping mapping = new DefaultConstraintMapping();
    mapping.constraintDefinition(UniqueProperty.class).validatedBy(UniqnenessValidator.class);
    final ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure()
        .addMapping(mapping).buildValidatorFactory();

    validator = validatorFactory.getValidator();
}
项目:cuba    文件:BeanValidationImpl.java   
protected HibernateValidatorConfiguration getValidatorFactoryConfiguration(Locale locale) {
    @SuppressWarnings("UnnecessaryLocalVariable")
    HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class)
            .configure()
            .timeProvider(new CubaValidationTimeProvider(timeSource))
            .traversableResolver(new CubaValidationTraversableResolver(metadata, entityStates))
            .messageInterpolator(new CubaValidationMessagesInterpolator(messages, locale));

    return configuration;
}
项目:auth    文件:ConfigurationParser.java   
/**
 * Parses the given configuration file and returns a configuration object.
 *
 * @param configurationFileName The name of the configuration file.
 * @return A configuration object.
 * @throws IOException The IO error that contains detail information.
 * @throws ConfigurationException The configuration error that contains detail information.
 */
public static ApiConfiguration parse(String configurationFileName)
  throws IOException, ConfigurationException {
  if (StringUtils.isBlank(configurationFileName)) {
    throw new IllegalArgumentException("Configuration file cannot be blank");
  }

  ObjectMapper objectMapper = null;
  if (configurationFileName.endsWith("yml") || configurationFileName.endsWith("yaml")) {
    objectMapper = Jackson.newObjectMapper(new YAMLFactory());
  } else if (configurationFileName.endsWith("json")) {
    objectMapper = Jackson.newObjectMapper(new JsonFactory());
  } else {
    throw new IllegalArgumentException("Unrecognized configuration file type");
  }

  ValidatorFactory validatorFactory = Validation
      .byProvider(HibernateValidator.class)
      .configure()
      .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
      .buildValidatorFactory();

  final ConfigurationFactory<ApiConfiguration> configurationFactory =
      new DefaultConfigurationFactoryFactory<ApiConfiguration>()
        .create(ApiConfiguration.class, validatorFactory.getValidator(), objectMapper, "dw");

  final File file = new File(configurationFileName);
  if (!file.exists()) {
    throw new FileNotFoundException("Configuration file " + configurationFileName + " not found");
  }

  return configurationFactory.build(file);
}
项目:nexus-public    文件:ValidationModule.java   
@Provides
@Singleton
ValidatorFactory validatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
  ClassLoader tccl = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(HibernateValidator.class.getClassLoader());

    ValidatorFactory factory = Validation.byDefaultProvider().configure()
        .constraintValidatorFactory(constraintValidatorFactory)
        .parameterNameProvider(new AopAwareParanamerParameterNameProvider())
        .traversableResolver(new AlwaysTraversableResolver())
        .buildValidatorFactory();

    // FIXME: Install custom MessageInterpolator that can properly find/merge ValidationMessages.properties for bundles

    // exercise interpolator to preload elements (avoids issues later when TCCL might be different)
    factory.getValidator().validate(new Object()
    {
      // minimal token message
      @NotNull(message = "${0}")
      String empty;
    });

    return factory;
  }
  finally {
    Thread.currentThread().setContextClassLoader(tccl);
  }
}
项目:mccy-engine    文件:MccyAssetSettingsNetworkValidatorTest.java   
@Before
public void setUp() throws Exception {
    validatorFactoryBean = new LocalValidatorFactoryBean();
    validatorFactoryBean.setProviderClass(HibernateValidator.class);
    validatorFactoryBean.afterPropertiesSet();

}
项目:mccy-engine    文件:MccyAssetSettingsFixedUriValidatorTest.java   
@Before
public void setUp() throws Exception {
    validatorFactoryBean = new LocalValidatorFactoryBean();
    validatorFactoryBean.setProviderClass(HibernateValidator.class);
    validatorFactoryBean.afterPropertiesSet();

}
项目:SpringBootTwoDataSources    文件:UniquePrimaryTest.java   
@Before
public void before() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.refresh();

    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    beanFactory.registerSingleton(PrimaryRepository.class.getCanonicalName(), primaryRepository);

    validator.setApplicationContext(context);
    validator.setProviderClass(HibernateValidator.class);
    validator.afterPropertiesSet();
}