use of de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse 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.model.api.response.InvokeOperationAsyncResponse in project FAAAST-Service by FraunhoferIOSB.
the class InvokeOperationAsyncRequestHandler method process.
@Override
public InvokeOperationAsyncResponse process(InvokeOperationAsyncRequest request) {
InvokeOperationAsyncResponse response = new InvokeOperationAsyncResponse();
try {
Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
// Check if submodelelement does exist
Operation operation = (Operation) persistence.get(reference, new OutputModifier());
OperationHandle operationHandle = executeOperationAsync(reference, request);
response.setPayload(operationHandle);
response.setStatusCode(StatusCode.Success);
publishOperationInvokeEventMessage(reference, toValues(request.getInputArguments()), toValues(request.getInoutputArguments()));
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
Aggregations