Search in sources :

Example 41 with RelativePathElement

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

the class TestUtils method checkIdentifierKeyValuePairNode.

/**
 * Checks the given IdentifierKeyValuePair Node
 *
 * @param client The OPC UA Client
 * @param node The desired node
 * @param aasns The namespace index of the AAS namespace.
 * @param map The expected values
 * @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 checkIdentifierKeyValuePairNode(UaClient client, NodeId node, int aasns, Map<String, String> map) throws ServiceException, AddressSpaceException, ServiceResultException, StatusException {
    checkType(client, node, new NodeId(aasns, TestDefines.AAS_ID_KEY_VALUE_PAIR_ID));
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.ID_KEY_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.ID_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkIdentifierKeyValuePairNode Browse Result Null", bpres);
    Assert.assertTrue("checkIdentifierKeyValuePairNode Browse Result: size doesn't match", bpres.length == 2);
    // Key
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkIdentifierKeyValuePairNode Browse Key Null", targets);
    Assert.assertTrue("checkIdentifierKeyValuePairNode Browse Key empty", targets.length > 0);
    DataValue dataValue = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, dataValue.getStatusCode());
    String key = dataValue.getValue().toString();
    // Value
    targets = bpres[1].getTargets();
    Assert.assertNotNull("checkIdentifierKeyValuePairNode Browse Value Null", targets);
    Assert.assertTrue("checkIdentifierKeyValuePairNode Browse Value empty", targets.length > 0);
    dataValue = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, dataValue.getStatusCode());
    String value = dataValue.getValue().toString();
    Assert.assertTrue("Key not found in Map", map.containsKey(key));
    Assert.assertEquals("Value not equal", map.get(key), value);
}
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) 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 42 with RelativePathElement

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

the class TestUtils method checkBillOfMaterialNode.

/**
 * Searches for the BillOfMaterial 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
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
public static void checkBillOfMaterialNode(UaClient client, NodeId node, int aasns) throws ServiceException, AddressSpaceException, ServiceResultException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.BILL_OF_MATERIAL_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkBillOfMaterialNode Browse Result Null", bpres);
    Assert.assertTrue("checkBillOfMaterialNode Browse Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkBillOfMaterialNode Node Targets Null", targets);
    Assert.assertTrue("checkBillOfMaterialNode Node targets empty", targets.length > 0);
    // Currently we only check that the NodeId is not null and we have the correct type
    NodeId billNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertFalse("checkBillOfMaterialNode Node not found", NodeId.isNull(billNode));
    checkType(client, billNode, new NodeId(aasns, TestDefines.AAS_REFERENCE_LIST_ID));
}
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)

Example 43 with RelativePathElement

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

the class TestUtils method checkIdentification.

/**
 * Checks the Identification values in the given node.
 *
 * @param client The OPC UA Client.
 * @param identificationNode the desired Identification Node.
 * @param aasns The namespace index of the AAS namespace.
 * @param idType The expected IdType
 * @param id The expected ID
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private static void checkIdentification(UaClient client, NodeId identificationNode, int aasns, AASIdentifierTypeDataType idType, String id) throws ServiceException, StatusException, AddressSpaceException, ServiceResultException {
    checkType(client, identificationNode, new NodeId(aasns, TestDefines.AAS_IDENTIFIER_TYPE_ID));
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "IdType")));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "Id")));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(identificationNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkIdentification Browse Result Null", bpres);
    Assert.assertTrue("checkIdentification Browse Result: size doesn't match", bpres.length == 2);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkIdentification IdType Null", targets);
    Assert.assertTrue("checkIdentification IdType empty", targets.length > 0);
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(idType.ordinal(), value.getValue().intValue());
    targets = bpres[1].getTargets();
    Assert.assertNotNull("checkIdentification Id Null", targets);
    Assert.assertTrue("checkIdentification Id empty", targets.length > 0);
    value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(id, value.getValue().toString());
}
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) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 44 with RelativePathElement

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

the class TestUtils method checkDataSpecificationNode.

/**
 * Searches for the DataSpecification 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
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 */
public static void checkDataSpecificationNode(UaClient client, NodeId node, int aasns) throws ServiceException, ServiceResultException, AddressSpaceException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.DATA_SPECIFICATION_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkDataSpecificationNode Browse Result Null", bpres);
    Assert.assertTrue("checkDataSpecificationNode Browse Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkDataSpecificationNode Node Targets Null", targets);
    Assert.assertTrue("checkDataSpecificationNode Node targets empty", targets.length > 0);
    // Currently we only check that the NodeId is not null and we have the correct type
    NodeId dataSpecNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertFalse("checkDataSpecificationNode Node not found", NodeId.isNull(dataSpecNode));
    checkType(client, dataSpecNode, new NodeId(aasns, TestDefines.AAS_REFERENCE_LIST_ID));
}
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)

Example 45 with RelativePathElement

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

the class TestUtils method checkAssetKindNode.

/**
 * Searches for the AssetKind Node in the given Node and checks the
 * AssetKind value.
 *
 * @param client The OPC UA Client
 * @param baseNode The base node where the AssetKind Node is searched.
 * @param aasns The namespace index of the AAS namespace.
 * @param assetKind The expected AssetKind Value
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private static void checkAssetKindNode(UaClient client, NodeId baseNode, int aasns, AASAssetKindDataType assetKind) throws ServiceException, AddressSpaceException, StatusException, ServiceResultException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.ASSET_KIND_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(baseNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkAssetKindNode Browse Result Null", bpres);
    Assert.assertTrue("checkAssetKindNode Browse Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkAssetKindNode Browse Target Node Null", targets);
    Assert.assertTrue("checkAssetKindNode Browse targets empty", targets.length > 0);
    checkAssetKind(client, client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId()), assetKind);
}
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) 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