@Test void validateOrderByInvalidRefAttribute() { String entityTypeId = "entityTypeId"; EntityType refEntity = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock(); Attribute attr = makeMockAttribute("attrName"); EntityType entity = mock(EntityType.class); when(entity.getId()).thenReturn("test"); when(attr.getEntityType()).thenReturn(entity); when(attr.getRefEntity()).thenReturn(refEntity); String mappedByAttrName = "mappedByAttrName"; Attribute mappedByAttr = when(mock(Attribute.class).getName()).thenReturn(mappedByAttrName).getMock(); when(mappedByAttr.getDataType()).thenReturn(XREF); when(attr.getMappedBy()).thenReturn(mappedByAttr); when(refEntity.getAttribute(mappedByAttrName)).thenReturn(mappedByAttr); when(attr.getOrderBy()).thenReturn(new Sort("fail", ASC)); @SuppressWarnings("deprecation") Exception exception = assertThrows(MolgenisDataException.class, () -> attributeValidator.validate(attr, ADD)); assertThat(exception.getMessage()) .containsPattern( "Unknown entity \\[entityTypeId\\] attribute \\[fail\\] referred to by entity \\[test\\] attribute \\[attrName\\] sortBy \\[fail,ASC\\]"); }
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);  }