use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testSetSubmodelElementValueByPathRequest.
@Test
public void testSetSubmodelElementValueByPathRequest() throws ResourceNotFoundException, AssetConnectionException {
when(persistence.get((Reference) any(), any())).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
PropertyValue propertyValue = new PropertyValue.Builder().value(new StringValue("Test")).build();
SetSubmodelElementValueByPathRequest request = new SetSubmodelElementValueByPathRequest.Builder<ElementValue>().id(environment.getSubmodels().get(0).getIdentification()).value(propertyValue).valueParser(new ElementValueParser<ElementValue>() {
@Override
public <U extends ElementValue> U parse(ElementValue raw, Class<U> type) {
return (U) raw;
}
}).path(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF)).build();
Response response = manager.execute(request);
SetSubmodelElementValueByPathResponse expected = new SetSubmodelElementValueByPathResponse.Builder().statusCode(StatusCode.Success).build();
Assert.assertEquals(expected, response);
verify(assetValueProvider).setValue(propertyValue);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testRangeToValueMapping.
@Test
public void testRangeToValueMapping() {
RangeValue expected = RangeValue.builder().min(new DoubleValue(2.3)).max(new DoubleValue(5.1)).build();
SubmodelElement input = new DefaultRange.Builder().valueType(expected.getMin().getDataType().getName()).min(expected.getMin().asString()).max(expected.getMax().asString()).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testMultiLanguagePropertyToValueMapping.
@Test
public void testMultiLanguagePropertyToValueMapping() {
MultiLanguagePropertyValue expected = MultiLanguagePropertyValue.builder().value("deutsch", "de").value("english", "en").build();
SubmodelElement input = new DefaultMultiLanguageProperty.Builder().values(List.copyOf(expected.getLangStringSet())).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testEntityToValueMapping.
@Test
public void testEntityToValueMapping() throws ValueFormatException {
EntityValue expected = EntityValue.builder().statement("property", PropertyValue.of(Datatype.String, "foo")).entityType(EntityType.SELF_MANAGED_ENTITY).globalAssetId(List.of(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://example.org/submodel/1").build(), new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value("property1").build())).build();
SubmodelElement input = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().category("Test").idShort(expected.getStatements().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).entityType(expected.getEntityType()).globalAssetId(new DefaultReference.Builder().keys(expected.getGlobalAssetId()).build()).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testSubmodelElementCollectionToValueMapping.
@Test
public void testSubmodelElementCollectionToValueMapping() {
PropertyValue propertyValue = PropertyValue.builder().value(new StringValue("testValue")).build();
PropertyValue propertyValue2 = PropertyValue.builder().value(new StringValue("testValue2")).build();
SubmodelElementCollectionValue expected = SubmodelElementCollectionValue.builder().value("prop1", propertyValue).value("prop2", propertyValue2).build();
SubmodelElement input = new DefaultSubmodelElementCollection.Builder().value(new DefaultProperty.Builder().idShort("prop1").value("testValue").build()).value(new DefaultProperty.Builder().idShort("prop2").value("testValue2").build()).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
Aggregations