use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class EntityControllerTest method testGetEntity.
@Test
void testGetEntity() {
String entityTypeId = "MyEntityTypeId";
String entityId = "MyId";
Selection filter = Selection.FULL_SELECTION;
Selection expand = Selection.FULL_SELECTION;
ReadEntityRequest entityRequest = new ReadEntityRequest();
entityRequest.setEntityTypeId(entityTypeId);
entityRequest.setEntityId(entityId);
entityRequest.setFilter(filter);
entityRequest.setExpand(expand);
Entity entity = mock(Entity.class);
when(dataServiceV3.find(entityTypeId, entityId, filter, expand)).thenReturn(entity);
EntityResponse entityResponse = mock(EntityResponse.class);
when(entityMapper.map(entity, filter, expand)).thenReturn(entityResponse);
assertEquals(entityResponse, entityController.getEntity(entityRequest));
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class EntityControllerTest method testGetField.
@Test
void testGetField() {
String entityTypeId = "MyEntityTypeId";
String entityId = "EntityId";
String fieldId = "Field";
Selection filter = Selection.FULL_SELECTION;
Selection expand = Selection.FULL_SELECTION;
Query query = Query.builder().setOperator(Operator.MATCHES).setValue("value").build();
Sort sort = Sort.create("field", Direction.ASC);
ReadSubresourceRequest readSubResourceRequest = new ReadSubresourceRequest();
readSubResourceRequest.setEntityTypeId(entityTypeId);
readSubResourceRequest.setEntityId(entityId);
readSubResourceRequest.setFieldId(fieldId);
readSubResourceRequest.setQ(query);
readSubResourceRequest.setSort(sort);
readSubResourceRequest.setFilter(filter);
readSubResourceRequest.setExpand(expand);
readSubResourceRequest.setSize(10);
readSubResourceRequest.setPage(2);
Entities entities = Entities.create(emptyList(), 30);
when(dataServiceV3.findSubresources(entityTypeId, entityId, fieldId, query, filter, expand, sort, 10, 2)).thenReturn(entities);
EntityCollection entityCollection = EntityCollection.builder().setEntityTypeId(entityTypeId).setEntities(emptyList()).setPage(Page.builder().setOffset(20).setPageSize(10).setTotal(30).build()).build();
EntitiesResponse entitiesResponse = mock(EntitiesResponse.class);
when(entityMapper.map(entityCollection, filter, expand, 10, 2, 30)).thenReturn(entitiesResponse);
assertEquals(entitiesResponse, entityController.getReferencedEntities(readSubResourceRequest));
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityFilter.
@Test
void testMapEntityFilter() throws URISyntaxException {
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("EntityType").getMock();
Attribute attribute0 = when(mock(Attribute.class).getName()).thenReturn("attr0").getMock();
doReturn(STRING).when(attribute0).getDataType();
Attribute attribute1 = when(mock(Attribute.class).getName()).thenReturn("attr1").getMock();
doReturn(STRING).when(attribute1).getDataType();
doReturn(asList(attribute0, attribute1)).when(entityType).getAtomicAttributes();
Entity entity = mock(Entity.class);
doReturn("id0").when(entity).getIdValue();
doReturn(entityType).when(entity).getEntityType();
doReturn("string0").when(entity).getString("attr0");
doReturn("string1").when(entity).getString(("attr1"));
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr1", "string1")).build();
assertEquals(expectedEntityResponse, entityMapper.map(entity, new Selection(singletonMap("attr1", null)), EMPTY_SELECTION));
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class FetchMapperTest method testToFetchEmpty.
@Test
void testToFetchEmpty() {
EntityType entityType = mock(EntityType.class);
Attribute attribute = mock(Attribute.class);
when(attribute.getName()).thenReturn("test");
when(entityType.getAtomicAttributes()).thenReturn(singletonList(attribute));
Selection expand = Selection.EMPTY_SELECTION;
Selection filter = Selection.FULL_SELECTION;
Fetch expected = new Fetch().field("test");
assertEquals(expected, fetchMapper.toFetch(entityType, filter, expand));
}
use of org.molgenis.api.model.Selection in project molgenis by molgenis.
the class EntityMapperImpl method mapReferences.
private EntitiesResponse mapReferences(Entity entity, Attribute attribute, Selection filter, Selection expand, int depth) {
URI uri = createEntityResponseUri(entity, attribute.getName());
if (expand.hasItem(attribute.getName())) {
String refEntityTypeId = attribute.getRefEntity().getId();
List<Entity> refEntities = stream(entity.getEntities(attribute.getName())).collect(toList());
EntityCollection entityCollection = EntityCollection.builder().setEntityTypeId(refEntityTypeId).setEntities(refEntities).setEntityId(entity.getIdValue().toString()).build();
Selection refFilter = getReferenceFilter(attribute, filter, expand);
Selection refExpand = getReferenceExpand(attribute, expand);
return mapRecursive(entityCollection, refFilter, refExpand, depth).setLinks(LinksResponse.create(null, uri, null)).build();
} else {
return EntitiesResponse.builder().setLinks(LinksResponse.create(null, uri, null)).build();
}
}
Aggregations