@Test void testValidateNullableExpressionConstraint() { String attributeName = "attr"; Attribute attribute = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock(); when(attribute.getName()).thenReturn(attributeName); String expression = "MyExpression"; when(attribute.getNullableExpression()).thenReturn(expression); EntityType entityType = when(mock(EntityType.class).getAtomicAttributes()) .thenReturn(singletonList(attribute)) .getMock(); Entity entity = when(mock(Entity.class).getEntityType()).thenReturn(entityType).getMock(); Errors errors = mock(Errors.class); entityValidator.validate(entity, errors); verify(errors) .rejectValue( attributeName, "constraints.NullableExpression", new Object[] {expression}, null); }
private void validateNullableExpressionConstraint( Entity entity, Attribute attribute, Errors errors) { String nullableExpression = attribute.getNullableExpression(); if (nullableExpression == null) { return; } boolean valid = expressionValidator.resolveBooleanExpression(nullableExpression, entity); if (!valid) { errors.rejectValue( attribute.getName(), ERROR_CODE_NULLABLE_EXPRESSION, new Object[] {nullableExpression}, null); } }
EntityValidator implements Validator { private void validateNullableExpressionConstraint( Entity entity, Attribute attribute, Errors errors) { String nullableExpression = attribute.getNullableExpression(); if (nullableExpression == null) { return; } boolean valid = expressionValidator.resolveBooleanExpression(nullableExpression, entity); if (!valid) { errors.rejectValue( attribute.getName(), ERROR_CODE_NULLABLE_EXPRESSION, new Object[] {nullableExpression}, null); } } }
EntityValidator implements Validator { private void validateNullableExpressionConstraint( Entity entity, Attribute attribute, Errors errors) { String nullableExpression = attribute.getNullableExpression(); if (nullableExpression == null) { return; } boolean valid = expressionValidator.resolveBooleanExpression(nullableExpression, entity); if (!valid) { errors.rejectValue( attribute.getName(), ERROR_CODE_NULLABLE_EXPRESSION, new Object[] {nullableExpression}, null); } } EntityValidator(ExpressionValidator expressionValidator); }
EntityValidator implements Validator { private void validateNullableExpressionConstraint( Entity entity, Attribute attribute, Errors errors) { String nullableExpression = attribute.getNullableExpression(); if (nullableExpression == null) { return; } boolean valid = expressionValidator.resolveBooleanExpression(nullableExpression, entity); if (!valid) { errors.rejectValue( attribute.getName(), ERROR_CODE_NULLABLE_EXPRESSION, new Object[] {nullableExpression}, null); } } EntityValidator(ExpressionValidator expressionValidator); @Override boolean supports(@Nonnull Class<?> clazz); @Override void validate(@Nonnull Object target, @Nonnull Errors errors); }
EntityValidator implements Validator { private void validateNullableExpressionConstraint( Entity entity, Attribute attribute, Errors errors) { String nullableExpression = attribute.getNullableExpression(); if (nullableExpression == null) { return; } boolean valid = expressionValidator.resolveBooleanExpression(nullableExpression, entity); if (!valid) { errors.rejectValue( attribute.getName(), ERROR_CODE_NULLABLE_EXPRESSION, new Object[] {nullableExpression}, null); } } EntityValidator(ExpressionValidator expressionValidator); @Override boolean supports(@Nonnull Class<?> clazz); @Override void validate(@Nonnull Object target, @Nonnull Errors errors);  }