Search in sources :

Example 1 with EntityTypesResponse

use of org.molgenis.api.metadata.v3.model.EntityTypesResponse 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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeResponseData(org.molgenis.api.metadata.v3.model.EntityTypeResponseData) EntityTypesResponse(org.molgenis.api.metadata.v3.model.EntityTypesResponse) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) EntityTypeResponse(org.molgenis.api.metadata.v3.model.EntityTypeResponse) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 2 with EntityTypesResponse

use of org.molgenis.api.metadata.v3.model.EntityTypesResponse in project molgenis by molgenis.

the class MetadataApiControllerTest method testGetEntityTypes.

@Test
void testGetEntityTypes() {
    int page = 2;
    int size = 1;
    Sort sort = mock(Sort.class);
    Query query = mock(Query.class);
    ReadEntityTypesRequest readEntityTypesRequest = new ReadEntityTypesRequest();
    readEntityTypesRequest.setPage(page);
    readEntityTypesRequest.setSize(size);
    readEntityTypesRequest.setSort(sort);
    readEntityTypesRequest.setQ(query);
    EntityTypes entityTypes = mock(EntityTypes.class);
    when(metadataApiService.findEntityTypes(query, sort, size, page)).thenReturn(entityTypes);
    EntityTypesResponse entityTypesResponse = mock(EntityTypesResponse.class);
    when(entityTypeResponseMapper.toEntityTypesResponse(entityTypes, size, page)).thenReturn(entityTypesResponse);
    assertEquals(entityTypesResponse, metadataApiController.getEntityTypes(readEntityTypesRequest));
}
Also used : EntityTypesResponse(org.molgenis.api.metadata.v3.model.EntityTypesResponse) Query(org.molgenis.api.model.Query) Sort(org.molgenis.api.model.Sort) ReadEntityTypesRequest(org.molgenis.api.metadata.v3.model.ReadEntityTypesRequest) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 3 with EntityTypesResponse

use of org.molgenis.api.metadata.v3.model.EntityTypesResponse in project molgenis by molgenis.

the class EntityTypeResponseMapperImpl method toEntityTypesResponse.

@Override
public EntityTypesResponse toEntityTypesResponse(EntityTypes entityTypes, int pageSize, int pageNumber) {
    List<EntityTypeResponse> results = new ArrayList<>();
    for (EntityType entityType : entityTypes.getEntityTypes()) {
        results.add(mapInternal(entityType, false, true, false, false));
    }
    int total = entityTypes.getTotal();
    return EntityTypesResponse.create(LinksUtils.createLinksResponse(pageNumber, pageSize, total), results, PageUtils.getPageResponse(pageSize, pageNumber * pageSize, total));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeResponse(org.molgenis.api.metadata.v3.model.EntityTypeResponse) ArrayList(java.util.ArrayList)

Aggregations

Test (org.junit.jupiter.api.Test)2 EntityTypeResponse (org.molgenis.api.metadata.v3.model.EntityTypeResponse)2 EntityTypesResponse (org.molgenis.api.metadata.v3.model.EntityTypesResponse)2 EntityType (org.molgenis.data.meta.model.EntityType)2 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 EntityTypeResponseData (org.molgenis.api.metadata.v3.model.EntityTypeResponseData)1 ReadEntityTypesRequest (org.molgenis.api.metadata.v3.model.ReadEntityTypesRequest)1 Query (org.molgenis.api.model.Query)1 Sort (org.molgenis.api.model.Sort)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1