Search in sources :

Example 11 with BrowsePathTarget

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

the class OpcUaEndpointTest method testWriteReferenceElementValue.

/**
 * Test method for writing a property. Writes the property in the OPC UA
 * Server and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWriteReferenceElementValue() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_REF_ELEM_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.KEYS_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteReferenceElementValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteReferenceElementValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteReferenceElementValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteReferenceElementValue ValueType Null", targets);
    Assert.assertTrue("testWriteReferenceElementValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    List<AASKeyDataType> oldValue = new ArrayList<>();
    oldValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, TestDefines.SUBMODEL_TECH_DATA_NAME, AASKeyTypeDataType.IRI));
    oldValue.add(new AASKeyDataType(AASKeyElementsDataType.Property, TestDefines.MAX_ROTATION_SPEED_NAME, AASKeyTypeDataType.IdShort));
    // The DataElementValueMapper changes the order of the elements
    List<AASKeyDataType> newValue = new ArrayList<>();
    newValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, TestDefines.SUBMODEL_TECH_DATA_NAME, AASKeyTypeDataType.IRI));
    newValue.add(new AASKeyDataType(AASKeyElementsDataType.Property, "Another property", AASKeyTypeDataType.IdShort));
    TestUtils.writeNewValueArray(client, writeNode, oldValue.toArray(AASKeyDataType[]::new), newValue.toArray(AASKeyDataType[]::new));
    System.out.println("testWriteReferenceElementValue: disconnect client");
    client.disconnect();
}
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) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 12 with BrowsePathTarget

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

the class OpcUaEndpointTest method testWriteEntityPropertyValue.

/**
 * Test method for writing a property of an entity. Writes the property in
 * the OPC UA Server and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWriteEntityPropertyValue() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testWriteEntityPropertyValue: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_ENTITY_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, AASEntityType.STATEMENT)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_ENTITY_PROPERTY_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteEntityPropertyValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteEntityPropertyValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteEntityPropertyValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteEntityPropertyValue ValueType Null", targets);
    Assert.assertTrue("testWriteEntityPropertyValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    TestUtils.writeNewValueIntern(client, writeNode, "http://acplt.org/ValueId/ExampleValueId", "http://acplt.org/ValueId/AnotherValue");
    System.out.println("disconnect client");
    client.disconnect();
}
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) UaClient(com.prosysopc.ua.client.UaClient) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 13 with BrowsePathTarget

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

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

use of com.prosysopc.ua.stack.core.BrowsePathTarget 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)

Aggregations

QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)40 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)40 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)40 ArrayList (java.util.ArrayList)40 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)39 RelativePath (com.prosysopc.ua.stack.core.RelativePath)39 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)33 UaClient (com.prosysopc.ua.client.UaClient)20 Test (org.junit.Test)20 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)14 DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)13 AASKeyDataType (opc.i4aas.AASKeyDataType)9 Variant (com.prosysopc.ua.stack.builtintypes.Variant)5 ReferenceDescription (com.prosysopc.ua.stack.core.ReferenceDescription)4 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)4 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)3 LangString (io.adminshell.aas.v3.model.LangString)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 StatusException (com.prosysopc.ua.StatusException)2 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)2