Search in sources :

Example 21 with Sort

use of org.molgenis.api.model.Sort 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)

Example 22 with Sort

use of org.molgenis.api.model.Sort in project molgenis by molgenis.

the class SortMapperTest method testMap.

@Test
void testMap() {
    Attribute attr1 = mock(Attribute.class);
    Attribute attr2 = mock(Attribute.class);
    EntityType entityType = mock(EntityType.class);
    doReturn(attr1).when(entityType).getAttribute("attr1");
    doReturn(attr2).when(entityType).getAttribute("attr2");
    SortMapper sortMapper = new SortMapper();
    Sort sort = Sort.create(asList(Order.create("attr1", Direction.ASC), Order.create("attr2", Direction.DESC)));
    org.molgenis.data.Sort expected = new org.molgenis.data.Sort();
    expected.on("attr1", org.molgenis.data.Sort.Direction.ASC);
    expected.on("attr2", org.molgenis.data.Sort.Direction.DESC);
    assertEquals(expected, sortMapper.map(sort, entityType));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) Sort(org.molgenis.api.model.Sort) Test(org.junit.jupiter.api.Test)

Aggregations

Sort (org.molgenis.api.model.Sort)22 Test (org.junit.jupiter.api.Test)17 Query (org.molgenis.api.model.Query)14 EntityType (org.molgenis.data.meta.model.EntityType)14 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)14 Selection (org.molgenis.api.model.Selection)11 Attribute (org.molgenis.data.meta.model.Attribute)11 QueryImpl (org.molgenis.data.support.QueryImpl)8 Entity (org.molgenis.data.Entity)7 Fetch (org.molgenis.data.Fetch)7 Transactional (org.springframework.transaction.annotation.Transactional)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 AttributeMetadata (org.molgenis.data.meta.model.AttributeMetadata)3 EntitiesResponse (org.molgenis.api.data.v3.model.EntitiesResponse)2 QueryRule (org.molgenis.data.QueryRule)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Maps (com.google.common.collect.Maps)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1