@Validate("email") public String getEmail() { return email; }
public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider) { Validate annotation = annotationProvider.getAnnotation(Validate.class); if (annotation == null) return null; //TAP5-520: Commas within regular expressions like {n,m} or {n,} or a\,b . //We use Negative Lookahead to avoid matching the case a\,b . //We use Positive Lookahead to avoid matching cases {n,m} and {n,}. //http://www.regular-expressions.info/lookaround.html return Arrays.asList(validatorPattern.split(annotation.value())); }
@Validate("setObjectValue") public void setObjectValue(String objectValue) { this.objectValue = objectValue; }
private Validate newValidate(String value) { Validate annotation = newMock(Validate.class); expect(annotation.value()).andReturn(value).atLeastOnce(); return annotation; } }
@Validate("required,minlength=5") public String getLastName() { return lastName; }
@Test public void field_annotations_are_visible() { PropertyConduit conduit = source.create(CompositeBean.class, "simple.firstName"); Validate annotation = conduit.getAnnotation(Validate.class); assertNotNull(annotation); assertEquals(annotation.value(), "required"); }
@Validate("required") public String getName() { return name; }
@Test public void annotation_from_write_only_property() { TargetBean bean = new TargetBean(); ComponentResources resources = newComponentResources(bean); Location l = mockLocation(); replay(); Binding binding = factory.newBinding("test binding", resources, null, "writeOnly", l); assertEquals(binding.getAnnotation(Validate.class).value(), "writeonly"); verify(); }
@Validate("required") public String getText() { return text; }
@Test public void annotation_from_read_only_property() { TargetBean bean = new TargetBean(); ComponentResources resources = newComponentResources(bean); Location l = mockLocation(); replay(); Binding binding = factory.newBinding("test binding", resources, null, "readOnly", l); assertEquals(binding.getAnnotation(Validate.class).value(), "readonly"); verify(); }
@Validate("required") public String getLastName() { return lastName; }
@Test public void annnotation_on_read_method_takes_precedence_over_write_method() { TargetBean bean = new TargetBean(); ComponentResources resources = newComponentResources(bean); Location l = mockLocation(); replay(); Binding binding = factory.newBinding("test binding", resources, null, "objectValue", l); assertEquals(binding.getAnnotation(Validate.class).value(), "getObjectValue"); verify(); }
@Validate("required") public RoleAccess getRole() { return role; }
@Validate("required,regexp") public String getZipCode() { return zipCode; }
@Validate("required") public void setMessage(String message) { this.message = message; }
@Validate("required") public Date getDate() { return date; }
@Validate("getObjectValue") public String getObjectValue() { return objectValue; }
@Validate("required") public String getTitle() { return title; }
@Validate("required,minlength=3") public void setFirstName(String firstName) { this.firstName = firstName; }
@Validate("required") public String getFirstName() { return firstName; }