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));
}
}
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));
}
}
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);
}
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);
}
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);
}
Aggregations