@Override public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups) { Assert.state(this.targetValidator != null, "No target Validator set"); return this.targetValidator.validateProperty(object, propertyName, groups); }
@Override public <T> Set<ConstraintViolation<T>> validateProperty(T t, String s, Class<?>... classes) { return validator.validateProperty(t, s, classes); }
@Override public <T> Set<ConstraintViolation<T>> validateProperty(final T object, final String propertyName, final Class<?>... groups) { return delegate.validateProperty(object, propertyName, groups); }
@Override public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups) { Assert.state(this.targetValidator != null, "No target Validator set"); return this.targetValidator.validateProperty(object, propertyName, groups); }
protected void tryValidate(Object data, String property, Class... groups) { validate(() -> validator.validateProperty(data, property, groups)); }
/** * {@inheritDoc} */ public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups) { return validator.validateProperty(object, propertyName, groups); }
public List<Message> validateProperty(Object bean, String property, Class<?>... groups) { if(bean == null) { logger.warn(SKIP_VALIDATION_INPUT_NULL); return emptyList(); } List<Message> messages = new ArrayList<Message>(); Set<ConstraintViolation<Object>> violations = validator.validateProperty(bean, property, groups); logger.debug(VIOLATIONS_AT_BEAN, violations.size(), bean); messages.addAll(getMessages(violations)); return messages; }
/** * {@inheritDoc} */ public <T> Set<ConstraintViolation<T>> validateProperty(T t, String s, Class<?>... classes) { return getValidator().validateProperty(t, s, classes); }
@Override public FineMessageSet validateProperty(Object object, String propertyName, Class<?>... groups) { Set<ConstraintViolation<Object>> violations = validator.validateProperty(object, propertyName, groups); return newFineMessageSet(violations); }
@SuppressWarnings("unchecked") public void validateProperty( T domainObject, String propertyName, Class<?>... groups) { Set constraintViolations = (Set) validator.validateProperty(domainObject, propertyName, groups); if (constraintViolations != null && constraintViolations.size() > 0) { throw new ValidationException("", constraintViolations); } }
@Test(expectedExceptions = IllegalArgumentException.class) @SpecAssertion(section = Sections.VALIDATIONAPI_VALIDATORAPI_VALIDATIONMETHODS, id = "e") public void testPassingNullAsGroup() { Customer customer = new Customer(); getValidator().validateProperty( customer, "firstName", (Class<?>) null ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_REQUIREMENTS, id = "d") public void testGetterMethod() { Shipment shipment = new Shipment(); Set<ConstraintViolation<Shipment>> constraintViolations = getValidator().validateProperty( shipment, "id" ); assertCorrectConstraintTypes( constraintViolations, NotNull.class ); }
@Test @SpecAssertion(section = "3.5.1", id = "c") public void testNullReferencesGetIgnored() { Parent p = new Parent(); Validator validator = TestUtil.getValidatorUnderTest(); Set<ConstraintViolation<Parent>> errors = validator.validateProperty( p, "child" ); assertCorrectNumberOfViolations( errors, 0 ); } }
@Test(expectedExceptions = IllegalArgumentException.class) @SpecAssertion(section = Sections.VALIDATIONAPI_VALIDATORAPI_VALIDATIONMETHODS, id = "e") public void testValidatePropertyWithEmptyProperty() { Customer customer = new Customer(); Order order = new Order(); customer.addOrder( order ); getValidator().validateProperty( customer, "" ); }
@Test @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "a") @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "f") public void testInterpolationWithUnknownElExpression() { Set<ConstraintViolation<TestBean>> violations = getValidator().validateProperty( new TestBean(), "houseNo" ); assertCorrectConstraintViolationMessages( violations, "${unknown}" ); }
@Test @SpecAssertion(section = "4.3.1", id = "d") public void testMessagesCanBeOverriddenAtConstraintLevel() { Validator validator = TestUtil.getValidatorUnderTest(); Set<ConstraintViolation<DummyEntity>> constraintViolations = validator.validateProperty( new DummyEntity(), "snafu" ); assertCorrectNumberOfViolations( constraintViolations, 1 ); assertCorrectConstraintViolationMessages( constraintViolations, "messages can also be overridden at constraint declaration." ); }
@Test @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "a") @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "e") public void testInterpolationUsingFormatterWithSeveralObjectsInElExpression() { Set<ConstraintViolation<TestBean>> violations = getValidator().validateProperty( new TestBean(), "latitude" ); assertCorrectConstraintViolationMessages( violations, "98.12 (that is, 98.1235) must be larger than 100" ); }
@Test @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "a") @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "b") public void testInterpolationWithSeveralElExpressions() { Set<ConstraintViolation<TestBean>> violations = getValidator().validateProperty( new TestBean(), "lastName" ); assertCorrectConstraintViolationMessages( violations, "2 some text 6" ); }
@Test @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "a") @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "c") public void testInterpolationUsingAnnotationAttributesInElExpression() { Set<ConstraintViolation<TestBean>> violations = getValidator().validateProperty( new TestBean(), "street" ); assertCorrectConstraintViolationMessages( violations, "must be longer than 30" ); }
@Test @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION, id = "e") @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "a") @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_DEFAULTMESSAGEINTERPOLATION_EXPRESSIONLANGUAGE, id = "b") public void testInterpolationWithElExpression() { Set<ConstraintViolation<TestBean>> violations = getValidator().validateProperty( new TestBean(), "firstName" ); assertCorrectConstraintViolationMessages( violations, "2" ); }