use of de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testReadValueFromAssetConnection.
@Test
public void testReadValueFromAssetConnection() throws AssetConnectionException {
RequestHandler requestHandler = new DeleteSubmodelByIdRequestHandler(persistence, messageBus, assetConnectionManager);
PropertyValue expected = new PropertyValue.Builder().value(new StringValue("test")).build();
when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
when(assetValueProvider.getValue()).thenReturn(expected);
DataElementValue actual = requestHandler.readDataElementValueFromAssetConnection(new DefaultReference());
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue 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.primitive.StringValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testSubmodelElementCollectionSetValueMapping.
@Test
public void testSubmodelElementCollectionSetValueMapping() {
SubmodelElement actual = new DefaultSubmodelElementCollection.Builder().value(new DefaultProperty.Builder().idShort("prop1").build()).value(new DefaultProperty.Builder().idShort("prop2").build()).build();
PropertyValue propertyValue = PropertyValue.builder().value(new StringValue("testValue")).build();
PropertyValue propertyValue2 = PropertyValue.builder().value(new StringValue("testValue2")).build();
SubmodelElementCollectionValue value = SubmodelElementCollectionValue.builder().value("prop1", propertyValue).value("prop2", propertyValue2).build();
SubmodelElement expected = new DefaultSubmodelElementCollection.Builder().value(new DefaultProperty.Builder().idShort("prop1").value("testValue").valueType("string").build()).value(new DefaultProperty.Builder().idShort("prop2").value("testValue2").valueType("string").build()).build();
actual = ElementValueMapper.setValue(actual, value);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue 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);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testPropertySetValueMapping.
@Test
public void testPropertySetValueMapping() {
PropertyValue value = new PropertyValue(new StringValue("foo"));
SubmodelElement expected = new DefaultProperty.Builder().valueType(value.getValue().getDataType().getName()).value(value.getValue().asString()).build();
SubmodelElement actual = new DefaultProperty.Builder().build();
ElementValueMapper.setValue(actual, value);
Assert.assertEquals(expected, actual);
}
Aggregations