use of org.molgenis.api.metadata.v3.model.EntityTypeResponseData in project molgenis by molgenis.
the class EntityTypeResponseMapperTest method toEntityTypesResponse.
@Test
void toEntityTypesResponse() throws URISyntaxException {
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest.setMethod("GET");
mockHttpServletRequest.setRequestURI("/api/metadata");
mockHttpServletRequest.setQueryString("page=1");
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(mockHttpServletRequest));
EntityType entityType = mock(EntityType.class);
when(entityType.getId()).thenReturn("MyEntityTypeId");
int total = 5;
EntityTypes entityTypes = EntityTypes.builder().setEntityTypes(singletonList(entityType)).setTotal(total).build();
int size = 1;
int number = 1;
EntityTypeResponseData entityTypeResponseData = EntityTypeResponseData.builder().setId("MyEntityTypeId").setAttributes(AttributesResponse.builder().setLinks(LinksResponse.create(null, new URI("http://localhost/api/metadata/MyEntityTypeId/attributes"), null)).build()).setAbstract(false).setIndexingDepth(0).build();
EntityTypeResponse entityTypeResponse = EntityTypeResponse.builder().setLinks(LinksResponse.create(null, new URI("http://localhost/api/metadata/MyEntityTypeId"), null)).setData(entityTypeResponseData).build();
EntityTypesResponse entityTypesResponse = EntityTypesResponse.builder().setLinks(LinksResponse.create(new URI("http://localhost/api/metadata?page=0"), new URI("http://localhost/api/metadata?page=1"), new URI("http://localhost/api/metadata?page=2"))).setItems(singletonList(entityTypeResponse)).setPage(PageResponse.create(size, total, number)).build();
assertEquals(entityTypesResponse, entityTypeV3Mapper.toEntityTypesResponse(entityTypes, size, number));
}
use of org.molgenis.api.metadata.v3.model.EntityTypeResponseData in project molgenis by molgenis.
the class EntityTypeResponseMapperTest method toEntityTypeResponse.
@Test
void toEntityTypeResponse() throws URISyntaxException {
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest.setMethod("GET");
mockHttpServletRequest.setRequestURI("/api/metadata/MyEntityTypeId");
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(mockHttpServletRequest));
EntityType entityType = mock(EntityType.class);
when(entityType.getId()).thenReturn("MyEntityTypeId");
doReturn("My Entity Type").when(entityType).getLabel();
doReturn("My Entity Type").when(entityType).getLabel(any(String.class));
doReturn("My Entity Type description").when(entityType).getDescription();
doReturn("My Entity Type description").when(entityType).getDescription(any(String.class));
when(entityType.getDescription()).thenReturn("My Entity Type description");
when(entityType.getString("labelEn")).thenReturn("My Entity Type (en)");
EntityTypeResponseData entityTypeResponseData = EntityTypeResponseData.builder().setId("MyEntityTypeId").setLabel("My Entity Type").setLabelI18n(I18nValue.builder().setDefaultValue("My Entity Type").setTranslations(ImmutableMap.of("en", "My Entity Type (en)")).build()).setDescription("My Entity Type description").setDescriptionI18n(I18nValue.builder().setDefaultValue("My Entity Type description").setTranslations(ImmutableMap.of()).build()).setAttributes(AttributesResponse.builder().setLinks(LinksResponse.create(null, new URI("http://localhost/api/metadata/MyEntityTypeId/attributes"), null)).setItems(ImmutableList.of()).build()).setAbstract(false).setIndexingDepth(0).build();
EntityTypeResponse entityTypeResponse = EntityTypeResponse.builder().setLinks(LinksResponse.create(null, new URI("http://localhost/api/metadata/MyEntityTypeId"), null)).setData(entityTypeResponseData).build();
assertEquals(entityTypeResponse, entityTypeV3Mapper.toEntityTypeResponse(entityType, true, true));
}
Aggregations