Search in sources :

Example 11 with EntityResponse

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));
}
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 12 with EntityResponse

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));
}
Also used : Entity(org.molgenis.data.Entity) EntityResponse(org.molgenis.api.data.v3.model.EntityResponse) URI(java.net.URI) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with EntityResponse

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));
}
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 14 with EntityResponse

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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) 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 15 with EntityResponse

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);
}
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)

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