I'm adding Java Bean Validation custom constraints and trying to write tests that they get applied by the provider, but I can't figure out how to do that.
I found this post that gives an example of how to test such annotations inside a class and it works for testing the annotations added to predefined model objects.
However, now I also want to test function input annotation and this is where I'm stuck.
Here is an example:
// -- Annotation
@Constraint(validatedBy = IdValidator.class)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Id{...}
// -- Validator
public class IdValidator implements ConstraintValidator<Id, String> {...}
// Now the way it's used (that I'm trying to test) is as follows:
public class MyController {
....
@Requestmapping(....)
@ResponseBody
public Response doStuff(@Id String personId) {....}
}
Is there a way to to write a test to check Validation Provider is able to apply custom validator in this way?