use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class EntityTypeRepositorySecurityDecoratorTest method iteratorUser.
@WithMockUser(username = USERNAME)
@Test
public void iteratorUser() {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String entityType1Name = "entity1";
EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
String entityType2Name = "entity2";
EntityType entityType2 = when(mock(EntityType.class).getId()).thenReturn(entityType2Name).getMock();
when(delegateRepository.iterator()).thenReturn(asList(entityType0, entityType1, entityType2).iterator());
doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT);
doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT);
doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType2Name), EntityTypePermission.COUNT);
assertEquals(newArrayList(repo.iterator()), asList(entityType0, entityType2));
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class EntityTypeRepositorySecurityDecoratorTest method findAllIdsFetchUser.
@WithMockUser(username = USERNAME)
@Test
public void findAllIdsFetchUser() {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String entityType1Name = "entity1";
EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
String entityType2Name = "entity2";
EntityType entityType2 = when(mock(EntityType.class).getId()).thenReturn(entityType2Name).getMock();
Stream<Object> ids = Stream.of("entity0", "entity1");
Fetch fetch = mock(Fetch.class);
when(delegateRepository.findAll(ids, fetch)).thenReturn(Stream.of(entityType0, entityType1, entityType2));
doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT);
doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT);
doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType2Name), EntityTypePermission.COUNT);
assertEquals(repo.findAll(ids, fetch).collect(toList()), asList(entityType0, entityType2));
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class EntityTypeRepositorySecurityDecoratorTest method findOneQueryUserPermissionDenied.
@WithMockUser(username = USERNAME)
@Test
public void findOneQueryUserPermissionDenied() {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
@SuppressWarnings("unchecked") Query q = mock(Query.class);
when(delegateRepository.findOne(q)).thenReturn(entityType0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
assertNull(repo.findOne(q));
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testFindOneById.
@Test
public void testFindOneById() {
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);
when(delegateRepository.findOneById(entityId)).thenReturn(entity);
assertEquals(rowLevelSecurityRepositoryDecorator.findOneById(entityId), entity);
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testDeleteAllStreamPermissionDenied.
@Test
public void testDeleteAllStreamPermissionDenied() {
String entityTypeId = "entityTypeId";
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
when(delegateRepository.getEntityType()).thenReturn(entityType);
Object entityId = "entityId";
rowLevelSecurityRepositoryDecorator.deleteAll(Stream.of(entityId));
@SuppressWarnings("unchecked") ArgumentCaptor<Stream<Object>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
verify(delegateRepository).deleteAll(entityStreamCaptor.capture());
assertEquals(entityStreamCaptor.getValue().collect(toList()), emptyList());
verify(mutableAclService, times(0)).deleteAcl(new EntityIdentity(entityTypeId, entityId), true);
}
Aggregations