Search in sources :

Example 61 with Attribute

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

the class AttributeRepositorySecurityDecoratorTest method findAllIdsFetchSuOrSystem.

private void findAllIdsFetchSuOrSystem() throws Exception {
    Attribute attr0 = mock(Attribute.class);
    Attribute attr1 = mock(Attribute.class);
    Stream<Object> ids = Stream.of("0", "1");
    Fetch fetch = mock(Fetch.class);
    when(delegateRepository.findAll(ids, fetch)).thenReturn(Stream.of(attr0, attr1));
    assertEquals(repo.findAll(ids, fetch).collect(toList()), asList(attr0, attr1));
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute)

Example 62 with Attribute

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

Example 63 with Attribute

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

the class AttributeRepositorySecurityDecoratorTest method findOneByIdSuOrSystem.

private void findOneByIdSuOrSystem() throws Exception {
    Attribute attr0 = mock(Attribute.class);
    Object id = "0";
    when(delegateRepository.findOneById(id)).thenReturn(attr0);
    assertEquals(repo.findOneById(id), attr0);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute)

Example 64 with Attribute

use of org.molgenis.data.meta.model.Attribute 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));
}
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 65 with Attribute

use of org.molgenis.data.meta.model.Attribute 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);
}
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