use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testFindAllStream.
@SuppressWarnings("unchecked")
@Test
public void testFindAllStream() {
Object entityId = "entityId";
Entity entity = getEntityMock();
when(delegateRepository.findAll(any(Stream.class))).thenAnswer(invocation -> Stream.of(entity));
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
assertEquals(rowLevelSecurityRepositoryDecorator.findAll(Stream.of(entityId)).collect(toList()), singletonList(entity));
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testCount.
@Test
public void testCount() {
Entity entity = getEntityMock();
when(delegateRepository.findAll(new QueryImpl<>().setOffset(0).setPageSize(Integer.MAX_VALUE))).thenAnswer(invocation -> Stream.of(entity));
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), COUNT)).thenReturn(true);
assertEquals(rowLevelSecurityRepositoryDecorator.count(), 1L);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testDeleteAll.
@Test
public void testDeleteAll() {
Entity entity = getEntityMock();
when(delegateRepository.findAll(new QueryImpl<>().setOffset(0).setPageSize(Integer.MAX_VALUE))).thenAnswer(invocation -> Stream.of(entity));
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), WRITE)).thenReturn(true);
rowLevelSecurityRepositoryDecorator.deleteAll();
@SuppressWarnings("unchecked") ArgumentCaptor<Stream<Entity>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
verify(delegateRepository).delete(entityStreamCaptor.capture());
assertEquals(entityStreamCaptor.getValue().collect(toList()), singletonList(entity));
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testUpdateStream.
@Test
public void testUpdateStream() {
Entity entity = getEntityMock();
EntityType entityType = entity.getEntityType();
when(delegateRepository.getEntityType()).thenReturn(entityType);
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), WRITE)).thenReturn(true);
rowLevelSecurityRepositoryDecorator.update(Stream.of(entity));
@SuppressWarnings("unchecked") ArgumentCaptor<Stream<Entity>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
verify(delegateRepository).update(entityStreamCaptor.capture());
assertEquals(entityStreamCaptor.getValue().collect(toList()), singletonList(entity));
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testDeleteById.
@Test
public void testDeleteById() {
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), WRITE)).thenReturn(true);
rowLevelSecurityRepositoryDecorator.deleteById(entityId);
verify(delegateRepository).deleteById(entityId);
verify(mutableAclService).deleteAcl(new EntityIdentity(entityTypeId, entityId), true);
}
Aggregations