use of org.molgenis.api.data.v3.model.EntityResponse in project molgenis by molgenis.
the class EntityMapperImplTest method testMapEntityLong.
@Test
void testMapEntityLong() throws URISyntaxException {
Entity entity = createMockEntity(LONG);
doReturn(Long.MAX_VALUE).when(entity).getLong("attr");
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", Long.MAX_VALUE)).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 testMapEntityStringType.
@ParameterizedTest
@MethodSource("stringTypeProvider")
void testMapEntityStringType(AttributeType attributeType) throws URISyntaxException {
Entity entity = createMockEntity(attributeType);
doReturn("string").when(entity).getString("attr");
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();
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 testMapEntityDecimal.
@Test
void testMapEntityDecimal() throws URISyntaxException {
Entity entity = createMockEntity(DECIMAL);
doReturn(3.14).when(entity).getDouble("attr");
URI self = new URI("http://localhost/api/data/EntityType/id0");
EntityResponse expectedEntityResponse = EntityResponse.builder().setLinks(LinksResponse.create(null, self, null)).setData(singletonMap("attr", 3.14)).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 EntityMapperImpl method mapRecursive.
private EntityResponse mapRecursive(Entity entity, Selection filter, Selection expand, int depth) {
if (depth > MAX_DEPTH) {
throw new IllegalArgumentException("max_depth exceeded: " + depth);
}
EntityResponse.Builder builder = EntityResponse.builder();
if (filter.hasItems()) {
Map<String, Object> dataMap = new LinkedHashMap<>();
stream(entity.getEntityType().getAtomicAttributes()).filter(attribute -> filter.hasItem(attribute.getName())).forEach(attribute -> dataMap.put(attribute.getName(), mapRecursive(entity, attribute, filter, expand, depth)));
builder.setData(dataMap);
}
URI uri = createEntityResponseUri(entity);
return builder.setLinks(LinksResponse.create(null, uri, null)).build();
}
use of org.molgenis.api.data.v3.model.EntityResponse in project molgenis by molgenis.
the class EntityControllerTest method testGetEntity.
@Test
void testGetEntity() {
String entityTypeId = "MyEntityTypeId";
String entityId = "MyId";
Selection filter = Selection.FULL_SELECTION;
Selection expand = Selection.FULL_SELECTION;
ReadEntityRequest entityRequest = new ReadEntityRequest();
entityRequest.setEntityTypeId(entityTypeId);
entityRequest.setEntityId(entityId);
entityRequest.setFilter(filter);
entityRequest.setExpand(expand);
Entity entity = mock(Entity.class);
when(dataServiceV3.find(entityTypeId, entityId, filter, expand)).thenReturn(entity);
EntityResponse entityResponse = mock(EntityResponse.class);
when(entityMapper.map(entity, filter, expand)).thenReturn(entityResponse);
assertEquals(entityResponse, entityController.getEntity(entityRequest));
}
Aggregations