Search in sources :

Example 46 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testCallOperationSuccess.

/**
 * Test method for successfully calling an operation.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws MethodCallStatusException If the operation fails
 */
@Test
public void testCallOperationSuccess() throws SecureIdentityException, IOException, ServiceException, ServiceResultException, MethodCallStatusException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    int serverns = client.getAddressSpace().getNamespaceTable().getIndex(AasServiceNodeManager.NAMESPACE_URI);
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_3_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_3_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(serverns, TestDefines.FULL_OPERATION_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testCallOperationSuccess Browse Result Null", bpres);
    Assert.assertEquals("testCallOperationSuccess Browse Result: size doesn't match", 2, bpres.length);
    Assert.assertTrue("testCallOperationSuccess Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testCallOperationSuccess Object Targets Null", targets);
    Assert.assertTrue("testCallOperationSuccess Object Targets empty", targets.length > 0);
    NodeId objectNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("testCallOperationSuccess objectNode Null", objectNode);
    targets = bpres[1].getTargets();
    Assert.assertNotNull("testCallOperationSuccess Method Targets Null", targets);
    Assert.assertTrue("testCallOperationSuccess Method Targets empty", targets.length > 0);
    NodeId methodNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("testCallOperationSuccess methodNode Null", methodNode);
    Variant[] inputArguments = new Variant[1];
    inputArguments[0] = new Variant("123454");
    Variant[] outputs = client.call(objectNode, methodNode, inputArguments);
    Assert.assertNotNull("testCallOperationSuccess output Arguments Null", outputs);
    Assert.assertEquals("testCallOperationSuccess output Arguments length not equal", 1, outputs.length);
    Assert.assertEquals("testCallOperationSuccess output Argument 0 not equal", new Variant("XYZ1"), outputs[0]);
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) UaClient(com.prosysopc.ua.client.UaClient) Variant(com.prosysopc.ua.stack.builtintypes.Variant) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 47 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointTest method testSubmodelRefs.

/**
 * Searches for the Submodel reference node and checks the corresponding
 * values
 *
 * @param client The OPC UA Client.
 * @param baseNode The base node where the Node is searched.
 * @param aasns The namespace index of the AAS namespace.
 * @param submodelDocNode The Submodel Documentation Node
 * @param submodelOperDataNode The Submodel OperationalData Node
 * @param submodelTechDataNode The Submodel TechnicalData Node
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 */
private void testSubmodelRefs(UaClient client, NodeId baseNode, int aasns, NodeId submodelDocNode, NodeId submodelOperDataNode, NodeId submodelTechDataNode) throws ServiceException, ServiceResultException, AddressSpaceException, StatusException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_REF_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(baseNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testSubmodelRefs Browse Result Null", bpres);
    Assert.assertTrue("testSubmodelRefs Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testSubmodelRefs Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testSubmodelRefs Target Null", targets);
    Assert.assertTrue("testSubmodelRefs Target empty", targets.length > 0);
    NodeId refNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("testSubmodelRefs RefNode Null", refNode);
    TestUtils.checkType(client, refNode, new NodeId(aasns, TestDefines.AAS_REFERENCE_LIST_ID));
    TestUtils.checkSubmodelRef(client, refNode, aasns, TestDefines.SUBMODEL_DOC_NAME, submodelDocNode);
    TestUtils.checkSubmodelRef(client, refNode, aasns, TestDefines.SUBMODEL_OPER_DATA_NAME, submodelOperDataNode);
    TestUtils.checkSubmodelRef(client, refNode, aasns, TestDefines.SUBMODEL_TECH_DATA_NAME, submodelTechDataNode);
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 48 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointTest method testWriteBlobValue.

/**
 * Test method for writing a range. Writes the property in the OPC UA Server
 * and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWriteBlobValue() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testWriteBlobValue: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_BLOB_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteBlobValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteBlobValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteBlobValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteBlobValue ValueType Null", targets);
    Assert.assertTrue("testWriteBlobValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    // byte[] oldValue = Base64.getDecoder().decode("AQIDBAU=");
    ByteString oldValue = ByteString.valueOf(Base64.getDecoder().decode("AQIDBAU="));
    ByteString newValue = ByteString.valueOf(Base64.getDecoder().decode("QUJDREU="));
    TestUtils.writeNewValueIntern(client, writeNode, oldValue, newValue);
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 49 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointTest method testWritePropertyValue.

/**
 * Test method for writing a property. Writes the property in the OPC UA
 * Server and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWritePropertyValue() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testWritePropertyValue: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_PROPERTY_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWritePropertyValue Browse Result Null", bpres);
    Assert.assertTrue("testWritePropertyValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWritePropertyValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWritePropertyValue ValueType Null", targets);
    Assert.assertTrue("testWritePropertyValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    TestUtils.writeNewValueIntern(client, writeNode, 50, 222);
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaClient(com.prosysopc.ua.client.UaClient) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 50 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointTest method testOpcUaEndpoint.

/**
 * Test method for testing the OPC UA Endpoint
 *
 * @throws InterruptedException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testOpcUaEndpoint() throws InterruptedException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testOpcUaEndpoint: client connected");
    DataValue value = client.readValue(Identifiers.Server_ServerStatus_State);
    System.out.println(value);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(ServerState.Running.ordinal(), value.getValue().intValue());
    // browse for AAS Environment
    List<ReferenceDescription> refs = client.getAddressSpace().browse(Identifiers.ObjectsFolder);
    Assert.assertNotNull("Browse ObjectsFolder Refs Null", refs);
    Assert.assertFalse("Browse ObjectsFolder Refs empty", refs.isEmpty());
    NodeId envNode = null;
    for (ReferenceDescription ref : refs) {
        if (ref.getBrowseName().getName().equals(TestDefines.AAS_ENVIRONMENT_NAME)) {
            envNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
            break;
        }
    }
    Assert.assertNotNull("AASEnvironment Null", envNode);
    // browse AAS Environment
    refs = client.getAddressSpace().browse(envNode);
    Assert.assertNotNull("Browse Environment Refs Null", refs);
    Assert.assertTrue("Browse Environment Refs empty", !refs.isEmpty());
    NodeId aasNode = null;
    NodeId assetNode = null;
    NodeId submodelDocNode = null;
    NodeId submodelTechDataNode = null;
    NodeId submodelOperDataNode = null;
    for (ReferenceDescription ref : refs) {
        switch(ref.getBrowseName().getName()) {
            case TestDefines.SIMPLE_AAS_NAME:
                aasNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
                break;
            case TestDefines.SIMPLE_ASSET_NAME:
                assetNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
                break;
            case TestDefines.SUBMODEL_DOC_NODE_NAME:
                submodelDocNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
                break;
            case TestDefines.SUBMODEL_OPER_DATA_NODE_NAME:
                submodelOperDataNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
                break;
            case TestDefines.SUBMODEL_TECH_DATA_NODE_NAME:
                submodelTechDataNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
                break;
            default:
                break;
        }
    }
    Assert.assertNotNull("AAS Node not found", aasNode);
    Assert.assertNotNull("Asset Node not found", assetNode);
    Assert.assertNotNull("Submodel Documentation Node not found", submodelDocNode);
    Assert.assertNotNull("Submodel TechnicalData Node not found", submodelTechDataNode);
    Assert.assertNotNull("Submodel OperationalData Node not found", submodelOperDataNode);
    // check Browse and Display Names
    TestUtils.checkBrowseName(client, aasNode, TestDefines.SIMPLE_AAS_NAME);
    TestUtils.checkDisplayName(client, aasNode, "AAS:" + TestDefines.SIMPLE_AAS_NAME);
    TestUtils.checkDisplayName(client, submodelDocNode, "Submodel:" + TestDefines.SUBMODEL_DOC_NODE_NAME);
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    // Asset
    testAsset(client, assetNode);
    // Submodels
    testSubmodelDoc(client, submodelDocNode);
    testSubmodelOperationalData(client, submodelOperDataNode);
    testSubmodelTechnicalData(client, submodelTechDataNode);
    // AAS
    refs = client.getAddressSpace().browse(aasNode);
    Assert.assertNotNull("Browse AASNode Refs Null", refs);
    Assert.assertFalse("Browse AASNode Refs empty", refs.isEmpty());
    testAas(client, aasNode, submodelDocNode, submodelOperDataNode, submodelTechDataNode);
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) ReferenceDescription(com.prosysopc.ua.stack.core.ReferenceDescription) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaClient(com.prosysopc.ua.client.UaClient) Test(org.junit.Test)

Aggregations

NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)79 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)59 StatusException (com.prosysopc.ua.StatusException)37 ServiceException (com.prosysopc.ua.ServiceException)35 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)35 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)35 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)35 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)35 ArrayList (java.util.ArrayList)33 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)32 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)32 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)31 RelativePath (com.prosysopc.ua.stack.core.RelativePath)31 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)29 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)27 LangString (io.adminshell.aas.v3.model.LangString)27 UaClient (com.prosysopc.ua.client.UaClient)19 Test (org.junit.Test)19 Reference (io.adminshell.aas.v3.model.Reference)17 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)17