Search in sources :

Example 1 with RequestHandlerManager

use of de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager 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);
}
Also used : CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) DefaultOperation(io.adminshell.aas.v3.model.impl.DefaultOperation) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) InvokeOperationAsyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationAsyncRequest) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) InvokeOperationAsyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse) Test(org.junit.Test)

Example 2 with RequestHandlerManager

use of de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager 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);
}
Also used : Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) AssetValueProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetValueProvider) Before(org.junit.Before)

Example 3 with RequestHandlerManager

use of de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager in project FAAAST-Service by FraunhoferIOSB.

the class Service method init.

private void init() throws ConfigurationException {
    if (config.getPersistence() == null) {
        throw new InvalidConfigurationException("config.persistence must be non-null");
    }
    persistence = (Persistence) config.getPersistence().newInstance(config.getCore(), this);
    if (config.getMessageBus() == null) {
        throw new InvalidConfigurationException("config.messagebus must be non-null");
    }
    messageBus = (MessageBus) config.getMessageBus().newInstance(config.getCore(), this);
    if (config.getAssetConnections() != null) {
        List<AssetConnection> assetConnections = new ArrayList<>();
        for (AssetConnectionConfig assetConnectionConfig : config.getAssetConnections()) {
            assetConnections.add((AssetConnection) assetConnectionConfig.newInstance(config.getCore(), this));
        }
        assetConnectionManager = new AssetConnectionManager(config.getCore(), assetConnections, this);
    }
    if (config.getEndpoints() == null || config.getEndpoints().isEmpty()) {
        // TODO maybe be less restrictive and only print warning
        // throw new InvalidConfigurationException("at least endpoint must be defined in the configuration");
        logger.warn("no endpoint configuration found, starting service without endpoint which means the service will not be accessible via any kind of API");
    } else {
        endpoints = new ArrayList<>();
        for (EndpointConfig endpointConfig : config.getEndpoints()) {
            Endpoint endpoint = (Endpoint) endpointConfig.newInstance(config.getCore(), this);
            endpoints.add(endpoint);
        }
    }
    this.requestHandler = new RequestHandlerManager(this.config.getCore(), this.persistence, this.messageBus, this.assetConnectionManager);
}
Also used : AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) Endpoint(de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) ArrayList(java.util.ArrayList) AssetConnectionConfig(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig) EndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig) InvalidConfigurationException(de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException) AssetConnection(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)

Example 4 with RequestHandlerManager

use of de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager 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);
}
Also used : CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) InvokeOperationSyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) DefaultOperation(io.adminshell.aas.v3.model.impl.DefaultOperation) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) Test(org.junit.Test)

Aggregations

AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)4 RequestHandlerManager (de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager)4 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)3 Persistence (de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence)3 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)2 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)2 Operation (io.adminshell.aas.v3.model.Operation)2 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)2 DefaultOperation (io.adminshell.aas.v3.model.impl.DefaultOperation)2 Test (org.junit.Test)2 AssetConnection (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)1 AssetConnectionConfig (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionConfig)1 AssetOperationProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider)1 AssetValueProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetValueProvider)1 Endpoint (de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint)1 EndpointConfig (de.fraunhofer.iosb.ilt.faaast.service.endpoint.EndpointConfig)1 InvalidConfigurationException (de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException)1 OperationHandle (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle)1 InvokeOperationAsyncResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse)1 InvokeOperationSyncResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse)1