Search in sources :

Example 1 with Engine

use of org.hibernate.validator.test.internal.metadata.Engine in project hibernate-validator by hibernate.

the class ConstraintHelperTest method testGetConstraintsFromMultiValueConstraint.

@Test
public void testGetConstraintsFromMultiValueConstraint() throws Exception {
    Engine engine = new Engine();
    Field field = engine.getClass().getDeclaredField("serialNumber");
    Annotation annotation = field.getAnnotation(Pattern.List.class);
    assertNotNull(annotation);
    List<Annotation> multiValueConstraintAnnotations = constraintHelper.getConstraintsFromMultiValueConstraint(annotation);
    assertTrue(multiValueConstraintAnnotations.size() == 2, "There should be two constraint annotations");
    assertTrue(multiValueConstraintAnnotations.get(0) instanceof Pattern, "Wrong constraint annotation");
    assertEquals(((Pattern) multiValueConstraintAnnotations.get(0)).regexp(), "^[A-Z0-9-]+$");
    assertTrue(multiValueConstraintAnnotations.get(1) instanceof Pattern, "Wrong constraint annotation");
    assertEquals(((Pattern) multiValueConstraintAnnotations.get(1)).regexp(), "^....-....-....$");
}
Also used : Field(java.lang.reflect.Field) Pattern(jakarta.validation.constraints.Pattern) Engine(org.hibernate.validator.test.internal.metadata.Engine) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test)

Aggregations

Pattern (jakarta.validation.constraints.Pattern)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 Engine (org.hibernate.validator.test.internal.metadata.Engine)1 Test (org.testng.annotations.Test)1