@Test void validateAttributeInvalidName() { Attribute attr = makeMockAttribute("invalid.name"); @SuppressWarnings("deprecation") Exception exception = assertThrows( MolgenisValidationException.class, () -> attributeValidator.validate(attr, ADD)); assertThat(exception.getMessage()) .containsPattern( "Invalid characters in: \\[invalid.name\\] Only letters \\(a-z, A-Z\\), digits \\(0-9\\), underscores \\(_\\) and hashes \\(#\\) are allowed."); }
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);  }