use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testIterator.
@Test
public void testIterator() {
Entity entity = getEntityMock();
when(delegateRepository.iterator()).thenReturn(singletonList(entity).iterator());
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
assertEquals(newArrayList(rowLevelSecurityRepositoryDecorator.iterator()), singletonList(entity));
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testDeleteStream.
@Test
public void testDeleteStream() {
Entity entity = getEntityMock();
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), WRITE)).thenReturn(true);
rowLevelSecurityRepositoryDecorator.delete(Stream.of(entity));
@SuppressWarnings("unchecked") ArgumentCaptor<Stream<Entity>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
verify(delegateRepository).delete(entityStreamCaptor.capture());
assertEquals(entityStreamCaptor.getValue().collect(toList()), singletonList(entity));
verify(mutableAclService).deleteAcl(new EntityIdentity(entity), true);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testDeleteByIdPermissionDenied.
@Test
public void testDeleteByIdPermissionDenied() {
String entityTypeId = "entityTypeId";
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
when(delegateRepository.getEntityType()).thenReturn(entityType);
Object entityId = "entityId";
rowLevelSecurityRepositoryDecorator.deleteById(entityId);
verify(delegateRepository, times(0)).deleteById(entityId);
verify(mutableAclService, times(0)).deleteAcl(new EntityIdentity(entityTypeId, entityId), true);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testFindOneByIdFetch.
@Test
public void testFindOneByIdFetch() {
String entityTypeId = "entityTypeId";
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
when(delegateRepository.getEntityType()).thenReturn(entityType);
Object entityId = "entityId";
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entityTypeId, entityId), READ)).thenReturn(true);
Entity entity = mock(Entity.class);
Fetch fetch = mock(Fetch.class);
when(delegateRepository.findOneById(entityId, fetch)).thenReturn(entity);
assertEquals(rowLevelSecurityRepositoryDecorator.findOneById(entityId, fetch), entity);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testFindOne.
@Test
public void testFindOne() {
@SuppressWarnings("unchecked") Query<Entity> query = mock(Query.class);
Entity entity = getEntityMock();
when(delegateRepository.findOne(query)).thenReturn(entity);
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
assertEquals(entity, rowLevelSecurityRepositoryDecorator.findOne(query));
}
Aggregations