use of dev.morphia.validation.ValidationExtension 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 dev.morphia.validation.ValidationExtension 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);
}
Aggregations