use of de.fraunhofer.iosb.ilt.faaast.service.request.handler.DeleteSubmodelByIdRequestHandler 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.request.handler.DeleteSubmodelByIdRequestHandler in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testReadValueFromAssetConnectionAndUpdatePersistence.
@Test
public void testReadValueFromAssetConnectionAndUpdatePersistence() throws AssetConnectionException, ResourceNotFoundException {
RequestHandler requestHandler = new DeleteSubmodelByIdRequestHandler(persistence, messageBus, assetConnectionManager);
Reference parentRef = new DefaultReference.Builder().key(new DefaultKey.Builder().value("sub").idType(KeyType.IRI).type(KeyElements.SUBMODEL).build()).build();
SubmodelElement prop1 = new DefaultProperty.Builder().idShort("prop1").value("test").valueType("string").build();
SubmodelElement range = new DefaultRange.Builder().idShort("range1").max("1.0").min("0").valueType("double").build();
SubmodelElement prop2 = new DefaultProperty.Builder().idShort("prop2").value("test").valueType("string").build();
SubmodelElementCollection collection = new DefaultSubmodelElementCollection.Builder().idShort("col1").value(prop2).build();
SubmodelElement prop1_new = new DefaultProperty.Builder().idShort("prop1").value("testNew").valueType("string").build();
SubmodelElement range_new = new DefaultRange.Builder().idShort("range1").max("1.0").min("0").valueType("double").build();
SubmodelElement prop2_new = new DefaultProperty.Builder().idShort("prop2").value("testNew").valueType("string").build();
List<SubmodelElement> submodelElements = List.of(prop1, range, collection);
AssetValueProvider provider_prop1 = mock(AssetValueProvider.class);
AssetValueProvider provider_prop2 = mock(AssetValueProvider.class);
AssetValueProvider provider_range1 = mock(AssetValueProvider.class);
when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
// mock value prop1
when(assetConnectionManager.getValueProvider(AasUtils.toReference(parentRef, prop1))).thenReturn(provider_prop1);
when(provider_prop1.getValue()).thenReturn(ElementValueMapper.toValue(prop1_new));
// mock value prop2
when(assetConnectionManager.getValueProvider(AasUtils.toReference(AasUtils.toReference(parentRef, collection), prop2))).thenReturn(provider_prop2);
when(provider_prop2.getValue()).thenReturn(ElementValueMapper.toValue(prop2_new));
// mock value range
when(assetConnectionManager.getValueProvider(AasUtils.toReference(parentRef, range))).thenReturn(provider_range1);
when(provider_range1.getValue()).thenReturn(ElementValueMapper.toValue(range_new));
requestHandler.readValueFromAssetConnectionAndUpdatePersistence(parentRef, submodelElements);
verify(persistence).put(null, AasUtils.toReference(parentRef, prop1), prop1_new);
verify(persistence).put(null, AasUtils.toReference(AasUtils.toReference(parentRef, collection), prop2), prop2_new);
Assert.assertEquals(prop1_new, prop1);
Assert.assertEquals(prop2_new, prop2);
Assert.assertEquals(range_new, range);
}
use of de.fraunhofer.iosb.ilt.faaast.service.request.handler.DeleteSubmodelByIdRequestHandler in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testWriteValueToAssetConnection.
@Test
public void testWriteValueToAssetConnection() 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);
requestHandler.writeValueToAssetConnection(new DefaultReference(), expected);
verify(assetValueProvider).setValue(expected);
}
Aggregations