use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findOneByIdUserPermissionAllowedAttrInCompoundWithOneAttr.
@WithMockUser(username = USERNAME)
@Test
public void findOneByIdUserPermissionAllowedAttrInCompoundWithOneAttr() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String attr0Name = "entity0attrCompoundattr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attrCompoundName = "entity0attrCompound";
Attribute attrCompound = when(mock(Attribute.class).getName()).thenReturn(attrCompoundName).getMock();
when(attrCompound.getEntity()).thenReturn(entityType0);
Object id = mock(Object.class);
when(delegateRepository.findOneById(id)).thenReturn(attr0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findOneById(id), attr0);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findAllQuerySuOrSystem.
private void findAllQuerySuOrSystem() throws Exception {
Attribute attr0 = mock(Attribute.class);
Attribute attr1 = mock(Attribute.class);
@SuppressWarnings("unchecked") Query<Attribute> q = mock(Query.class);
when(delegateRepository.findAll(q)).thenReturn(Stream.of(attr0, attr1));
assertEquals(repo.findAll(q).collect(toList()), asList(attr0, attr1));
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findOneQueryUserPermissionAllowed.
@WithMockUser(username = USERNAME)
@Test
public void findOneQueryUserPermissionAllowed() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
Query<Attribute> q = new QueryImpl<>();
when(delegateRepository.findOne(q)).thenReturn(attr0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findOne(q), attr0);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method updateSystemEntity.
@WithMockUser(username = USERNAME, roles = { ROLE_SU })
@Test(expectedExceptions = { MolgenisDataException.class }, expectedExceptionsMessageRegExp = "Updating system entity attribute \\[attributeName\\] is not allowed")
public void updateSystemEntity() {
Attribute currentAttribute = mock(Attribute.class);
when(systemEntityTypeRegistry.getSystemAttribute(attributeId)).thenReturn(currentAttribute);
repo.update(attribute);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findOneByIdFetchUserPermissionDenied.
@WithMockUser(username = USERNAME)
@Test
public void findOneByIdFetchUserPermissionDenied() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
Object id = mock(Object.class);
Fetch fetch = mock(Fetch.class);
when(delegateRepository.findOneById(id, fetch)).thenReturn(attr0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
assertNull(repo.findOneById(id, fetch));
}
Aggregations