Search in sources :

Example 16 with Fetch

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

the class InMemoryRepositoryTest method findOneObjectFetchEntityNull.

@Test
public void findOneObjectFetchEntityNull() throws IOException {
    String idAttrName = "id";
    EntityType entityType = mock(EntityType.class);
    Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn(idAttrName).getMock();
    when(entityType.getIdAttribute()).thenReturn(idAttr);
    try (InMemoryRepository inMemoryRepository = new InMemoryRepository(entityType)) {
        Object id = 0;
        Fetch fetch = new Fetch();
        assertNull(inMemoryRepository.findOneById(id, fetch));
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Fetch(org.molgenis.data.Fetch) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Example 17 with Fetch

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

the class InMemoryRepositoryTest method findAllStreamFetch.

@Test
public void findAllStreamFetch() throws IOException {
    String idAttrName = "id";
    EntityType entityType = mock(EntityType.class);
    Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn(idAttrName).getMock();
    when(entityType.getIdAttribute()).thenReturn(idAttr);
    try (InMemoryRepository inMemoryRepository = new InMemoryRepository(entityType)) {
        Object id0 = 0;
        Entity entity0 = when(mock(Entity.class).get(idAttrName)).thenReturn(id0).getMock();
        Object id1 = 1;
        Entity entity1 = when(mock(Entity.class).get(idAttrName)).thenReturn(id1).getMock();
        inMemoryRepository.add(entity0);
        inMemoryRepository.add(entity1);
        Fetch fetch = new Fetch();
        List<Entity> entities = inMemoryRepository.findAll(Stream.of(id0, id1, "bogus"), fetch).collect(Collectors.toList());
        assertEquals(Lists.newArrayList(entities), Arrays.asList(entity0, entity1));
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Fetch(org.molgenis.data.Fetch) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Example 18 with Fetch

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

the class PartialEntityTest method setUpBeforeMethod.

@BeforeMethod
public void setUpBeforeMethod() {
    Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn("id").getMock();
    meta = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    when(meta.getIdAttribute()).thenReturn(idAttr);
    originalEntity = mock(Entity.class);
    decoratedEntity = mock(Entity.class);
    when(decoratedEntity.getEntityType()).thenReturn(meta);
    when(decoratedEntity.getIdValue()).thenReturn("id");
    fetch = new Fetch().field("id");
    entityManager = mock(EntityManager.class);
    when(entityManager.getReference(meta, "id")).thenReturn(originalEntity);
    partialEntity = new PartialEntity(decoratedEntity, fetch, entityManager);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Fetch(org.molgenis.data.Fetch) Entity(org.molgenis.data.Entity) EntityManager(org.molgenis.data.EntityManager) Attribute(org.molgenis.data.meta.model.Attribute) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 19 with Fetch

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

the class TransactionalRepositoryDecoratorTest method findOneByIdFetch.

@Test
public void findOneByIdFetch() throws Exception {
    Object id = mock(Object.class);
    Fetch fetch = mock(Fetch.class);
    transactionalRepo.findOneById(id, fetch);
    verify(transactionManager).getTransaction(any(TransactionDefinition.class));
    verify(delegateRepository).findOneById(id, fetch);
}
Also used : Fetch(org.molgenis.data.Fetch) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Test(org.testng.annotations.Test)

Example 20 with Fetch

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

the class EntityTypeUtilsTest method testCreateFetchForReindexingIndexingDepth0.

@Test
public void testCreateFetchForReindexingIndexingDepth0() {
    EntityType entityType = createMockEntityType();
    when(entityType.getIndexingDepth()).thenReturn(0);
    Fetch expectedFetch = new Fetch().field("MyEntityTypeAttr").field("MyEntityTypeRefAttr");
    assertEquals(EntityTypeUtils.createFetchForReindexing(entityType), expectedFetch);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test)

Aggregations

Fetch (org.molgenis.data.Fetch)36 Test (org.testng.annotations.Test)28 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)12 EntityType (org.molgenis.data.meta.model.EntityType)10 Entity (org.molgenis.data.Entity)9 Attribute (org.molgenis.data.meta.model.Attribute)7 List (java.util.List)3 Query (org.molgenis.data.Query)3 TransactionDefinition (org.springframework.transaction.TransactionDefinition)3 ConstraintViolation (org.molgenis.data.validation.ConstraintViolation)2 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)2 Stopwatch (com.google.common.base.Stopwatch)1 Stopwatch.createStarted (com.google.common.base.Stopwatch.createStarted)1 CacheLoader (com.google.common.cache.CacheLoader)1 com.google.common.collect (com.google.common.collect)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 String.format (java.lang.String.format)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1