Search in sources :

Example 1 with ReferenceDescription

use of com.prosysopc.ua.stack.core.ReferenceDescription in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointTest method testSubmodelDoc.

/**
 * Tests the given Submodel Documentation.
 *
 * @param client The OPC UA Client.
 * @param submodelNode The desired Submodel
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws InterruptedException Id a wait was interrupted
 */
private void testSubmodelDoc(UaClient client, NodeId submodelNode) throws ServiceException, AddressSpaceException, StatusException, ServiceResultException, InterruptedException {
    TestUtils.checkDisplayName(client, submodelNode, "Submodel:" + TestDefines.SUBMODEL_DOC_NODE_NAME);
    TestUtils.checkType(client, submodelNode, new NodeId(aasns, TestDefines.AAS_SUBMODEL_TYPE_ID));
    String submodelName = "SubmodelOperationalData";
    NodeId operatingManualNode = null;
    List<ReferenceDescription> refs = client.getAddressSpace().browse(submodelNode);
    Assert.assertNotNull("Browse " + submodelName + " Refs Null", refs);
    Assert.assertFalse("Browse " + submodelName + " Refs empty", refs.isEmpty());
    for (ReferenceDescription ref : refs) {
        NodeId nid = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
        switch(ref.getBrowseName().getName()) {
            case TestDefines.OPERATING_MANUAL_NAME:
                operatingManualNode = nid;
                break;
            default:
                break;
        }
    }
    Assert.assertNotNull(submodelName + " OperatingManual Node not found", operatingManualNode);
    TestUtils.checkIdentificationNode(client, submodelNode, aasns, AASIdentifierTypeDataType.IRI, TestDefines.SUBMODEL_DOC_NAME);
    TestUtils.checkAdministrationNode(client, submodelNode, aasns, "11", "159");
    TestUtils.checkModelingKindNode(client, submodelNode, aasns, AASModelingKindDataType.Instance);
    TestUtils.checkCategoryNode(client, submodelNode, aasns, "");
    TestUtils.checkDataSpecificationNode(client, submodelNode, aasns);
    TestUtils.checkQualifierNode(client, submodelNode, aasns, new ArrayList<>());
    testOperatingManual(client, operatingManualNode);
}
Also used : ReferenceDescription(com.prosysopc.ua.stack.core.ReferenceDescription) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString)

Example 2 with ReferenceDescription

use of com.prosysopc.ua.stack.core.ReferenceDescription in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testOpcUaEndpointFull.

/**
 * Test method for testing the OPC UA Endpoint
 *
 * @throws InterruptedException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testOpcUaEndpointFull() throws InterruptedException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    Assert.assertTrue("client not connected", client.isConnected());
    System.out.println("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());
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    // 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 submodel1Node = null;
    for (ReferenceDescription ref : refs) {
        NodeId rid = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
        switch(ref.getBrowseName().getName()) {
            case TestDefines.FULL_SUBMODEL_1_NAME:
                submodel1Node = rid;
                break;
        }
    }
    Assert.assertNotNull("Submodel 1 Node not found", submodel1Node);
    testSubmodel1(client, submodel1Node);
    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)

Example 3 with ReferenceDescription

use of com.prosysopc.ua.stack.core.ReferenceDescription in project FAAAST-Service by FraunhoferIOSB.

the class TestUtils method checkQualifierNode.

/**
 * Searches for the Qualifier Node in the given Node.
 *
 * @param client The OPC UA client
 * @param node The desired node
 * @param aasns The namespace index of the AAS namespace
 * @param qualifierList The list of qualifiers
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 */
public static void checkQualifierNode(UaClient client, NodeId node, int aasns, List<Qualifier> qualifierList) 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.QUALIFIER_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkQualifierNode Browse Result Null", bpres);
    Assert.assertTrue("checkQualifierNode Browse Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkQualifierNode Node Targets Null", targets);
    Assert.assertTrue("checkQualifierNode Node targets empty", targets.length > 0);
    // Currently we only check that the NodeId is not null and we have the correct type
    NodeId qualNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertFalse("checkQualifierNode Node not found", NodeId.isNull(qualNode));
    checkType(client, qualNode, new NodeId(aasns, TestDefines.AAS_QUALIFIER_LIST_ID));
    List<AASQualifierType> nodeList = new ArrayList<>();
    List<ReferenceDescription> refs = client.getAddressSpace().browse(qualNode);
    for (ReferenceDescription ref : refs) {
        NodeId nid = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
        checkType(client, nid, new NodeId(aasns, TestDefines.AAS_QUALIFIER_TYPE_ID));
        UaNode qnode = client.getAddressSpace().getNode(nid);
        if (qnode instanceof AASQualifierType) {
            nodeList.add((AASQualifierType) qnode);
        }
    }
    checkQualifierList(qualifierList, nodeList);
// Assert.assertArrayEquals(qualifierList.toArray(), nodeList.toArray());
}
Also used : AASQualifierType(opc.i4aas.AASQualifierType) 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) UaNode(com.prosysopc.ua.nodes.UaNode) ReferenceDescription(com.prosysopc.ua.stack.core.ReferenceDescription) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 4 with ReferenceDescription

use of com.prosysopc.ua.stack.core.ReferenceDescription in project FAAAST-Service by FraunhoferIOSB.

the class TestUtils method checkSubmodelRef.

/**
 * Searches for the Submodel reference Node with the given name
 *
 * @param client The OPC UA Client
 * @param baseNode The base node where the AssetInformation Node is
 *            searched.
 * @param aasns The namespace index of the AAS namespace.
 * @param name The name of the desired Node
 * @param submodelNode The Submodel 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
 */
public static void checkSubmodelRef(UaClient client, NodeId baseNode, int aasns, String name, NodeId submodelNode) 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, name)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(baseNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkSubmodelRef Browse Result Null", bpres);
    Assert.assertTrue("checkSubmodelRef Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("checkSubmodelRef Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkSubmodelRef Target Null", targets);
    Assert.assertTrue("checkSubmodelRef Target empty", targets.length > 0);
    NodeId refNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("checkSubmodelRef RefNode Null", refNode);
    checkType(client, refNode, new NodeId(aasns, TestDefines.AAS_REFERENCE_TYPE_ID));
    // check AAS Reference
    List<AASKeyDataType> refKeys = new ArrayList<>();
    refKeys.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, name, AASKeyTypeDataType.IRI));
    checkAasReference(client, refNode, aasns, refKeys);
    // check Reference to Submodel
    List<ReferenceDescription> refs = client.getAddressSpace().browse(refNode, BrowseDirection.Forward, Identifiers.HasAddIn);
    Assert.assertEquals(1, refs.size());
    NodeId smNode = client.getAddressSpace().getNamespaceTable().toNodeId(refs.get(0).getNodeId());
    Assert.assertEquals(smNode, submodelNode);
}
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) AASKeyDataType(opc.i4aas.AASKeyDataType) ReferenceDescription(com.prosysopc.ua.stack.core.ReferenceDescription) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 5 with ReferenceDescription

use of com.prosysopc.ua.stack.core.ReferenceDescription 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)6 ReferenceDescription (com.prosysopc.ua.stack.core.ReferenceDescription)6 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)3 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)3 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)3 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)3 RelativePath (com.prosysopc.ua.stack.core.RelativePath)3 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)3 ArrayList (java.util.ArrayList)3 UaClient (com.prosysopc.ua.client.UaClient)2 DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)2 Test (org.junit.Test)2 UaNode (com.prosysopc.ua.nodes.UaNode)1 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)1 LangString (io.adminshell.aas.v3.model.LangString)1 AASKeyDataType (opc.i4aas.AASKeyDataType)1 AASQualifierType (opc.i4aas.AASQualifierType)1