use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-orm by hibernate.
the class TypeSafeActivator method applyMin.
private static void applyMin(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
if (Min.class.equals(descriptor.getAnnotation().annotationType())) {
@SuppressWarnings("unchecked") ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor;
long min = minConstraint.getAnnotation().value();
for (Selectable selectable : property.getSelectables()) {
if (selectable instanceof Column) {
Column col = (Column) selectable;
String checkConstraint = col.getQuotedName(dialect) + ">=" + min;
applySQLCheck(col, checkConstraint);
}
}
}
}
use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-orm by hibernate.
the class TypeSafeActivator method applyMax.
private static void applyMax(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
if (Max.class.equals(descriptor.getAnnotation().annotationType())) {
@SuppressWarnings("unchecked") ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor;
long max = maxConstraint.getAnnotation().value();
for (Selectable selectable : property.getSelectables()) {
if (selectable instanceof Column) {
Column col = (Column) selectable;
String checkConstraint = col.getQuotedName(dialect) + "<=" + max;
applySQLCheck(col, checkConstraint);
}
}
}
}
use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class ParameterTermResolverTest method createHibernateContextWithConstraintDescriptorAttr.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static MessageInterpolator.Context createHibernateContextWithConstraintDescriptorAttr(String attrName, Object attrValue) {
final Map<String, Object> attrs = createConstraintDescriptorAttr(attrName, attrValue);
final HibernateMessageInterpolatorContext context = EasyMock.mock(HibernateMessageInterpolatorContext.class);
final ConstraintDescriptor constraintDescriptor = EasyMock.mock(ConstraintDescriptor.class);
EasyMock.expect(context.getMessageParameters()).andStubReturn(attrs);
EasyMock.expect(context.getConstraintDescriptor()).andStubReturn(constraintDescriptor);
EasyMock.expect(constraintDescriptor.getAttributes()).andStubReturn(attrs);
EasyMock.replay(context);
EasyMock.replay(constraintDescriptor);
return context;
}
use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class XMLConfigurationTest method testXMLCrossParameterConstraints.
@Test
public void testXMLCrossParameterConstraints() {
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(Garage.class);
MethodDescriptor methodDescriptor = beanDescriptor.getConstraintsForMethod("buildCar", java.util.List.class);
CrossParameterDescriptor crossParameterDescriptor = methodDescriptor.getCrossParameterDescriptor();
Set<ConstraintDescriptor<?>> constraintDescriptors = crossParameterDescriptor.getConstraintDescriptors();
assertCorrectConstraintTypes(constraintDescriptors, ELAssert.class);
methodDescriptor = beanDescriptor.getConstraintsForMethod("paintCar", int.class);
ReturnValueDescriptor returnValueDescriptor = methodDescriptor.getReturnValueDescriptor();
constraintDescriptors = returnValueDescriptor.getConstraintDescriptors();
assertCorrectConstraintTypes(constraintDescriptors, ELAssert.class);
}
use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class XMLConfigurationTest method testXMLConstraintsApplied.
@Test
public void testXMLConstraintsApplied() {
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(RentalStation.class);
assertTrue(beanDescriptor.isBeanConstrained());
ConstructorDescriptor constructorDescriptor = beanDescriptor.getConstraintsForConstructor();
ReturnValueDescriptor returnValueDescriptor = constructorDescriptor.getReturnValueDescriptor();
Set<ConstraintDescriptor<?>> constraintDescriptors = returnValueDescriptor.getConstraintDescriptors();
assertCorrectConstraintTypes(constraintDescriptors, ValidRentalStation.class);
constructorDescriptor = beanDescriptor.getConstraintsForConstructor(String.class);
List<ParameterDescriptor> parameterDescriptors = constructorDescriptor.getParameterDescriptors();
constraintDescriptors = parameterDescriptors.get(0).getConstraintDescriptors();
assertCorrectConstraintTypes(constraintDescriptors, NotNull.class);
MethodDescriptor methodDescriptor = beanDescriptor.getConstraintsForMethod("getCustomers");
returnValueDescriptor = methodDescriptor.getReturnValueDescriptor();
constraintDescriptors = returnValueDescriptor.getConstraintDescriptors();
assertCorrectConstraintTypes(constraintDescriptors, NotNull.class, Size.class);
methodDescriptor = beanDescriptor.getConstraintsForMethod("rentCar", Customer.class, Date.class, int.class);
parameterDescriptors = methodDescriptor.getParameterDescriptors();
constraintDescriptors = parameterDescriptors.get(0).getConstraintDescriptors();
assertCorrectConstraintTypes(constraintDescriptors, NotNull.class);
constraintDescriptors = parameterDescriptors.get(1).getConstraintDescriptors();
assertCorrectConstraintTypes(constraintDescriptors, NotNull.class, Future.class);
constraintDescriptors = parameterDescriptors.get(2).getConstraintDescriptors();
assertCorrectConstraintTypes(constraintDescriptors, Min.class);
}
Aggregations