Search in sources :

Example 61 with EntityType

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

the class RowLevelSecurityRepositoryDecoratorTest method testUpdateStreamPermissionDenied.

@Test
public void testUpdateStreamPermissionDenied() {
    Entity entity = getEntityMock();
    EntityType entityType = entity.getEntityType();
    when(delegateRepository.getEntityType()).thenReturn(entityType);
    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()), emptyList());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Stream(java.util.stream.Stream) Test(org.testng.annotations.Test)

Example 62 with EntityType

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

the class RowLevelSecurityRepositoryDecoratorTest method getEntityMock.

private Entity getEntityMock() {
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn("entityTypeId");
    Entity entity = mock(Entity.class);
    when(entity.getEntityType()).thenReturn(entityType);
    when(entity.getIdValue()).thenReturn("entityId");
    return entity;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType)

Example 63 with EntityType

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

the class RowLevelSecurityRepositoryDecoratorTest method testDeleteByIdPermissionDenied.

@Test
public void testDeleteByIdPermissionDenied() {
    String entityTypeId = "entityTypeId";
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    when(delegateRepository.getEntityType()).thenReturn(entityType);
    Object entityId = "entityId";
    rowLevelSecurityRepositoryDecorator.deleteById(entityId);
    verify(delegateRepository, times(0)).deleteById(entityId);
    verify(mutableAclService, times(0)).deleteAcl(new EntityIdentity(entityTypeId, entityId), true);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 64 with EntityType

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

the class RowLevelSecurityRepositoryDecoratorTest method testFindOneByIdFetch.

@Test
public void testFindOneByIdFetch() {
    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);
    Fetch fetch = mock(Fetch.class);
    when(delegateRepository.findOneById(entityId, fetch)).thenReturn(entity);
    assertEquals(rowLevelSecurityRepositoryDecorator.findOneById(entityId, fetch), entity);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 65 with EntityType

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

the class RowLevelSecurityRepositoryDecoratorTest method testUpdatePermissionDenied.

@Test(expectedExceptions = MolgenisDataAccessException.class, expectedExceptionsMessageRegExp = "No \\[WRITE\\] permission on entity type \\[test\\] with id \\[entityId\\]")
public void testUpdatePermissionDenied() {
    Entity entity = getEntityMock();
    EntityType entityType = entity.getEntityType();
    when(entityType.getLabel()).thenReturn("test");
    rowLevelSecurityRepositoryDecorator.update(entity);
    verify(delegateRepository, times(0)).update(entity);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) 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