Search in sources :

Example 6 with Selection

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

the class DataServiceV3ImplTest method testFindAllUnknownRepositoryUnknownEntity.

@Test
void testFindAllUnknownRepositoryUnknownEntity() {
    String entityTypeId = "MyEntityType";
    Selection filter = Selection.FULL_SELECTION;
    Selection expand = Selection.EMPTY_SELECTION;
    when(metaDataService.getRepository(entityTypeId)).thenReturn(Optional.empty());
    assertThrows(UnknownRepositoryException.class, () -> dataServiceV3Impl.findAll(entityTypeId, null, filter, expand, Sort.EMPTY_SORT, 1, 1));
}
Also used : Selection(org.molgenis.api.model.Selection) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 7 with Selection

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

the class EntityControllerTest method testGetEntities.

@Test
void testGetEntities() {
    String entityTypeId = "MyEntityTypeId";
    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);
    ReadEntitiesRequest entityRequest = new ReadEntitiesRequest();
    entityRequest.setEntityTypeId(entityTypeId);
    entityRequest.setQ(query);
    entityRequest.setSort(sort);
    entityRequest.setFilter(filter);
    entityRequest.setExpand(expand);
    entityRequest.setSize(10);
    entityRequest.setPage(2);
    Entities entities = Entities.create(emptyList(), 30);
    when(dataServiceV3.findAll(entityTypeId, 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.getEntities(entityRequest));
}
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) ReadEntitiesRequest(org.molgenis.api.data.v3.model.ReadEntitiesRequest) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 8 with Selection

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

the class EntityMapperImplTest method testMapEntityExpandXref.

@Test
void testMapEntityExpandXref() throws URISyntaxException {
    Entity refRefEntity = createMockEntity(XREF, "RefRefEntityType", "refRefId0");
    Entity refEntity = createMockEntity(XREF, "RefEntityType", "refId0");
    Entity entity = createMockEntity(XREF);
    doReturn(refRefEntity).when(refEntity).getEntity("attr");
    doReturn(refEntity).when(entity).getEntity("attr");
    URI refRefSelf = new URI("http://localhost/api/data/RefRefEntityType/refRefId0");
    EntityResponse expectedRefRefEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, refRefSelf, null)).build();
    URI refSelf = new URI("http://localhost/api/data/RefEntityType/refId0");
    EntityResponse expectedRefEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, refSelf, null)).setData(singletonMap("attr", expectedRefRefEntityResponse)).build();
    URI self = new URI("http://localhost/api/data/EntityType/id0");
    EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", expectedRefEntityResponse)).build();
    assertEquals(expectedEntityResponse, entityMapper.map(entity, FULL_SELECTION, new Selection(singletonMap("attr", null))));
}
Also used : Entity(org.molgenis.data.Entity) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) Selection(org.molgenis.api.model.Selection) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with Selection

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

the class FetchMapperTest method testToFetch.

@Test
void testToFetch() {
    EntityType entityType = mock(EntityType.class);
    Attribute attribute = mock(Attribute.class);
    when(attribute.getName()).thenReturn("test");
    Attribute attributeXref = mock(Attribute.class);
    when(attributeXref.getName()).thenReturn("xref");
    when(attributeXref.getDataType()).thenReturn(AttributeType.XREF);
    when(entityType.getAtomicAttributes()).thenReturn(Arrays.asList(attribute, attributeXref));
    Selection expand = new Selection(Collections.singletonMap("xref", Selection.FULL_SELECTION));
    Selection filter = Selection.FULL_SELECTION;
    Fetch expected = new Fetch().field("xref").field("test");
    assertEquals(expected, fetchMapper.toFetch(entityType, filter, expand));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Fetch(org.molgenis.data.Fetch) Attribute(org.molgenis.data.meta.model.Attribute) Selection(org.molgenis.api.model.Selection) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 10 with Selection

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

the class EntityController method getReferencedEntities.

@Transactional(readOnly = true)
@GetMapping("/{entityTypeId}/{entityId}/{fieldId}")
public EntitiesResponse getReferencedEntities(@Valid ReadSubresourceRequest entitiesRequest) {
    String entityTypeId = entitiesRequest.getEntityTypeId();
    String entityId = entitiesRequest.getEntityId();
    String fieldId = entitiesRequest.getFieldId();
    Selection filter = entitiesRequest.getFilter();
    Selection expand = entitiesRequest.getExpand();
    int size = entitiesRequest.getSize();
    int page = entitiesRequest.getPage();
    Sort sort = entitiesRequest.getSort();
    Entities entities = dataServiceV3.findSubresources(entityTypeId, entityId, fieldId, entitiesRequest.getQ().orElse(null), filter, expand, sort, size, page);
    EntityCollection entityCollection = EntityCollection.builder().setEntityTypeId(entityTypeId).setEntities(entities.getEntities()).setPage(Page.builder().setOffset(size * page).setPageSize(size).setTotal(entities.getTotal()).build()).build();
    return entityMapper.map(entityCollection, filter, expand, size, page, entities.getTotal());
}
Also used : Selection(org.molgenis.api.model.Selection) Sort(org.molgenis.api.model.Sort) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Selection (org.molgenis.api.model.Selection)32 Test (org.junit.jupiter.api.Test)24 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)19 Entity (org.molgenis.data.Entity)18 Attribute (org.molgenis.data.meta.model.Attribute)15 EntityType (org.molgenis.data.meta.model.EntityType)13 Fetch (org.molgenis.data.Fetch)12 Sort (org.molgenis.api.model.Sort)11 Query (org.molgenis.api.model.Query)9 QueryImpl (org.molgenis.data.support.QueryImpl)7 URI (java.net.URI)5 EntityResponse (org.molgenis.api.data.v3.model.EntityResponse)5 CheckForNull (javax.annotation.CheckForNull)4 Nullable (javax.annotation.Nullable)4 EntitiesResponse (org.molgenis.api.data.v3.model.EntitiesResponse)4 HashMap (java.util.HashMap)3 Transactional (org.springframework.transaction.annotation.Transactional)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 Streams.stream (com.google.common.collect.Streams.stream)2 LinkedHashMap (java.util.LinkedHashMap)2