use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositoryValidationDecoratorTest method testDeleteAllValid.
@Test
public void testDeleteAllValid() throws Exception {
Package package_ = mock(Package.class);
when(delegateRepository.iterator()).thenReturn(singletonList(package_).iterator());
packageRepositoryValidationDecorator.deleteAll();
verify(packageValidator).validate(package_);
verify(delegateRepository).deleteAll();
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositoryValidationDecoratorTest method testDeleteValid.
@Test
public void testDeleteValid() throws Exception {
Package package_ = mock(Package.class);
packageRepositoryValidationDecorator.delete(package_);
verify(packageValidator).validate(package_);
verify(delegateRepository).delete(package_);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositoryValidationDecoratorTest method testUpdateInvalid.
@Test(expectedExceptions = MolgenisValidationException.class)
public void testUpdateInvalid() throws Exception {
Package package_ = mock(Package.class);
doThrow(mock(MolgenisValidationException.class)).when(packageValidator).validate(package_);
packageRepositoryValidationDecorator.update(package_);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageValidatorTest method testValidatePackageValidNameNoParent.
@Test
public void testValidatePackageValidNameNoParent() throws Exception {
Package package_ = when(mock(Package.class).getId()).thenReturn("myPackage").getMock();
when(package_.getParent()).thenReturn(null);
packageValidator.validate(package_);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class EntityTypeValidator method validateOwnAttributes.
/**
* Validates the attributes owned by this entity:
* 1) validates that the parent entity doesn't have attributes with the same name
* 2) validates that this entity doesn't have attributes with the same name
* 3) validates that this entity has attributes defined at all
*
* @param entityType entity meta data
* @throws MolgenisValidationException if an attribute is owned by another entity or a parent attribute has the same name
*/
private static void validateOwnAttributes(EntityType entityType) {
// Validate that entity has attributes
if (asStream(entityType.getAllAttributes()).collect(toList()).isEmpty()) {
throw new MolgenisValidationException(new ConstraintViolation(format("Entity [%s] does not contain any attributes. Did you use the correct package+entity name combination in both the entities as well as the attributes sheet?", entityType.getId())));
}
// Validate that entity does not contain multiple attributes with the same name
Multimap<String, Attribute> attrMultiMap = asStream(entityType.getAllAttributes()).collect(MultimapCollectors.toArrayListMultimap(Attribute::getName, Function.identity()));
attrMultiMap.keySet().forEach(attrName -> {
if (attrMultiMap.get(attrName).size() > 1) {
throw new MolgenisValidationException(new ConstraintViolation(format("Entity [%s] contains multiple attributes with name [%s]", entityType.getId(), attrName)));
}
});
// Validate that entity attributes with same name do no exist in parent entity
EntityType extendsEntityType = entityType.getExtends();
if (extendsEntityType != null) {
Map<String, Attribute> extendsAllAttrMap = stream(extendsEntityType.getAllAttributes().spliterator(), false).collect(toMap(Attribute::getName, Function.identity(), (u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
}, LinkedHashMap::new));
entityType.getOwnAllAttributes().forEach(attr -> {
if (extendsAllAttrMap.containsKey(attr.getName())) {
throw new MolgenisValidationException(new ConstraintViolation(format("An attribute with name [%s] already exists in entity [%s] or one of its parents", attr.getName(), extendsEntityType.getId())));
}
});
}
}
Aggregations