Search in sources :

Example 46 with RelativePathElement

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

the class TestUtils method checkCategoryNode.

/**
 * Searches for the Category Node in the given Node and checks the Category
 * value.
 *
 * @param client The OPC UA client
 * @param node The desired node
 * @param aasns The namespace index of the AAS namespace
 * @param category The expected category value
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
public static void checkCategoryNode(UaClient client, NodeId node, int aasns, String category) throws ServiceException, StatusException, AddressSpaceException, ServiceResultException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.CATEGORY_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("Category Result Null", bpres);
    Assert.assertTrue("Category Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("Browse Category Null", targets);
    Assert.assertTrue("Category targets empty", targets.length > 0);
    checkType(client, targets[0].getTargetId(), Identifiers.PropertyType);
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    String str = "";
    if (!value.getValue().isEmpty()) {
        str = value.getValue().toString();
    }
    Assert.assertEquals(category.isEmpty(), str.isEmpty());
    if (!category.isEmpty()) {
        Assert.assertEquals(category, 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) 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