Search in sources :

Example 6 with EntityManager

use of org.molgenis.data.EntityManager in project molgenis by molgenis.

the class EntityUtilsTest method getTypedValueStringAttributeEntityManagerOneToMany.

@Test
public void getTypedValueStringAttributeEntityManagerOneToMany() {
    String valueStr = "0,1,2";
    Attribute attr = mock(Attribute.class);
    EntityType refEntityType = mock(EntityType.class);
    Attribute refIdAttr = mock(Attribute.class);
    when(refIdAttr.getDataType()).thenReturn(INT);
    when(refEntityType.getIdAttribute()).thenReturn(refIdAttr);
    when(attr.getRefEntity()).thenReturn(refEntityType);
    when(attr.getDataType()).thenReturn(ONE_TO_MANY);
    EntityManager entityManager = mock(EntityManager.class);
    Entity entity0 = mock(Entity.class);
    Entity entity1 = mock(Entity.class);
    Entity entity2 = mock(Entity.class);
    when(entityManager.getReference(refEntityType, 0)).thenReturn(entity0);
    when(entityManager.getReference(refEntityType, 1)).thenReturn(entity1);
    when(entityManager.getReference(refEntityType, 2)).thenReturn(entity2);
    assertEquals(EntityUtils.getTypedValue(valueStr, attr, entityManager), newArrayList(entity0, entity1, entity2));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) EntityManager(org.molgenis.data.EntityManager) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Aggregations

EntityManager (org.molgenis.data.EntityManager)6 Entity (org.molgenis.data.Entity)4 Attribute (org.molgenis.data.meta.model.Attribute)4 EntityType (org.molgenis.data.meta.model.EntityType)4 BeforeMethod (org.testng.annotations.BeforeMethod)3 DataService (org.molgenis.data.DataService)2 DynamicEntity (org.molgenis.data.support.DynamicEntity)2 Test (org.testng.annotations.Test)2 Iterables (com.google.common.collect.Iterables)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 String.format (java.lang.String.format)1 DateTimeParseException (java.time.format.DateTimeParseException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 Fetch (org.molgenis.data.Fetch)1 MolgenisDataException (org.molgenis.data.MolgenisDataException)1