@Test void testValidateIdValueNull() { Entity entity = mock(Entity.class); when(entity.getLabelValue()).thenReturn("My entity"); EntityType entityType = mock(EntityType.class); when(entityType.getId()).thenReturn("MyEntityTypeId"); Attribute idAttribute = mock(Attribute.class); when(idAttribute.getDataType()).thenReturn(STRING); when(idAttribute.getLabel()).thenReturn("id"); when(entityType.getIdAttribute()).thenReturn(idAttribute); Set<ConstraintViolation> constraintViolations = entityAttributesValidator.validate(entity, entityType); assertEquals( singleton( new ConstraintViolation( "Invalid [string] value [null] for attribute [id] of entity [My entity] with type [MyEntityTypeId].")), constraintViolations); }
public Set<ConstraintViolation> validate(Entity entity, EntityType meta) { Set<ConstraintViolation> violations = checkNullableExpressions(entity, meta); violations.addAll(checkValidationExpressions(entity, meta)); stream(meta.getAtomicAttributes()) .filter(this::isValidationAttribute) .forEach(attr -> validateAttribute(entity, meta, attr).ifPresent(violations::add)); if (entity.getIdValue() == null) { violations.add(createConstraintViolation(entity, meta.getIdAttribute(), meta, null)); } return violations; }
EntityAttributesValidator { public Set<ConstraintViolation> validate(Entity entity, EntityType meta) { Set<ConstraintViolation> violations = checkNullableExpressions(entity, meta); violations.addAll(checkValidationExpressions(entity, meta)); stream(meta.getAtomicAttributes()) .filter(this::isValidationAttribute) .forEach(attr -> validateAttribute(entity, meta, attr).ifPresent(violations::add)); if (entity.getIdValue() == null) { violations.add(createConstraintViolation(entity, meta.getIdAttribute(), meta, null)); } return violations; } }
EntityAttributesValidator { public Set<ConstraintViolation> validate(Entity entity, EntityType meta) { Set<ConstraintViolation> violations = checkNullableExpressions(entity, meta); violations.addAll(checkValidationExpressions(entity, meta)); stream(meta.getAtomicAttributes()) .filter(this::isValidationAttribute) .forEach(attr -> validateAttribute(entity, meta, attr).ifPresent(violations::add)); if (entity.getIdValue() == null) { violations.add(createConstraintViolation(entity, meta.getIdAttribute(), meta, null)); } return violations; } EntityAttributesValidator(ExpressionValidator expressionValidator); }
EntityAttributesValidator { public Set<ConstraintViolation> validate(Entity entity, EntityType meta) { Set<ConstraintViolation> violations = checkNullableExpressions(entity, meta); violations.addAll(checkValidationExpressions(entity, meta)); stream(meta.getAtomicAttributes()) .filter(this::isValidationAttribute) .forEach(attr -> validateAttribute(entity, meta, attr).ifPresent(violations::add)); if (entity.getIdValue() == null) { violations.add(createConstraintViolation(entity, meta.getIdAttribute(), meta, null)); } return violations; } EntityAttributesValidator(ExpressionValidator expressionValidator); Set<ConstraintViolation> validate(Entity entity, EntityType meta); }
EntityAttributesValidator { public Set<ConstraintViolation> validate(Entity entity, EntityType meta) { Set<ConstraintViolation> violations = checkNullableExpressions(entity, meta); violations.addAll(checkValidationExpressions(entity, meta)); stream(meta.getAtomicAttributes()) .filter(this::isValidationAttribute) .forEach(attr -> validateAttribute(entity, meta, attr).ifPresent(violations::add)); if (entity.getIdValue() == null) { violations.add(createConstraintViolation(entity, meta.getIdAttribute(), meta, null)); } return violations; } EntityAttributesValidator(ExpressionValidator expressionValidator); Set<ConstraintViolation> validate(Entity entity, EntityType meta);  }