use of jakarta.validation.constraints.Max in project minijax by minijax.
the class MinijaxConstraintDescriptor method build.
@SuppressWarnings("unchecked")
public static <T extends Annotation> MinijaxConstraintDescriptor<T> build(final AnnotatedType annotatedType, final T annotation) {
final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class);
if (constraint == null) {
return null;
}
final Class<?> valueClass = ReflectionUtils.getRawType(annotatedType);
final Class<?> annotationClass = annotation.annotationType();
if (constraint.validatedBy().length > 0) {
return buildDeclaredValidator(annotation, constraint.validatedBy()[0]);
} else if (annotationClass == AssertFalse.class) {
return (MinijaxConstraintDescriptor<T>) buildAssertFalseValidator((AssertFalse) annotation, valueClass);
} else if (annotationClass == AssertTrue.class) {
return (MinijaxConstraintDescriptor<T>) buildAssertTrueValidator((AssertTrue) annotation, valueClass);
} else if (annotationClass == Max.class) {
return (MinijaxConstraintDescriptor<T>) buildMaxValidator((Max) annotation, valueClass);
} else if (annotationClass == Min.class) {
return (MinijaxConstraintDescriptor<T>) buildMinValidator((Min) annotation, valueClass);
} else if (annotationClass == NotBlank.class) {
return (MinijaxConstraintDescriptor<T>) buildNotBlankValidator((NotBlank) annotation, valueClass);
} else if (annotationClass == NotEmpty.class) {
return (MinijaxConstraintDescriptor<T>) buildNotEmptyValidator((NotEmpty) annotation, valueClass);
} else if (annotationClass == NotNull.class) {
return (MinijaxConstraintDescriptor<T>) buildNotNullValidator((NotNull) annotation);
} else if (annotationClass == Pattern.class) {
return (MinijaxConstraintDescriptor<T>) buildPatternValidator((Pattern) annotation, valueClass);
} else if (annotationClass == Size.class) {
return (MinijaxConstraintDescriptor<T>) buildSizeValidator((Size) annotation, valueClass);
} else {
throw new ValidationException("Unrecognized constraint annotation: " + annotation);
}
}
use of jakarta.validation.constraints.Max in project hibernate-validator by hibernate.
the class ResourceBundleMessageInterpolatorTest method testCorrectMessageInterpolationIfParameterCannotBeReplaced.
@Test
@TestForIssue(jiraKey = "HV-182")
public void testCorrectMessageInterpolationIfParameterCannotBeReplaced() {
ConstraintAnnotationDescriptor.Builder<Max> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(Max.class);
String message = "Message should stay unchanged since {fubar} is not replaceable";
descriptorBuilder.setMessage(message);
descriptorBuilder.setAttribute("value", 10L);
ConstraintAnnotationDescriptor<Max> maxDescriptor = descriptorBuilder.build();
ConstraintDescriptorImpl<Max> constraintDescriptor = new ConstraintDescriptorImpl<Max>(ConstraintHelper.forAllBuiltinConstraints(), null, maxDescriptor, ConstraintLocationKind.FIELD);
interpolator = new ResourceBundleMessageInterpolator(new TestResourceBundleLocator());
MessageInterpolator.Context messageInterpolatorContext = createMessageInterpolatorContext(constraintDescriptor);
String actual = interpolator.interpolate(maxDescriptor.getMessage(), messageInterpolatorContext);
assertEquals(actual, message, "The message should not have changed.");
}
use of jakarta.validation.constraints.Max in project hibernate-validator by hibernate.
the class MaxValidatorForNumberTest method testIsValidMax.
@Test
public void testIsValidMax() {
ConstraintAnnotationDescriptor.Builder<Max> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(Max.class);
descriptorBuilder.setAttribute("value", 15L);
descriptorBuilder.setMessage("{validator.max}");
Max m = descriptorBuilder.build().getAnnotation();
testMax(m, true);
}
use of jakarta.validation.constraints.Max in project hibernate-validator by hibernate.
the class MinMaxValidatorBoundaryTest method testMaxBoundaryValue.
@Test
public void testMaxBoundaryValue() {
Validator validator = ValidatorUtil.getValidator();
this.min = Long.MAX_VALUE;
this.max = 9223372036854775807L;
// Current max value is bigger, should fail, but it doesn't
Set<ConstraintViolation<MinMaxValidatorBoundaryTest>> constraintViolations = validator.validate(this);
assertThat(constraintViolations).containsOnlyViolations(violationOf(Max.class));
}
use of jakarta.validation.constraints.Max 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);
}
}
}
}
Aggregations