Search in sources :

Example 51 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method countQuery.

@WithMockUser(username = USERNAME)
@Test
public void countQuery() {
    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();
    Query q = new QueryImpl<>();
    @SuppressWarnings("unchecked") ArgumentCaptor<Query> queryCaptor = forClass(Query.class);
    when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(entityType0, entityType1));
    doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT);
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT);
    assertEquals(repo.count(q), 1L);
    assertEquals(queryCaptor.getValue().getOffset(), 0);
    assertEquals(queryCaptor.getValue().getPageSize(), Integer.MAX_VALUE);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) QueryImpl(org.molgenis.data.support.QueryImpl) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 52 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method findOneQueryUserPermissionAllowed.

@WithMockUser(username = USERNAME)
@Test
public void findOneQueryUserPermissionAllowed() {
    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(true);
    assertEquals(repo.findOne(q), entityType0);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 53 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method findOneByIdUserPermissionAllowed.

@WithMockUser(username = USERNAME)
@Test
public void findOneByIdUserPermissionAllowed() {
    String entityType0Name = "entity0";
    EntityType entityType0 = mock(EntityType.class);
    when(delegateRepository.findOneById("entity0")).thenReturn(entityType0);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
    assertEquals(repo.findOneById("entity0"), entityType0);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 54 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method findAllQueryUserOffsetLimit.

@WithMockUser(username = USERNAME)
@Test
public void findAllQueryUserOffsetLimit() {
    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();
    @SuppressWarnings("unchecked") Query q = mock(Query.class);
    when(q.getOffset()).thenReturn(1);
    when(q.getPageSize()).thenReturn(1);
    @SuppressWarnings("unchecked") ArgumentCaptor<Query<EntityType>> queryCaptor = forClass(Query.class);
    when(delegateRepository.findAll(queryCaptor.capture())).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(q).collect(toList()), singletonList(entityType2));
    Query<EntityType> decoratedQ = queryCaptor.getValue();
    assertEquals(decoratedQ.getOffset(), 0);
    assertEquals(decoratedQ.getPageSize(), Integer.MAX_VALUE);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 55 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method delete.

@WithMockUser(username = USERNAME)
@Test
public void delete() {
    String entityTypeId = "entityTypeId";
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)).thenReturn(true);
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn("entityTypeId").getMock();
    repo.delete(entityType);
    verify(mutableAclService).deleteAcl(new EntityTypeIdentity(entityTypeId), true);
    verify(mutableAclClassService).deleteAclClass("entity-" + entityTypeId);
    verify(delegateRepository).delete(entityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Aggregations

EntityType (org.molgenis.data.meta.model.EntityType)581 Test (org.testng.annotations.Test)367 Attribute (org.molgenis.data.meta.model.Attribute)315 Entity (org.molgenis.data.Entity)98 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)71 DynamicEntity (org.molgenis.data.support.DynamicEntity)61 Stream (java.util.stream.Stream)44 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)43 WithMockUser (org.springframework.security.test.context.support.WithMockUser)40 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)36 QueryImpl (org.molgenis.data.support.QueryImpl)33 Package (org.molgenis.data.meta.model.Package)32 Objects.requireNonNull (java.util.Objects.requireNonNull)22 Collectors.toList (java.util.stream.Collectors.toList)22 BeforeMethod (org.testng.annotations.BeforeMethod)20 AttributeType (org.molgenis.data.meta.AttributeType)19 List (java.util.List)17 String.format (java.lang.String.format)16 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)16 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)15