use of jakarta.validation.ConstraintViolation in project glassfish-hk2 by eclipse-ee4j.
the class ValidationTest method checkMultiException.
private static void checkMultiException(MultiException me, String expectedConstraintMessage) {
ConstraintViolationException found = null;
for (Throwable th : me.getErrors()) {
if (th instanceof ConstraintViolationException) {
found = (ConstraintViolationException) th;
break;
}
}
Assert.assertNotNull(found);
boolean foundMessage = false;
Set<ConstraintViolation<?>> violations = found.getConstraintViolations();
for (ConstraintViolation<?> violation : violations) {
if (expectedConstraintMessage.equals(violation.getMessage())) {
foundMessage = true;
break;
}
}
Assert.assertTrue("Did not find expected exception in " + me + " was looking for " + expectedConstraintMessage, foundMessage);
}
use of jakarta.validation.ConstraintViolation in project glassfish-hk2 by eclipse-ee4j.
the class XmlRootHandleImpl method startValidating.
@Override
public void startValidating() {
if (changeControl == null)
throw new IllegalStateException();
Validator validator = changeControl.findOrCreateValidator();
if (root == null)
return;
Set<ConstraintViolation<Object>> violations = validator.<Object>validate(root);
if (violations == null || violations.isEmpty())
return;
throw new ConstraintViolationException(violations);
}
use of jakarta.validation.ConstraintViolation in project glassfish-hk2 by eclipse-ee4j.
the class DynamicChangeInfo method endOrDeferChange.
/**
* Write lock MUST be held!
*
* @return
*/
public void endOrDeferChange(boolean success) throws MultiException {
changeDepth--;
if (changeDepth < 0)
changeDepth = 0;
if (!success)
globalSuccess = false;
if (changeDepth > 0)
return;
List<BaseHK2JAXBBean> localParticipants = new ArrayList<BaseHK2JAXBBean>(participants);
participants.clear();
XmlDynamicChange localDynamicChange = dynamicChange;
dynamicChange = null;
if (localDynamicChange == null)
return;
ConstraintViolationException validationException = null;
if (globalSuccess && (validator != null) && (root != null) && (root.getRoot() != null)) {
// Validate root if validation is on
Set<ConstraintViolation<Object>> violations = validator.<Object>validate(root.getRoot());
if (violations != null && !violations.isEmpty()) {
validationException = new ConstraintViolationException(violations);
}
}
if (!globalSuccess || (validationException != null)) {
for (BaseHK2JAXBBean participant : localParticipants) {
participant.__rollbackChange();
}
if (validationException != null) {
throw new MultiException(validationException);
}
return;
}
for (BaseHK2JAXBBean participant : localParticipants) {
participant.__activateChange();
}
DynamicConfiguration systemChange = localDynamicChange.getSystemDynamicConfiguration();
WriteableBeanDatabase wbd = localDynamicChange.getBeanDatabase();
if (systemChange == null && wbd != null) {
// Weird case, can it happen?
wbd.commit(new XmlHubCommitMessage() {
});
return;
}
if (systemChange == null)
return;
// Can definitely throw, for example if a listener fails
systemChange.commit();
}
use of jakarta.validation.ConstraintViolation in project today-framework by TAKETODAY.
the class ValidatorFactoryTests method testSimpleValidationWithCustomProvider.
@Test
public void testSimpleValidationWithCustomProvider() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.setProviderClass(HibernateValidator.class);
validator.afterPropertiesSet();
ValidPerson person = new ValidPerson();
Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
assertThat(result.size()).isEqualTo(2);
for (ConstraintViolation<ValidPerson> cv : result) {
String path = cv.getPropertyPath().toString();
assertThat(path).matches(actual -> "name".equals(actual) || "address.street".equals(actual));
assertThat(cv.getConstraintDescriptor().getAnnotation()).isInstanceOf(NotNull.class);
}
Validator nativeValidator = validator.unwrap(Validator.class);
assertThat(nativeValidator.getClass().getName().startsWith("org.hibernate")).isTrue();
assertThat(validator.unwrap(ValidatorFactory.class)).isInstanceOf(HibernateValidatorFactory.class);
assertThat(validator.unwrap(HibernateValidatorFactory.class)).isInstanceOf(HibernateValidatorFactory.class);
validator.destroy();
}
use of jakarta.validation.ConstraintViolation in project mojarra by eclipse-ee4j.
the class WholeBeanValidator method doBeanValidation.
private Set<ConstraintViolation<?>> doBeanValidation(jakarta.validation.Validator beanValidator, Object wholeBeanCopy, Class<?>[] validationGroupArray, ValueExpression wholeBeanVE) {
@SuppressWarnings("rawtypes") Set violationsRaw = null;
try {
violationsRaw = beanValidator.validate(wholeBeanCopy, validationGroupArray);
} catch (IllegalArgumentException iae) {
LOGGER.fine("Unable to validate expression " + wholeBeanVE.getExpressionString() + " using Bean Validation. Unable to get value of expression. " + " Message from Bean Validation: " + iae.getMessage());
}
@SuppressWarnings("unchecked") Set<ConstraintViolation<?>> violations = violationsRaw;
return violations;
}
Aggregations