Search in sources :

Example 1 with ReadSubresourceRequest

use of org.molgenis.api.data.v3.model.ReadSubresourceRequest 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));
}
Also used : Query(org.molgenis.api.model.Query) Selection(org.molgenis.api.model.Selection) EntitiesResponse(org.molgenis.api.data.v3.model.EntitiesResponse) Sort(org.molgenis.api.model.Sort) ReadSubresourceRequest(org.molgenis.api.data.v3.model.ReadSubresourceRequest) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

Test (org.junit.jupiter.api.Test)1 EntitiesResponse (org.molgenis.api.data.v3.model.EntitiesResponse)1 ReadSubresourceRequest (org.molgenis.api.data.v3.model.ReadSubresourceRequest)1 Query (org.molgenis.api.model.Query)1 Selection (org.molgenis.api.model.Selection)1 Sort (org.molgenis.api.model.Sort)1 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)1