Search in sources :

Example 6 with DataValue

use of com.prosysopc.ua.stack.builtintypes.DataValue 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 7 with DataValue

use of com.prosysopc.ua.stack.builtintypes.DataValue 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 8 with DataValue

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

the class TestUtils method writeNewValueArray.

/**
 * Writes the new value (array) into the given node and checks whether the value was written correctly.
 *
 * @param client The OPC UA Client.
 * @param writeNode The node which should be written.
 * @param oldValue The old value.
 * @param newValue The new value.
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 */
public static void writeNewValueArray(UaClient client, NodeId writeNode, AASKeyDataType[] oldValue, AASKeyDataType[] newValue) throws ServiceException, StatusException, InterruptedException {
    DataValue value = client.readValue(writeNode);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertArrayEquals("intial value not equal", oldValue, (AASKeyDataType[]) value.getValue().getValue());
    client.writeValue(writeNode, newValue);
    // wait until the write is finished completely
    Thread.sleep(WRITE_TIMEOUT);
    // read new value
    value = client.readValue(writeNode);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertArrayEquals("new value not equal", newValue, (AASKeyDataType[]) value.getValue().getValue());
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) AASKeyDataType(opc.i4aas.AASKeyDataType)

Example 9 with DataValue

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

the class TestUtils method writeNewValueIntern.

/**
 * Writes the new value into the given node and checks whether the value was written correctly.
 *
 * @param client The OPC UA Client.
 * @param writeNode The node which should be written.
 * @param oldValue The old value.
 * @param newValue The new value.
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 */
public static void writeNewValueIntern(UaClient client, NodeId writeNode, Object oldValue, Object newValue) throws ServiceException, StatusException, InterruptedException {
    DataValue value = client.readValue(writeNode);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    if (oldValue == null) {
        Assert.assertTrue("intial null value not equal", value.getValue().isEmpty());
    } else {
        Assert.assertEquals("intial value not equal", oldValue, value.getValue().getValue());
    }
    client.writeValue(writeNode, newValue);
    // wait until the write is finished completely
    Thread.sleep(WRITE_TIMEOUT);
    // read new value
    value = client.readValue(writeNode);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals("new value not equal", newValue, value.getValue().getValue());
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue)

Example 10 with DataValue

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

the class TestUtils method checkAssetKind.

/**
 * Checks the AssetKind value in the given Node. The Node must already be
 * the AssetKind Node.
 *
 * @param client The OPC UA Client
 * @param kindNode The Asset Node
 * @param modelingKind The expected Asset 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 checkAssetKind(UaClient client, NodeId kindNode, AASAssetKindDataType assetKind) throws ServiceException, AddressSpaceException, StatusException, ServiceResultException {
    checkDisplayName(client, kindNode, TestDefines.ASSET_KIND_NAME);
    checkType(client, kindNode, Identifiers.PropertyType);
    DataValue value = client.readValue(kindNode);
    Assert.assertEquals(assetKind.ordinal(), value.getValue().intValue());
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue)

Aggregations

DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)20 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)13 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)13 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)13 ArrayList (java.util.ArrayList)13 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)12 RelativePath (com.prosysopc.ua.stack.core.RelativePath)12 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)11 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)7 UaClient (com.prosysopc.ua.client.UaClient)6 Test (org.junit.Test)6 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)4 AASKeyDataType (opc.i4aas.AASKeyDataType)4 Variant (com.prosysopc.ua.stack.builtintypes.Variant)3 ReferenceDescription (com.prosysopc.ua.stack.core.ReferenceDescription)3 LangString (io.adminshell.aas.v3.model.LangString)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)2 ValueChangeEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage)2 Key (io.adminshell.aas.v3.model.Key)2