Search in sources :

Example 1 with EntityResponse

use of org.molgenis.api.data.v3.model.EntityResponse 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 2 with EntityResponse

use of org.molgenis.api.data.v3.model.EntityResponse 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));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Entity(org.molgenis.data.Entity) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) EntitiesResponse(org.molgenis.api.data.v3.model.EntitiesResponse) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with EntityResponse

use of org.molgenis.api.data.v3.model.EntityResponse in project molgenis by molgenis.

the class EntityMapperImplTest method testMapEntityDateTime.

@Test
void testMapEntityDateTime() throws URISyntaxException {
    Entity entity = createMockEntity(DATE_TIME);
    doReturn(Instant.ofEpochMilli(1561010330984L)).when(entity).getInstant("attr");
    URI self = new URI("http://localhost/api/data/EntityType/id0");
    EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", Instant.ofEpochMilli(1561010330984L))).build();
    assertEquals(expectedEntityResponse, entityMapper.map(entity, FULL_SELECTION, EMPTY_SELECTION));
}
Also used : Entity(org.molgenis.data.Entity) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with EntityResponse

use of org.molgenis.api.data.v3.model.EntityResponse in project molgenis by molgenis.

the class EntityMapperImplTest method testMapEntityInt.

@Test
void testMapEntityInt() throws URISyntaxException {
    Entity entity = createMockEntity(INT);
    doReturn(123).when(entity).getInt("attr");
    URI self = new URI("http://localhost/api/data/EntityType/id0");
    EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", 123)).build();
    assertEquals(expectedEntityResponse, entityMapper.map(entity, FULL_SELECTION, EMPTY_SELECTION));
}
Also used : Entity(org.molgenis.data.Entity) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with EntityResponse

use of org.molgenis.api.data.v3.model.EntityResponse in project molgenis by molgenis.

the class EntityMapperImplTest method testMapEntityRefsType.

@ParameterizedTest
@MethodSource("refsTypeProvider")
void testMapEntityRefsType(AttributeType attributeType) throws URISyntaxException {
    Entity entity = createMockEntity(attributeType);
    doReturn(emptyList()).when(entity).getEntities("attr");
    URI refSelf = new URI("http://localhost/api/data/EntityType/id0/attr");
    EntitiesResponse expectedRefEntitiesResponse = EntitiesResponse.builder().setLinks(LinksResponse.create(null, refSelf, null)).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();
    assertEquals(expectedEntityResponse, entityMapper.map(entity, FULL_SELECTION, EMPTY_SELECTION));
}
Also used : Entity(org.molgenis.data.Entity) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) EntitiesResponse(org.molgenis.api.data.v3.model.EntitiesResponse) URI(java.net.URI) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

EntityResponse (org.molgenis.api.data.v3.model.EntityResponse)17 Entity (org.molgenis.data.Entity)17 URI (java.net.URI)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 Test (org.junit.jupiter.api.Test)12 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)12 EntitiesResponse (org.molgenis.api.data.v3.model.EntitiesResponse)6 Selection (org.molgenis.api.model.Selection)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 Attribute (org.molgenis.data.meta.model.Attribute)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)3 Streams.stream (com.google.common.collect.Streams.stream)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors.toList (java.util.stream.Collectors.toList)2 CheckForNull (javax.annotation.CheckForNull)2 Nullable (javax.annotation.Nullable)2