use of javax.validation.Validator in project druid by druid-io.
the class S3DataSegmentPusherConfigTest method testSerializationValidatingMaxListingLength.
@Test
public void testSerializationValidatingMaxListingLength() throws IOException {
String jsonConfig = "{\"bucket\":\"bucket1\",\"baseKey\":\"dataSource1\"," + "\"disableAcl\":false,\"maxListingLength\":-1}";
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
S3DataSegmentPusherConfig config = jsonMapper.readValue(jsonConfig, S3DataSegmentPusherConfig.class);
Set<ConstraintViolation<S3DataSegmentPusherConfig>> violations = validator.validate(config);
Assert.assertEquals(1, violations.size());
ConstraintViolation violation = Iterators.getOnlyElement(violations.iterator());
Assert.assertEquals("must be greater than or equal to 0", violation.getMessage());
}
use of javax.validation.Validator in project dropwizard by dropwizard.
the class ConstraintViolationBenchmark method prepare.
@Setup
public void prepare() {
final Validator validator = Validators.newValidator();
final ExecutableValidator execValidator = validator.forExecutables();
final Set<ConstraintViolation<ConstraintViolationBenchmark.Resource>> paramViolations = execValidator.validateParameters(new Resource(), getAccessibleMethod(ConstraintViolationBenchmark.Resource.class, "paramFunc", String.class), // the parameter value
new Object[] { "" });
paramViolation = paramViolations.iterator().next();
final Set<ConstraintViolation<ConstraintViolationBenchmark.Resource>> objViolations = execValidator.validateParameters(new Resource(), getAccessibleMethod(ConstraintViolationBenchmark.Resource.class, "objectFunc", Foo.class), // the parameter value
new Object[] { new Foo() });
objViolation = objViolations.iterator().next();
}
use of javax.validation.Validator in project platformlayer by platformlayer.
the class PlatformlayerValidationModule method configure.
@Override
protected void configure() {
Configuration<?> config = Validation.byDefaultProvider().configure();
// config.messageInterpolator(new MyMessageInterpolator())
// .traversableResolver( new MyTraversableResolver())
// .constraintValidatorFactory(new MyConstraintValidatorFactory());
config.messageInterpolator(new ValidationMessageInterpolator());
ValidatorFactory factory = config.buildValidatorFactory();
// ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
bind(Validator.class).toInstance(validator);
}
use of javax.validation.Validator in project JessMA by ldcsaa.
the class HibernateBeanValidator method tryCreateValidator.
private Validator tryCreateValidator(final String bundle, final Locale locale, ValidatorKey key) {
HibernateValidatorConfiguration configure = Validation.byProvider(HibernateValidator.class).configure();
configure.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(bundle)) {
@Override
public String interpolate(String message, Context context) {
return super.interpolate(message, context, locale);
}
});
ValidatorFactory vf = configure.buildValidatorFactory();
Validator validator = vf.getValidator();
GeneralHelper.syncTryPut(validatorMap, key, validator);
return validatorMap.get(key);
}
use of javax.validation.Validator in project torodb by torodb.
the class ConfigUtils method validateBean.
public static <T> void validateBean(T config) {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<T>> constraintViolations = validator.validate(config);
if (!constraintViolations.isEmpty()) {
IllegalArgumentException illegalArgumentException = transformConstraintsValidation(constraintViolations);
throw illegalArgumentException;
}
}
Aggregations