use of org.molgenis.api.metadata.v3.model.AttributeResponse in project molgenis by molgenis.
the class MetadataApiControllerTest method testGetAttribute.
@Test
void testGetAttribute() {
String attributeId = "MyAttributeId";
String entityTypeId = "entityTypeId";
Attribute attribute = mock(Attribute.class);
when(metadataApiService.findAttribute(entityTypeId, attributeId)).thenReturn(attribute);
AttributeResponse attributeResponse = mock(AttributeResponse.class);
when(attributeResponseMapper.toAttributeResponse(attribute, false)).thenReturn(attributeResponse);
assertEquals(attributeResponse, metadataApiController.getAttribute(entityTypeId, attributeId));
}
use of org.molgenis.api.metadata.v3.model.AttributeResponse in project molgenis by molgenis.
the class AttributeResponseMapperTest method mapAttribute.
@Test
void mapAttribute() throws URISyntaxException {
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
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");
doReturn("My Attribute").when(attribute).getLabel();
doReturn(null).when(attribute).getLabel(any(String.class));
doReturn("My Attribute description").when(attribute).getDescription();
doReturn(null).when(attribute).getDescription(any(String.class));
when(attribute.getSequenceNumber()).thenReturn(2);
when(attribute.getEntity()).thenReturn(entityType);
when(attribute.getDataType()).thenReturn(AttributeType.ENUM);
when(attribute.getMaxLength()).thenReturn(255);
when(attribute.getEnumOptions()).thenReturn(asList("option0", "option1"));
when(attribute.getLookupAttributeIndex()).thenReturn(null);
when(attribute.getCascadeDelete()).thenReturn(null);
AttributeResponseData attributeResponseData = AttributeResponseData.builder().setId("MyAttributeId").setName("MyAttributeName").setSequenceNr(2).setType("enum").setMaxLength(255).setEnumOptions(ImmutableList.of("option0", "option1")).setIdAttribute(false).setLabelAttribute(false).setNullable(false).setAuto(false).setVisible(false).setUnique(false).setReadOnly(false).setAggregatable(false).setLabelI18n(I18nValue.builder().setDefaultValue("My Attribute").setTranslations(ImmutableMap.of()).build()).setDescriptionI18n(I18nValue.builder().setDefaultValue("My Attribute description").setTranslations(ImmutableMap.of()).build()).build();
AttributeResponse attributeResponse = AttributeResponse.builder().setLink(LinksResponse.create(null, new URI("http://localhost/api/metadata/MyEntityTypeId/attributes/MyAttributeId"), null)).setData(attributeResponseData).build();
assertEquals(attributeResponse, attributeResponseMapper.toAttributeResponse(attribute, true));
}
use of org.molgenis.api.metadata.v3.model.AttributeResponse 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