use of org.molgenis.data.meta.model.EntityType 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.EntityType 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));
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method countQueryUser.
@WithMockUser(username = USERNAME)
@Test
public void countQueryUser() throws Exception {
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 attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attr1Name = "entity1attr0";
Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn(attr1Name).getMock();
when(attr1.getEntity()).thenReturn(entityType1);
Query<Attribute> q = new QueryImpl<>();
@SuppressWarnings("unchecked") ArgumentCaptor<Query<Attribute>> queryCaptor = forClass(Query.class);
when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(attr0, attr1));
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.count(q), 1L);
assertEquals(queryCaptor.getValue().getOffset(), 0);
assertEquals(queryCaptor.getValue().getPageSize(), Integer.MAX_VALUE);
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method forEachBatchedUser.
@WithMockUser(username = USERNAME)
@Test
public void forEachBatchedUser() throws Exception {
List<Attribute> attributes = newArrayList();
Attribute attribute1 = mock(Attribute.class);
Attribute attribute2 = mock(Attribute.class);
Attribute attribute3 = mock(Attribute.class);
Attribute attribute4 = mock(Attribute.class);
EntityType entityType1 = mock(EntityType.class);
EntityType entityType2 = mock(EntityType.class);
EntityType entityType3 = mock(EntityType.class);
EntityType entityType4 = mock(EntityType.class);
when(attribute1.getEntity()).thenReturn(entityType1);
when(attribute2.getEntity()).thenReturn(entityType2);
when(attribute3.getEntity()).thenReturn(entityType3);
when(attribute4.getEntity()).thenReturn(entityType4);
when(entityType1.getId()).thenReturn("EntityType1");
when(entityType2.getId()).thenReturn("EntityType2");
when(entityType3.getId()).thenReturn("EntityType3");
when(entityType4.getId()).thenReturn("EntityType4");
repo.forEachBatched(attributes::addAll, 2);
when(permissionService.hasPermission(new EntityTypeIdentity("EntityType1"), EntityTypePermission.COUNT)).thenReturn(true);
when(permissionService.hasPermission(new EntityTypeIdentity("EntityType2"), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity("EntityType3"), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity("EntityType4"), EntityTypePermission.COUNT)).thenReturn(true);
// Decorated repo returns two batches of two entityTypes
verify(delegateRepository).forEachBatched(eq(null), consumerCaptor.capture(), eq(2));
consumerCaptor.getValue().accept(Lists.newArrayList(attribute1, attribute2));
consumerCaptor.getValue().accept(Lists.newArrayList(attribute3, attribute4));
assertEquals(attributes, newArrayList(attribute1, attribute4));
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method countUser.
@WithMockUser(username = USERNAME)
@Test
public void countUser() throws Exception {
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 attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attr1Name = "entity1attr0";
Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn(attr1Name).getMock();
when(attr1.getEntity()).thenReturn(entityType1);
when(delegateRepository.spliterator()).thenReturn(asList(attr0, attr1).spliterator());
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.count(), 1L);
}
Aggregations