Search in sources :

Example 56 with Attribute

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

the class AttributeRepositorySecurityDecoratorTest method findOneByIdUserPermissionAllowedAttrInCompoundWithOneAttr.

@WithMockUser(username = USERNAME)
@Test
public void findOneByIdUserPermissionAllowedAttrInCompoundWithOneAttr() throws Exception {
    String entityType0Name = "entity0";
    EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
    String attr0Name = "entity0attrCompoundattr0";
    Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
    when(attr0.getEntity()).thenReturn(entityType0);
    String attrCompoundName = "entity0attrCompound";
    Attribute attrCompound = when(mock(Attribute.class).getName()).thenReturn(attrCompoundName).getMock();
    when(attrCompound.getEntity()).thenReturn(entityType0);
    Object id = mock(Object.class);
    when(delegateRepository.findOneById(id)).thenReturn(attr0);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
    assertEquals(repo.findOneById(id), attr0);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 57 with Attribute

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

the class AttributeRepositorySecurityDecoratorTest method findAllQuerySuOrSystem.

private void findAllQuerySuOrSystem() throws Exception {
    Attribute attr0 = mock(Attribute.class);
    Attribute attr1 = mock(Attribute.class);
    @SuppressWarnings("unchecked") Query<Attribute> q = mock(Query.class);
    when(delegateRepository.findAll(q)).thenReturn(Stream.of(attr0, attr1));
    assertEquals(repo.findAll(q).collect(toList()), asList(attr0, attr1));
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute)

Example 58 with Attribute

use of org.molgenis.data.meta.model.Attribute 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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 59 with Attribute

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

the class AttributeRepositorySecurityDecoratorTest method updateSystemEntity.

@WithMockUser(username = USERNAME, roles = { ROLE_SU })
@Test(expectedExceptions = { MolgenisDataException.class }, expectedExceptionsMessageRegExp = "Updating system entity attribute \\[attributeName\\] is not allowed")
public void updateSystemEntity() {
    Attribute currentAttribute = mock(Attribute.class);
    when(systemEntityTypeRegistry.getSystemAttribute(attributeId)).thenReturn(currentAttribute);
    repo.update(attribute);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 60 with Attribute

use of org.molgenis.data.meta.model.Attribute 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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)600 Test (org.testng.annotations.Test)351 EntityType (org.molgenis.data.meta.model.EntityType)321 Entity (org.molgenis.data.Entity)109 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)54 DynamicEntity (org.molgenis.data.support.DynamicEntity)53 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)47 Stream (java.util.stream.Stream)39 AttributeType (org.molgenis.data.meta.AttributeType)34 QueryImpl (org.molgenis.data.support.QueryImpl)29 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)29 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)28 BeforeMethod (org.testng.annotations.BeforeMethod)20 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Collectors.toList (java.util.stream.Collectors.toList)17 Relation (org.molgenis.data.semantic.Relation)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 MolgenisDataException (org.molgenis.data.MolgenisDataException)16 Package (org.molgenis.data.meta.model.Package)16