use of de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testInvokeOperationAsyncRequest.
@Test
public void testInvokeOperationAsyncRequest() {
CoreConfig coreConfig = CoreConfig.builder().build();
Persistence persistence = mock(Persistence.class);
MessageBus messageBus = mock(MessageBus.class);
AssetConnectionManager assetConnectionManager = mock(AssetConnectionManager.class);
AssetOperationProvider assetOperationProvider = mock(AssetOperationProvider.class);
RequestHandlerManager manager = new RequestHandlerManager(coreConfig, persistence, messageBus, assetConnectionManager);
Operation operation = getTestOperation();
OperationHandle expectedOperationHandle = new OperationHandle.Builder().handleId("1").requestId("1").build();
when(persistence.putOperationContext(any(), any(), any())).thenReturn(expectedOperationHandle);
when(persistence.getOperationResult(any())).thenReturn(new OperationResult.Builder().requestId("1").build());
when(assetConnectionManager.hasOperationProvider(any())).thenReturn(true);
when(assetConnectionManager.getOperationProvider(any())).thenReturn(assetOperationProvider);
InvokeOperationAsyncRequest invokeOperationAsyncRequest = new InvokeOperationAsyncRequest.Builder().requestId("1").id(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("http://example.org").build()).inoutputArguments(operation.getInoutputVariables()).inputArguments(operation.getInputVariables()).build();
InvokeOperationAsyncResponse response = manager.execute(invokeOperationAsyncRequest);
OperationHandle actualOperationHandle = response.getPayload();
Assert.assertEquals(expectedOperationHandle, actualOperationHandle);
}
use of de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method createRequestHandlerManager.
@Before
public void createRequestHandlerManager() {
environment = AASFull.createEnvironment();
coreConfig = CoreConfig.builder().build();
messageBus = mock(MessageBus.class);
persistence = mock(Persistence.class);
assetConnectionManager = mock(AssetConnectionManager.class);
manager = new RequestHandlerManager(coreConfig, persistence, messageBus, assetConnectionManager);
assetValueProvider = mock(AssetValueProvider.class);
when(assetConnectionManager.getValueProvider(any())).thenReturn(assetValueProvider);
}
use of de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method subscribeMessageBus.
/**
* Subscribes to Events on the MessageBus (e.g. ValueChangeEvents).
*/
private void subscribeMessageBus() {
try {
if (messageBus != null) {
logger.debug("subscribeMessageBus: subscribe ValueChangeEvents");
SubscriptionInfo info = SubscriptionInfo.create(ValueChangeEventMessage.class, (t) -> {
try {
valueChanged(t.getElement(), t.getNewValue(), t.getOldValue());
} catch (StatusException ex2) {
logger.error("valueChanged Exception", ex2);
}
});
SubscriptionId rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementCreateEventMessage.class, (x) -> {
try {
elementCreated(x.getElement(), x.getValue());
} catch (Exception ex3) {
logger.error("elementCreated Exception", ex3);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementDeleteEventMessage.class, (x) -> {
try {
elementDeleted(x.getElement());
} catch (Exception ex3) {
logger.error("elementDeleted Exception", ex3);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementUpdateEventMessage.class, (x) -> {
try {
elementUpdated(x.getElement(), x.getValue());
} catch (Exception ex3) {
logger.error("elementUpdated Exception", ex3);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
} else {
logger.warn("MessageBus not available!");
}
} catch (Throwable ex) {
logger.error("subscribeMessageBus Exception", ex);
throw ex;
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testInvokeOperationSyncRequest.
@Test
public void testInvokeOperationSyncRequest() {
CoreConfig coreConfig = CoreConfig.builder().build();
Persistence persistence = mock(Persistence.class);
MessageBus messageBus = mock(MessageBus.class);
AssetConnectionManager assetConnectionManager = mock(AssetConnectionManager.class);
when(assetConnectionManager.hasOperationProvider(any())).thenReturn(true);
when(assetConnectionManager.getOperationProvider(any())).thenReturn(new CustomAssetOperationProvider());
RequestHandlerManager manager = new RequestHandlerManager(coreConfig, persistence, messageBus, assetConnectionManager);
Operation operation = getTestOperation();
InvokeOperationSyncRequest invokeOperationSyncRequest = new InvokeOperationSyncRequest.Builder().requestId("1").inoutputArguments(operation.getInoutputVariables()).inputArguments(operation.getInputVariables()).id(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("http://example.org").build()).build();
InvokeOperationSyncResponse actualResponse = manager.execute(invokeOperationSyncRequest);
InvokeOperationSyncResponse expectedResponse = new InvokeOperationSyncResponse.Builder().statusCode(StatusCode.Success).payload(new OperationResult.Builder().requestId("1").inoutputArguments(List.of(new DefaultOperationVariable.Builder().value(new DefaultProperty.Builder().idShort("TestProp").value("TestOutput").build()).build())).outputArguments(operation.getInputVariables()).executionState(ExecutionState.Completed).build()).build();
Assert.assertEquals(expectedResponse, actualResponse);
}
Aggregations