Search in sources :

Example 1 with CoreConfig

use of de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig 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 CoreConfig

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

the class OpcUaEndpoint2Test method startTest.

/**
 * Initialize and start the test.
 *
 * @throws ConfigurationException If the operation fails
 * @throws Exception If the operation fails
 */
@BeforeClass
public static void startTest() throws ConfigurationException, Exception {
    logger.trace("startTest");
    CoreConfig coreConfig = new CoreConfig();
    OpcUaEndpointConfig config = new OpcUaEndpointConfig();
    config.setTcpPort(OPC_TCP_PORT);
    config.setSecondsTillShutdown(0);
    endpoint = new OpcUaEndpoint();
    service = new TestService(endpoint, null, false);
    endpoint.init(coreConfig, config, service);
    service.start();
}
Also used : CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) TestService(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.TestService) BeforeClass(org.junit.BeforeClass)

Example 3 with CoreConfig

use of de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig 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)

Example 4 with CoreConfig

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

the class OpcUaEndpointTest method startTest.

/**
 * Initialize and start the test.
 *
 * @throws ConfigurationException If the operation fails
 * @throws Exception If the operation fails
 */
@BeforeClass
public static void startTest() throws ConfigurationException, Exception {
    CoreConfig coreConfig = new CoreConfig();
    OpcUaEndpointConfig config = new OpcUaEndpointConfig();
    config.setTcpPort(OPC_TCP_PORT);
    config.setSecondsTillShutdown(0);
    endpoint = new OpcUaEndpoint();
    service = new TestService(endpoint, null, false);
    endpoint.init(coreConfig, config, service);
    service.start();
}
Also used : CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) TestService(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.TestService) BeforeClass(org.junit.BeforeClass)

Example 5 with CoreConfig

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

the class OpcUaEndpointFullTest method startTest.

/**
 * Initialize and start the test.
 *
 * @throws Exception If the operation fails
 */
@BeforeClass
public static void startTest() throws Exception {
    CoreConfig coreConfig = new CoreConfig();
    OpcUaEndpointConfig config = new OpcUaEndpointConfig();
    config.setTcpPort(OPC_TCP_PORT);
    config.setSecondsTillShutdown(0);
    AssetConnection assetConnection = new TestAssetConnection();
    // register Test Operation
    List<Key> keys = new ArrayList<>();
    keys.add(new DefaultKey.Builder().type(KeyElements.SUBMODEL).idType(KeyType.IRI).value("https://acplt.org/Test_Submodel3").build());
    keys.add(new DefaultKey.Builder().type(KeyElements.OPERATION).idType(KeyType.ID_SHORT).value("ExampleOperation").build());
    Reference ref = new DefaultReference.Builder().keys(keys).build();
    List<OperationVariable> outputArgs = new ArrayList<>();
    outputArgs.add(new DefaultOperationVariable.Builder().value(new DefaultProperty.Builder().idShort("Test Output 1").valueType("string").value("XYZ1").build()).build());
    assetConnection.registerOperationProvider(ref, new TestOperationProviderConfig(outputArgs));
    endpoint = new OpcUaEndpoint();
    service = new TestService(endpoint, assetConnection, true);
    endpoint.init(coreConfig, config, service);
    service.start();
}
Also used : TestAssetConnection(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.assetconnection.TestAssetConnection) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) TestOperationProviderConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.assetconnection.TestOperationProviderConfig) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) TestService(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.TestService) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) ArrayList(java.util.ArrayList) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) AssetConnection(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection) TestAssetConnection(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.assetconnection.TestAssetConnection) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Key(io.adminshell.aas.v3.model.Key) BeforeClass(org.junit.BeforeClass)

Aggregations

CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)6 TestService (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.TestService)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.Test)3 AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)2 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)2 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)2 Persistence (de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence)2 RequestHandlerManager (de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager)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 DefaultOperationVariable (io.adminshell.aas.v3.model.impl.DefaultOperationVariable)2 AssetConnection (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)1 AssetOperationProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider)1 ServiceConfig (de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig)1 TestAssetConnection (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.assetconnection.TestAssetConnection)1 TestOperationProviderConfig (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.assetconnection.TestOperationProviderConfig)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