use of org.molgenis.api.metadata.v3.model.AttributesResponse in project molgenis by molgenis.
the class MetadataApiControllerTest method testGetAttributes.
@Test
void testGetAttributes() {
String entityTypeId = "MyEntityTypeId";
Query query = mock(Query.class);
Sort sort = mock(Sort.class);
int size = 1;
int page = 2;
ReadAttributesRequest readAttributesRequest = new ReadAttributesRequest();
readAttributesRequest.setQ(query);
readAttributesRequest.setSort(sort);
readAttributesRequest.setSize(size);
readAttributesRequest.setPage(page);
Attributes attributes = mock(Attributes.class);
when(metadataApiService.findAttributes(entityTypeId, query, sort, size, page)).thenReturn(attributes);
AttributesResponse attributesResponse = mock(AttributesResponse.class);
when(attributeResponseMapper.toAttributesResponse(attributes, size, page)).thenReturn(attributesResponse);
assertEquals(attributesResponse, metadataApiController.getAttributes(entityTypeId, readAttributesRequest));
}
use of org.molgenis.api.metadata.v3.model.AttributesResponse in project molgenis by molgenis.
the class AttributeResponseMapperTest method mapAttributes.
@Test
void mapAttributes() throws URISyntaxException {
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest.setRequestURI("/api/metadata/MyEntityType/attributes");
mockHttpServletRequest.setQueryString("page=1");
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(mockHttpServletRequest));
EntityType entityType = mock(EntityType.class);
when(entityType.getId()).thenReturn("MyEntityTypeId");
Attribute attribute = mock(Attribute.class);
when(attribute.getIdentifier()).thenReturn("MyAttributeId");
when(attribute.getName()).thenReturn("MyAttributeName");
when(attribute.getSequenceNumber()).thenReturn(2);
when(attribute.getEntity()).thenReturn(entityType);
when(attribute.getDataType()).thenReturn(AttributeType.STRING);
when(attribute.getMaxLength()).thenReturn(255);
when(attribute.getLookupAttributeIndex()).thenReturn(null);
when(attribute.getCascadeDelete()).thenReturn(null);
AttributeResponseData attributeResponseData = AttributeResponseData.builder().setId("MyAttributeId").setName("MyAttributeName").setSequenceNr(2).setType("string").setMaxLength(255).setIdAttribute(false).setLabelAttribute(false).setNullable(false).setAuto(false).setVisible(false).setUnique(false).setReadOnly(false).setAggregatable(false).build();
AttributeResponse attributeResponse = AttributeResponse.builder().setLink(LinksResponse.create(null, new URI("http://localhost/api/metadata/MyEntityTypeId/attributes/MyAttributeId"), null)).setData(attributeResponseData).build();
AttributesResponse attributesResponse = AttributesResponse.builder().setLinks(LinksResponse.create(new URI("http://localhost/api/metadata/MyEntityType/attributes?page=0"), new URI("http://localhost/api/metadata/MyEntityType/attributes?page=1"), new URI("http://localhost/api/metadata/MyEntityType/attributes?page=2"))).setItems(ImmutableList.of(attributeResponse)).setPage(PageResponse.create(1, 5, 1)).build();
assertEquals(attributesResponse, attributeResponseMapper.toAttributesResponse(Attributes.create(ImmutableList.of(attribute), 5), 1, 1));
}
Aggregations