@Test void testTemplateExpressionValid() { Attribute attr = makeMockAttribute("name"); when(attr.getExpression()).thenReturn("{template:xref.id}"); when(attr.getDataType()).thenReturn(STRING); attributeValidator.validate(attr, ADD_SKIP_ENTITY_VALIDATION); }
public void validate(Attribute attr, ValidationMode validationMode) { validateName(attr); validateDefaultValue(attr, validationMode == ADD || validationMode == UPDATE); validateParent(attr); validateChildren(attr); validateExpression(attr); switch (validationMode) { case ADD: case ADD_SKIP_ENTITY_VALIDATION: validateAdd(attr); break; case UPDATE: case UPDATE_SKIP_ENTITY_VALIDATION: Attribute currentAttr = dataService.findOneById(ATTRIBUTE_META_DATA, attr.getIdentifier(), Attribute.class); if (currentAttr == null) { throw new UnknownEntityException(ATTRIBUTE_META_DATA, attr.getIdentifier()); } validateUpdate(attr, currentAttr); break; default: throw new UnexpectedEnumException(validationMode); } }
AttributeValidator { public void validate(Attribute attr, ValidationMode validationMode) { validateName(attr); validateDefaultValue(attr, validationMode == ADD || validationMode == UPDATE); validateParent(attr); validateChildren(attr); validateExpression(attr); switch (validationMode) { case ADD: case ADD_SKIP_ENTITY_VALIDATION: validateAdd(attr); break; case UPDATE: case UPDATE_SKIP_ENTITY_VALIDATION: Attribute currentAttr = dataService.findOneById(ATTRIBUTE_META_DATA, attr.getIdentifier(), Attribute.class); if (currentAttr == null) { throw new UnknownEntityException(ATTRIBUTE_META_DATA, attr.getIdentifier()); } validateUpdate(attr, currentAttr); break; default: throw new UnexpectedEnumException(validationMode); } } }
AttributeValidator { public void validate(Attribute attr, ValidationMode validationMode) { validateName(attr); validateDefaultValue(attr, validationMode == ADD || validationMode == UPDATE); validateParent(attr); validateChildren(attr); validateExpression(attr); switch (validationMode) { case ADD: case ADD_SKIP_ENTITY_VALIDATION: validateAdd(attr); break; case UPDATE: case UPDATE_SKIP_ENTITY_VALIDATION: Attribute currentAttr = dataService.findOneById(ATTRIBUTE_META_DATA, attr.getIdentifier(), Attribute.class); if (currentAttr == null) { throw new UnknownEntityException(ATTRIBUTE_META_DATA, attr.getIdentifier()); } validateUpdate(attr, currentAttr); break; default: throw new UnexpectedEnumException(validationMode); } } AttributeValidator(DataService dataService, EntityManager entityManager); }
AttributeValidator { public void validate(Attribute attr, ValidationMode validationMode) { validateName(attr); validateDefaultValue(attr, validationMode == ADD || validationMode == UPDATE); validateParent(attr); validateChildren(attr); validateExpression(attr); switch (validationMode) { case ADD: case ADD_SKIP_ENTITY_VALIDATION: validateAdd(attr); break; case UPDATE: case UPDATE_SKIP_ENTITY_VALIDATION: Attribute currentAttr = dataService.findOneById(ATTRIBUTE_META_DATA, attr.getIdentifier(), Attribute.class); if (currentAttr == null) { throw new UnknownEntityException(ATTRIBUTE_META_DATA, attr.getIdentifier()); } validateUpdate(attr, currentAttr); break; default: throw new UnexpectedEnumException(validationMode); } } AttributeValidator(DataService dataService, EntityManager entityManager); void validate(Attribute attr, ValidationMode validationMode); }
AttributeValidator { public void validate(Attribute attr, ValidationMode validationMode) { validateName(attr); validateDefaultValue(attr, validationMode == ADD || validationMode == UPDATE); validateParent(attr); validateChildren(attr); validateExpression(attr); switch (validationMode) { case ADD: case ADD_SKIP_ENTITY_VALIDATION: validateAdd(attr); break; case UPDATE: case UPDATE_SKIP_ENTITY_VALIDATION: Attribute currentAttr = dataService.findOneById(ATTRIBUTE_META_DATA, attr.getIdentifier(), Attribute.class); if (currentAttr == null) { throw new UnknownEntityException(ATTRIBUTE_META_DATA, attr.getIdentifier()); } validateUpdate(attr, currentAttr); break; default: throw new UnexpectedEnumException(validationMode); } } AttributeValidator(DataService dataService, EntityManager entityManager); void validate(Attribute attr, ValidationMode validationMode);  }