use of javax.validation.Validator in project podam by devopsfolks.
the class ValidatedPojoTest method whenDigitsAndDecimalMinOrDecimalMaxAreAttachedToTheSameFieldPodamShouldUseMinimumRequirement.
@Test
@Title("When the @Digits and @DecimalMin and @DecimalMax applied to the same field, Podam should use minimum requirements")
public void whenDigitsAndDecimalMinOrDecimalMaxAreAttachedToTheSameFieldPodamShouldUseMinimumRequirement() throws Exception {
PodamFactory podamFactory = podamFactorySteps.givenAStandardPodamFactory();
ValidatedPojoMultipleConstraints pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidatedPojoMultipleConstraints.class, podamFactory);
podamValidationSteps.theObjectShouldNotBeNull(pojo);
Validator validator = podamFactorySteps.givenAJavaxValidator();
validatorSteps.thePojoShouldNotViolateAnyValidations(validator, pojo);
}
use of javax.validation.Validator in project podam by devopsfolks.
the class ValidatedPojoTest method podamShouldAllowValidationAnnotationsCustomization.
@Test
@Title("Podam should allow validation annotations customization")
public void podamShouldAllowValidationAnnotationsCustomization() throws Exception {
AttributeStrategy<?> strategy = new PatternStrategy();
PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithCustomStrategy(Pattern.class, strategy);
ValidatedPatternPojo pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidatedPatternPojo.class, podamFactory);
podamValidationSteps.thePojoMustBeOfTheType(pojo, ValidatedPatternPojo.class);
podamValidationSteps.thePojoMustBeOfTheType(pojo.getNumber(), String.class);
podamValidationSteps.thePojoMustBeOfTheType(pojo.getIdentifier(), String.class);
Validator validator = podamFactorySteps.givenAJavaxValidator();
validatorSteps.thePojoShouldNotViolateAnyValidations(validator, pojo);
podamFactorySteps.removeCustomStrategy(podamFactory, Pattern.class);
}
use of javax.validation.Validator in project jo-client-platform by jo-source.
the class BeanPropertyValidatorAdapter method validate.
@SuppressWarnings("unchecked")
@Override
public IValidationResult validate(final Object value) {
if (propertyValidatable) {
final Set<ConstraintViolation<Object>> beanValidationResult;
try {
final Validator beanValidator = CapCommonToolkit.beanValidator();
beanValidationResult = beanValidator.validateValue((Class<Object>) beanType, propertyName, value);
} catch (final Exception e) {
propertyValidatable = false;
return ValidationResult.ok();
}
for (final ConstraintViolation<Object> violation : beanValidationResult) {
return ValidationResult.error(violation.getMessage());
}
}
return ValidationResult.ok();
}
use of javax.validation.Validator in project Payara by payara.
the class BVIntegrationTestServlet method configureValidation.
private Validator configureValidation(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
GenericBootstrap bootstrap = Validation.byDefaultProvider();
Configuration config = bootstrap.configure();
InputStream mappingsXml = new ByteArrayInputStream(validationXml.getBytes());
config.addMapping(mappingsXml);
ValidatorFactory factory = config.buildValidatorFactory();
ValidatorContext validatorContext = factory.usingContext();
Validator validator = validatorContext.getValidator();
if (validator == null) {
factory = Validation.byDefaultProvider().configure().buildValidatorFactory();
validator = factory.getValidator();
}
out.print("<p>");
out.print("Obtained ValidatorFactory: " + factory + ".");
out.print("</p>");
return validator;
}
Aggregations