Search in sources :

Example 16 with RelativePathElement

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

the class TestUtils method checkAasReference.

/**
 * Checks the given Reference Node
 *
 * @param client The OPC UA Client
 * @param node The desired Node
 * @param aasns The namespace index of the AAS namespace.
 * @param refKeys The expected list of Keys
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws StatusException If the operation fails
 */
private static void checkAasReference(UaClient client, NodeId node, int aasns, List<AASKeyDataType> refKeys) throws ServiceException, AddressSpaceException, ServiceResultException, StatusException {
    checkType(client, node, new NodeId(aasns, TestDefines.AAS_REFERENCE_TYPE_ID));
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, "Keys")));
    BrowsePathTarget[] targetsProp = client.getAddressSpace().translateBrowsePathToNodeId(node, browsePath.toArray(RelativePathElement[]::new));
    Assert.assertNotNull("Property Keys Null", targetsProp);
    Assert.assertTrue("Property Keys empty", targetsProp.length > 0);
    checkType(client, targetsProp[0].getTargetId(), Identifiers.PropertyType);
    UaVariable variable = (UaVariable) client.getAddressSpace().getNode(targetsProp[0].getTargetId());
    UaType dataType = variable.getDataType();
    Assert.assertNotNull("DataType null", dataType);
    Assert.assertEquals("DataType not equal", new NodeId(aasns, TestDefines.AAS_KEY_DATA_TYPE_ID), dataType.getNodeId());
    DataValue value = client.readValue(targetsProp[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertNotNull("Value null", value.getValue());
    Variant var = value.getValue();
    Object o = var.getValue();
    Assert.assertTrue("Keys no array", var.isArray());
    // Assert.assertEquals(AASKeyDataType.class, o.getClass());
    AASKeyDataType[] arr = (AASKeyDataType[]) o;
    Assert.assertEquals(refKeys.size(), arr.length);
    Assert.assertArrayEquals(refKeys.toArray(), arr);
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) UaVariable(com.prosysopc.ua.nodes.UaVariable) ArrayList(java.util.ArrayList) UaType(com.prosysopc.ua.nodes.UaType) AASKeyDataType(opc.i4aas.AASKeyDataType) Variant(com.prosysopc.ua.stack.builtintypes.Variant) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 17 with RelativePathElement

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

the class TestUtils method checkAasPropertyObject.

/**
 * Checks the String Property with the given Name
 *
 * @param client The OPC UA Client
 * @param node The Node where the desired property is located
 * @param aasns The namespace index of the AAS namespace
 * @param name The name of the desired property
 * @param kind The expected ModelingKind
 * @param category The expected Category
 * @param valueType The expected ValueType
 * @param propValue The expected Value
 * @param qualifierList The list of qualifiers
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
public static void checkAasPropertyObject(UaClient client, NodeId node, int aasns, String name, AASModelingKindDataType kind, String category, AASValueTypeDataType valueType, Object propValue, List<Qualifier> qualifierList) throws ServiceException, AddressSpaceException, StatusException, ServiceResultException {
    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(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkAasPropertyString Browse Property Result Null", bpres);
    Assert.assertTrue("checkAasPropertyString Browse Property Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkAasPropertyString Property Null", targets);
    Assert.assertTrue("checkAasPropertyString Property empty", targets.length > 0);
    NodeId propertyNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    checkDisplayName(client, propertyNode, name);
    checkCategoryNode(client, propertyNode, aasns, category);
    checkModelingKindNode(client, propertyNode, aasns, kind);
    checkDataSpecificationNode(client, propertyNode, aasns);
    checkQualifierNode(client, propertyNode, aasns, qualifierList);
    relPath.clear();
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_TYPE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(propertyNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkAasPropertyString Browse Value & Type Result Null", bpres);
    Assert.assertTrue("checkAasPropertyString Browse Value & Type Result: size doesn't match", bpres.length == 2);
    targets = bpres[0].getTargets();
    Assert.assertNotNull("checkAasPropertyString ValueType Null", targets);
    Assert.assertTrue("checkAasPropertyString ValueType empty", targets.length > 0);
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(valueType.ordinal(), value.getValue().intValue());
    targets = bpres[1].getTargets();
    Assert.assertNotNull("checkAasPropertyString Value Null", targets);
    Assert.assertTrue("checkAasPropertyString value empty", targets.length > 0);
    value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Variant var = new Variant(propValue);
    Assert.assertEquals(var, value.getValue());
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) Variant(com.prosysopc.ua.stack.builtintypes.Variant) 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 18 with RelativePathElement

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

the class TestUtils method checkAdministrationNode.

/**
 * Searches for the Administration Node in the given Node and checks the
 * corresponding values.
 *
 * @param client The OPC UA Client
 * @param baseNode The base node where the Administration Node is searched.
 * @param aasns The namespace index of the AAS namespace.
 * @param version The expected version
 * @param revision The expected revision
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 */
public static void checkAdministrationNode(UaClient client, NodeId baseNode, int aasns, String version, String revision) throws ServiceException, StatusException, ServiceResultException, AddressSpaceException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.ADMINISTRATION_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(baseNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkAdministrationNode Browse(1) Result Null", bpres);
    Assert.assertTrue("checkAdministrationNode Browse(1) Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkAdministrationNode Browse Administration Node Null", targets);
    Assert.assertTrue("checkAdministrationNode Browse Administration targets empty", targets.length > 0);
    NodeId administrationNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    checkType(client, administrationNode, new NodeId(aasns, TestDefines.AAS_ADMIN_INFO_TYPE_ID));
    Assert.assertNotNull(administrationNode);
    Assert.assertNotEquals(NodeId.NULL, administrationNode);
    relPath.clear();
    int size = 0;
    if (version != null) {
        browsePath.clear();
        browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.VERSION_NAME)));
        relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
        size++;
    }
    if (revision != null) {
        browsePath.clear();
        browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.REVISION_NAME)));
        relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
        size++;
    }
    if (size > 0) {
        bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(administrationNode, relPath.toArray(RelativePath[]::new));
        Assert.assertNotNull("checkAdministrationNode Browse(2) Result Null", bpres);
        Assert.assertTrue("checkAdministrationNode Browse(2) Result: size doesn't match", bpres.length == size);
        int index = 0;
        if (version != null) {
            targets = bpres[index].getTargets();
            Assert.assertNotNull("checkAdministrationNode Browse Version Node Null", targets);
            Assert.assertTrue("checkAdministrationNode Browse Version targets empty", targets.length > 0);
            DataValue value = client.readValue(targets[0].getTargetId());
            Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
            Assert.assertEquals(version, value.getValue().toString());
            index++;
        }
        if (revision != null) {
            targets = bpres[index].getTargets();
            Assert.assertNotNull("checkAdministrationNode Browse Revision Node Null", targets);
            Assert.assertTrue("checkAdministrationNode Browse Revision targets empty", targets.length > 0);
            DataValue value = client.readValue(targets[0].getTargetId());
            Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
            Assert.assertEquals(revision, value.getValue().toString());
            index++;
        }
    }
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) 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) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 19 with RelativePathElement

use of com.prosysopc.ua.stack.core.RelativePathElement 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 20 with RelativePathElement

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

the class TestUtils method checkAasReferenceNode.

/**
 * Searches for a Reference Node with the given Name and checks the
 * corresponding values.
 *
 * @param client The OPC UA Client
 * @param baseNode The base node where the Reference Node is searched.
 * @param aasns The namespace index of the AAS namespace.
 * @param name The desired Name
 * @param refKeys The expected list of Keys
 * @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 static void checkAasReferenceNode(UaClient client, NodeId baseNode, int aasns, String name, List<AASKeyDataType> refKeys) 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("checkAasReferenceNode Browse Result Null", bpres);
    Assert.assertTrue("checkAasReferenceNode Browse Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkAasReferenceNode Browse Target Node Null", targets);
    Assert.assertTrue("checkAasReferenceNode Browse targets empty", targets.length > 0);
    NodeId refNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("checkAasReferenceNode Ref Node Null", refNode);
    Assert.assertNotEquals("checkAasReferenceNode Ref Node Null", NodeId.NULL, refNode);
    checkAasReference(client, refNode, aasns, refKeys);
}
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) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Aggregations

QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)46 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)46 ArrayList (java.util.ArrayList)46 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)45 RelativePath (com.prosysopc.ua.stack.core.RelativePath)45 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)40 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)33 UaClient (com.prosysopc.ua.client.UaClient)26 Test (org.junit.Test)26 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)14 DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)13 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)10 AASKeyDataType (opc.i4aas.AASKeyDataType)9 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)7 Variant (com.prosysopc.ua.stack.builtintypes.Variant)5 LangString (io.adminshell.aas.v3.model.LangString)5 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)4 ReferenceDescription (com.prosysopc.ua.stack.core.ReferenceDescription)4 ElementCreateEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage)4 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)3