use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testFindAllStreamFetch.
@SuppressWarnings("unchecked")
@Test
public void testFindAllStreamFetch() {
Object entityId = "entityId";
Entity entity = getEntityMock();
Fetch fetch = mock(Fetch.class);
when(delegateRepository.findAll(any(Stream.class), eq(fetch))).thenAnswer(invocation -> Stream.of(entity));
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
assertEquals(rowLevelSecurityRepositoryDecorator.findAll(Stream.of(entityId), fetch).collect(toList()), singletonList(entity));
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testFindAllQuery.
@Test
public void testFindAllQuery() {
@SuppressWarnings("unchecked") Query<Entity> query = mock(Query.class);
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), READ)).thenReturn(true);
assertEquals(rowLevelSecurityRepositoryDecorator.findAll(query).collect(toList()), singletonList(entity));
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testForEachBatched.
@SuppressWarnings("unchecked")
@Test
public void testForEachBatched() {
Entity entity = getEntityMock();
Fetch fetch = mock(Fetch.class);
List<Entity> actualEntities = new ArrayList<>();
doAnswer(invocation -> {
((Consumer<List<Entity>>) invocation.getArgument(1)).accept(singletonList(entity));
return null;
}).when(delegateRepository).forEachBatched(eq(fetch), any(), eq(1000));
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
rowLevelSecurityRepositoryDecorator.forEachBatched(fetch, actualEntities::addAll, 1000);
assertEquals(actualEntities, singletonList(entity));
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecorator method deleteAcl.
@Override
public void deleteAcl(Entity entity) {
EntityIdentity entityIdentity = new EntityIdentity(entity);
deleteAcl(entityIdentity);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class PermissionManagerControllerTest method testUpdateEntityClassRlsEnableRls.
@Test
public void testUpdateEntityClassRlsEnableRls() {
String entityTypeId = "entityTypeId";
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
Attribute idAttribute = when(mock(Attribute.class).getDataType()).thenReturn(LONG).getMock();
when(entityType.getIdAttribute()).thenReturn(idAttribute);
when(dataService.getEntityType(entityTypeId)).thenReturn(entityType);
Entity entity = when(mock(Entity.class).getEntityType()).thenReturn(entityType).getMock();
when(entity.getIdValue()).thenReturn("entityId");
when(dataService.findAll(entityTypeId)).thenReturn(Stream.of(entity));
EntityTypeRlsRequest entityTypeRlsRequest = new EntityTypeRlsRequest(entityTypeId, true);
permissionManagerController.updateEntityClassRls(entityTypeRlsRequest);
verify(mutableAclClassService).createAclClass("entity-entityTypeId", Long.class);
verify(mutableAclService).createAcl(new EntityIdentity(entity));
}
Aggregations