use of jakarta.validation.ValidationException in project morphia by mongodb.
the class TestMorphiaValidation method testValidation.
/**
* Test method for {@link ValidationExtension#prePersist(Object, Document, Mapper)}.
*/
public void testValidation() {
final Data data = new Data();
data.email = "not an email";
getDs().getMapper().addInterceptor(new ValidationExtension());
try {
getDs().save(data);
Assert.fail("Should have failed validation");
} catch (ValidationException exception) {
assertTrue(exception.getMessage().contains("Data.email:not a well-formed email address ('not an email')"));
}
data.email = "foo@bar.com";
getDs().save(data);
}
use of jakarta.validation.ValidationException in project mojarra by eclipse-ee4j.
the class BeanValidator method getValidatorFactory.
private static ValidatorFactory getValidatorFactory(FacesContext context) {
ValidatorFactory validatorFactory = null;
Object cachedObject = context.getExternalContext().getApplicationMap().get(VALIDATOR_FACTORY_KEY);
if (cachedObject instanceof ValidatorFactory) {
validatorFactory = (ValidatorFactory) cachedObject;
} else {
try {
validatorFactory = Validation.buildDefaultValidatorFactory();
} catch (ValidationException e) {
throw new FacesException("Could not build a default Bean Validator factory", e);
}
context.getExternalContext().getApplicationMap().put(VALIDATOR_FACTORY_KEY, validatorFactory);
}
return validatorFactory;
}
use of jakarta.validation.ValidationException in project morphia by MorphiaOrg.
the class TestMorphiaValidation method testValidation.
/**
* Test method for {@link ValidationExtension#prePersist(Object, Document, Mapper)}.
*/
public void testValidation() {
final Data data = new Data();
data.email = "not an email";
getDs().getMapper().addInterceptor(new ValidationExtension());
try {
getDs().save(data);
Assert.fail("Should have failed validation");
} catch (ValidationException exception) {
assertTrue(exception.getMessage().contains("Data.email:not a well-formed email address ('not an email')"));
}
data.email = "foo@bar.com";
getDs().save(data);
}
use of jakarta.validation.ValidationException in project hibernate-validator by hibernate.
the class InvalidConfiguredClassInheritanceMethodValidationTest method testInvalidConfigurationThrowsException.
@Test
public void testInvalidConfigurationThrowsException() {
ValidationExtension extension = beanManager.getExtension(ValidationExtension.class);
AnnotatedType<CIA> annotatedType = beanManager.createAnnotatedType(CIA.class);
try {
extension.processAnnotatedType(new ProcessAnnotatedTypeImpl<CIA>(annotatedType));
fail("ValidationExtension should throw an exception, because the validated method overrides another " + "method and adds @ValidateOnExecution ");
} catch (ValidationException e) {
assertThat(e.getMessage()).startsWith("HV000166");
}
}
use of jakarta.validation.ValidationException in project hibernate-validator by hibernate.
the class PredefinedScopeValidatorFactoryTest method validatorSpecificTraversableResolver.
@Test
public void validatorSpecificTraversableResolver() {
Set<Class<?>> beanMetaDataToInitialize = new HashSet<>();
beanMetaDataToInitialize.add(Bean.class);
beanMetaDataToInitialize.add(AnotherBean.class);
beanMetaDataToInitialize.add(SomeEnum.class);
ValidatorFactory validatorFactory = Validation.byProvider(PredefinedScopeHibernateValidator.class).configure().builtinConstraints(new HashSet<>(Arrays.asList(Email.class.getName(), NotNull.class.getName()))).initializeBeanMetaData(beanMetaDataToInitialize).buildValidatorFactory();
try {
Validator validator = validatorFactory.usingContext().traversableResolver(new ThrowExceptionTraversableResolver()).getValidator();
validator.validate(new Bean());
fail();
} catch (ValidationException e) {
Assertions.assertThat(e).hasCauseExactlyInstanceOf(ValidatorSpecificTraversableResolverUsedException.class);
}
}
Aggregations