use of org.molgenis.api.data.v3.model.EntityResponse in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityBool.
@Test
void testMapEntityBool() throws URISyntaxException {
Entity entity = createMockEntity(BOOL);
doReturn(true).when(entity).getBoolean("attr");
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", true)).build();
assertEquals(expectedEntityResponse, entityMapper.map(entity, FULL_SELECTION, EMPTY_SELECTION));
}
use of org.molgenis.api.data.v3.model.EntityResponse in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityRefType.
@ParameterizedTest
@MethodSource("refTypeProvider")
void testMapEntityRefType(AttributeType attributeType) throws URISyntaxException {
Entity refEntity = createMockEntity(STRING, "RefEntityType", "refId0");
Entity entity = createMockEntity(attributeType);
doReturn(refEntity).when(entity).getEntity("attr");
URI refSelf = new URI("http://localhost/api/data/RefEntityType/refId0");
EntityResponse expectedRefEntityResponse = EntityResponse.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", expectedRefEntityResponse)).build();
assertEquals(expectedEntityResponse, entityMapper.map(entity, FULL_SELECTION, EMPTY_SELECTION));
}
use of org.molgenis.api.data.v3.model.EntityResponse 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.model.EntityResponse in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityFilter.
@Test
void testMapEntityFilter() throws URISyntaxException {
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("EntityType").getMock();
Attribute attribute0 = when(mock(Attribute.class).getName()).thenReturn("attr0").getMock();
doReturn(STRING).when(attribute0).getDataType();
Attribute attribute1 = when(mock(Attribute.class).getName()).thenReturn("attr1").getMock();
doReturn(STRING).when(attribute1).getDataType();
doReturn(asList(attribute0, attribute1)).when(entityType).getAtomicAttributes();
Entity entity = mock(Entity.class);
doReturn("id0").when(entity).getIdValue();
doReturn(entityType).when(entity).getEntityType();
doReturn("string0").when(entity).getString("attr0");
doReturn("string1").when(entity).getString(("attr1"));
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr1", "string1")).build();
assertEquals(expectedEntityResponse, entityMapper.map(entity, new Selection(singletonMap("attr1", null)), EMPTY_SELECTION));
}
use of org.molgenis.api.data.v3.model.EntityResponse in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityDate.
@Test
void testMapEntityDate() throws URISyntaxException {
Entity entity = createMockEntity(DATE);
doReturn(LocalDate.of(2019, 4, 30)).when(entity).getLocalDate("attr");
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", LocalDate.of(2019, 4, 30))).build();
assertEquals(entityMapper.map(entity, FULL_SELECTION, EMPTY_SELECTION), expectedEntityResponse);
}
Aggregations