use of org.molgenis.api.data.v3.EntityCollection.Page in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityCollectionExpand.
@Test
void testMapEntityCollectionExpand() throws URISyntaxException {
HttpServletRequest request = mock(HttpServletRequest.class);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
when(request.getRequestURI()).thenReturn("/api/data/EntityType");
when(request.getScheme()).thenReturn("http");
when(request.getServerName()).thenReturn("localhost");
when(request.getServerPort()).thenReturn(80);
Entity refEntity = createMockEntity(STRING, "RefEntityType", "refId0");
Entity entity = createMockEntity(MREF);
doReturn("refString").when(refEntity).getString("attr");
doReturn(singletonList(refEntity)).when(entity).getEntities("attr");
EntityCollection entityCollection = EntityCollection.builder().setEntityTypeId("EntityType").setEntities(singletonList(entity)).setPage(Page.builder().setOffset(0).setPageSize(1).setTotal(2).build()).build();
URI refSelf = new URI("http://localhost/api/data/RefEntityType/refId0");
EntityResponse expectedRefEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, refSelf, null)).setData(singletonMap("attr", "refString")).build();
URI entitiesRefSelf = new URI("http://localhost/api/data/EntityType/id0/attr");
EntitiesResponse expectedRefEntitiesResponse = EntitiesResponse.builder().setLinks(LinksResponse.create(null, entitiesRefSelf, null)).setItems(singletonList(expectedRefEntityResponse)).build();
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", expectedRefEntitiesResponse)).build();
URI entitiesPrevious = new URI("http://localhost/api/data/EntityType?page=0");
URI entitiesSelf = new URI("http://localhost/api/data/EntityType");
URI entitiesNext = new URI("http://localhost/api/data/EntityType?page=2");
EntitiesResponse expectedEntitiesResponse = EntitiesResponse.builder().setLinks(LinksResponse.create(entitiesPrevious, entitiesSelf, entitiesNext)).setItems(singletonList(expectedEntityResponse)).setPage(PageResponse.create(1, 2, 0)).build();
assertEquals(expectedEntitiesResponse, entityMapper.map(entityCollection, FULL_SELECTION, FULL_SELECTION, 10, 1, 100));
}
use of org.molgenis.api.data.v3.EntityCollection.Page in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityRefNull.
@Test
void testMapEntityRefNull() throws URISyntaxException {
HttpServletRequest request = mock(HttpServletRequest.class);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
when(request.getRequestURI()).thenReturn("/api/data/EntityType");
when(request.getScheme()).thenReturn("http");
when(request.getServerName()).thenReturn("localhost");
when(request.getServerPort()).thenReturn(80);
Entity entity = createMockEntity(XREF);
doReturn(null).when(entity).getEntity("attr");
URI entitySelf = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, entitySelf, null)).setData(singletonMap("attr", null)).build();
URI entitiesPrevious = new URI("http://localhost/api/data/EntityType?page=0");
URI entitiesSelf = new URI("http://localhost/api/data/EntityType");
URI entitiesNext = new URI("http://localhost/api/data/EntityType?page=2");
EntitiesResponse expectedEntitiesResponse = EntitiesResponse.builder().setLinks(LinksResponse.create(entitiesPrevious, entitiesSelf, entitiesNext)).setItems(singletonList(expectedEntityResponse)).build();
EntityCollection entityCollection = EntityCollection.builder().setEntityTypeId("EntityType").setEntities(singletonList(entity)).build();
assertEquals(expectedEntitiesResponse, entityMapper.map(entityCollection, FULL_SELECTION, FULL_SELECTION, 10, 1, 100));
}
use of org.molgenis.api.data.v3.EntityCollection.Page in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityCollection.
@Test
void testMapEntityCollection() throws URISyntaxException {
HttpServletRequest request = mock(HttpServletRequest.class);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
when(request.getRequestURI()).thenReturn("/api/data/EntityType");
when(request.getScheme()).thenReturn("http");
when(request.getServerName()).thenReturn("localhost");
when(request.getServerPort()).thenReturn(80);
Entity entity = createMockEntity(STRING);
doReturn("string").when(entity).getString("attr");
EntityCollection entityCollection = EntityCollection.builder().setEntityTypeId("EntityType").setEntities(singletonList(entity)).setPage(Page.builder().setOffset(0).setPageSize(1).setTotal(2).build()).build();
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", "string")).build();
URI entitiesPrevious = new URI("http://localhost/api/data/EntityType?page=0");
URI entitiesSelf = new URI("http://localhost/api/data/EntityType");
URI entitiesNext = new URI("http://localhost/api/data/EntityType?page=2");
EntitiesResponse expectedEntitiesResponse = EntitiesResponse.builder().setLinks(LinksResponse.create(entitiesPrevious, entitiesSelf, entitiesNext)).setItems(singletonList(expectedEntityResponse)).setPage(PageResponse.create(1, 2, 0)).build();
assertEquals(expectedEntitiesResponse, entityMapper.map(entityCollection, FULL_SELECTION, EMPTY_SELECTION, 10, 1, 100));
}
Aggregations