use of jakarta.validation.constraints.AssertTrue 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.AssertTrue in project eclipselink by eclipse-ee4j.
the class BeanValidationBindingsTestCase method testFacetCustomizationsAndCustomFacets.
/**
* Tests customizations, i.e. facet customizations + custom facets, i.e.
* Future, Past, AssertTrue, AssertFalse.
*/
public void testFacetCustomizationsAndCustomFacets() throws Throwable {
pkg = "cs";
xjcGenerateJavaSourcesWithCustomizations(CUSTOMIZED_SCHEMA_PATH);
compileGeneratedSources(createCompileList(pkg));
Class<?> custom = loadCompiledClasses(createLoadList(pkg))[0];
Field generic = custom.getDeclaredField("generic");
Size s = generic.getAnnotation(Size.class);
assertEquals(s.message(), "Hello, world!");
assertEquals(s.groups()[0], BindingTeam.class);
assertEquals(s.groups()[1], RocketTeam.class);
assertEquals(s.max(), 4);
Pattern p1 = generic.getAnnotation(Pattern.List.class).value()[0];
Pattern p2 = generic.getAnnotation(Pattern.List.class).value()[1];
assertEquals(p1.message(), p2.message());
assertTrue(Arrays.equals(p1.groups(), p2.groups()));
assertEquals(p1.message(), "Hello.");
assertEquals(p1.groups()[0], Object.class);
assertEquals(p1.regexp(), "10");
Future f = generic.getAnnotation(Future.class);
assertEquals(f.message(), "Welcome to the Future!");
assertEquals(f.groups()[0], BindingTeam.class);
Past p = generic.getAnnotation(Past.class);
assertEquals(p.message(), "Farewell from the ancestors.");
assertEquals(p.groups()[0], Ancestors.class);
AssertTrue at = generic.getAnnotation(AssertTrue.class);
assertEquals(at.message(), "True fan of the team!");
assertEquals(at.groups()[0], BindingTeam.class);
AssertFalse af = generic.getAnnotation(AssertFalse.class);
assertEquals(af.message(), "false");
assertEquals(af.groups()[0], Object.class);
// To test a user custom annotation.
CustomAnnotation xmlKey = generic.getAnnotation(CustomAnnotation.class);
assertNotNull(xmlKey);
}
Aggregations