use of org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext in project fess by codelibs.
the class CustomSizeValidator method isValid.
@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {
if (value == null) {
return true;
}
final HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
hibernateContext.disableDefaultConstraintViolation();
hibernateContext.addExpressionVariable("min", min).addExpressionVariable("max", max).buildConstraintViolationWithTemplate(message).addConstraintViolation();
final int length = value.length();
return length >= min && length <= max;
}
use of org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext in project syndesis by syndesisio.
the class UniquePropertyValidatorTest method shouldAscertainPropertyUniqueness.
@Test
public void shouldAscertainPropertyUniqueness() {
final HibernateConstraintValidatorContext context = mock(HibernateConstraintValidatorContext.class);
when(context.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(context);
when(context.addExpressionVariable(eq("nonUnique"), anyString())).thenReturn(context);
when(context.getDefaultConstraintMessageTemplate()).thenReturn("template");
final ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
when(context.buildConstraintViolationWithTemplate("template")).thenReturn(builder);
when(builder.addPropertyNode(anyString())).thenReturn(mock(NodeBuilderCustomizableContext.class));
assertThat(validator.isValid(connection, context)).isEqualTo(validity);
}
Aggregations