Search in sources :

Example 1 with DataValue

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

the class OpcUaEndpointTest method testPropertyChangeFromMessageBus.

/**
 * Test method to check whether the new value message from the MessageBus is
 * processed correctly
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testPropertyChangeFromMessageBus() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testPropertyChangeFromMessageBus: 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_TECH_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.MAX_ROTATION_SPEED_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("testPropertyChangeFromMessageBus Browse Result Null", bpres);
    Assert.assertTrue("testPropertyChangeFromMessageBus Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testPropertyChangeFromMessageBus Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testPropertyChangeFromMessageBus ValueType Null", targets);
    Assert.assertTrue("testPropertyChangeFromMessageBus ValueType empty", targets.length > 0);
    List<Key> keys = new ArrayList<>();
    keys.add(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value(TestDefines.SUBMODEL_TECH_DATA_NAME).build());
    keys.add(new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value(TestDefines.MAX_ROTATION_SPEED_NAME).build());
    Reference propRef = new DefaultReference.Builder().keys(keys).build();
    ValueChangeEventMessage valueChangeMessage = new ValueChangeEventMessage();
    valueChangeMessage.setElement(propRef);
    valueChangeMessage.setOldValue(PropertyValue.of(Datatype.Int, "5000"));
    Integer newValue = 5005;
    valueChangeMessage.setNewValue(PropertyValue.of(Datatype.Int, newValue.toString()));
    service.getMessageBus().publish(valueChangeMessage);
    Thread.sleep(DEFAULT_TIMEOUT);
    // read new value
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals("new value not equal", newValue, value.getValue().getValue());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) Reference(io.adminshell.aas.v3.model.Reference) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Key(io.adminshell.aas.v3.model.Key) ValueChangeEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 2 with DataValue

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

the class OpcUaEndpointTest method testUpdatePropertyValue.

/**
 * Test method for changing a property based on an event from the MessageBus. Sets an event
 * on the MessageBus and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws IOException If the operation fails
 * @throws StatusException If the operation fails
 */
@Test
public void testUpdatePropertyValue() throws SecureIdentityException, ServiceException, IOException, StatusException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testUpdatePropertyValue: 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.ROTATION_SPEED_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("testWriteProperty Browse Result Null", bpres);
    Assert.assertTrue("testWriteProperty Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteProperty Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteProperty ValueType Null", targets);
    Assert.assertTrue("testWriteProperty ValueType empty", targets.length > 0);
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Integer oldValue = 4370;
    Assert.assertEquals("intial value not equal", oldValue, value.getValue().getValue());
    CountDownLatch condition = new CountDownLatch(1);
    final AtomicReference<EventMessage> response = new AtomicReference<>();
    service.getMessageBus().subscribe(SubscriptionInfo.create(ValueChangeEventMessage.class, x -> {
        response.set(x);
        condition.countDown();
    }));
    Integer newValue = 9999;
    List<Key> keys = new ArrayList<>();
    keys.add(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value(TestDefines.SUBMODEL_OPER_DATA_NAME).build());
    keys.add(new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value(TestDefines.ROTATION_SPEED_NAME).build());
    Reference propRef = new DefaultReference.Builder().keys(keys).build();
    ValueChangeEventMessage valueChangeMessage = new ValueChangeEventMessage();
    valueChangeMessage.setElement(propRef);
    // PropertyValue propertyValue = new PropertyValue();
    // propertyValue.setValue(new IntValue(oldValue));
    valueChangeMessage.setOldValue(PropertyValue.of(Datatype.Int, oldValue.toString()));
    // propertyValue.setValue(new IntValue(newValue));
    valueChangeMessage.setNewValue(PropertyValue.of(Datatype.Int, newValue.toString()));
    service.getMessageBus().publish(valueChangeMessage);
    Thread.sleep(100);
    // check MessageBus
    condition.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
    Assert.assertEquals(valueChangeMessage, response.get());
    // read new value
    value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals("new value not equal", newValue, value.getValue().getValue());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) DefaultRelationshipElement(io.adminshell.aas.v3.model.impl.DefaultRelationshipElement) ValueChangeEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage) LoggerFactory(org.slf4j.LoggerFactory) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) ReferenceDescription(com.prosysopc.ua.stack.core.ReferenceDescription) TestUtils(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.TestUtils) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) SubscriptionInfo(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo) ServiceResultException(com.prosysopc.ua.stack.common.ServiceResultException) TestDefines(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.TestDefines) TestService(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.helper.TestService) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) SecureIdentityException(com.prosysopc.ua.SecureIdentityException) AfterClass(org.junit.AfterClass) IdentifierType(io.adminshell.aas.v3.model.IdentifierType) Reference(io.adminshell.aas.v3.model.Reference) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) ServiceException(com.prosysopc.ua.ServiceException) AASRelationshipElementType(opc.i4aas.AASRelationshipElementType) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) EventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage) Key(io.adminshell.aas.v3.model.Key) CountDownLatch(java.util.concurrent.CountDownLatch) Base64(java.util.Base64) List(java.util.List) StatusCode(com.prosysopc.ua.stack.builtintypes.StatusCode) AASKeyElementsDataType(opc.i4aas.AASKeyElementsDataType) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) AASKeyTypeDataType(opc.i4aas.AASKeyTypeDataType) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) ModelingKind(io.adminshell.aas.v3.model.ModelingKind) RelativePath(com.prosysopc.ua.stack.core.RelativePath) KeyElements(io.adminshell.aas.v3.model.KeyElements) ServerState(com.prosysopc.ua.stack.core.ServerState) AASModelingKindDataType(opc.i4aas.AASModelingKindDataType) BeforeClass(org.junit.BeforeClass) StatusException(com.prosysopc.ua.StatusException) AtomicReference(java.util.concurrent.atomic.AtomicReference) UaClient(com.prosysopc.ua.client.UaClient) ArrayList(java.util.ArrayList) AASValueTypeDataType(opc.i4aas.AASValueTypeDataType) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) KeyType(io.adminshell.aas.v3.model.KeyType) LangString(io.adminshell.aas.v3.model.LangString) VariableIds(opc.i4aas.VariableIds) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) AASEntityType(opc.i4aas.AASEntityType) Identifiers(com.prosysopc.ua.stack.core.Identifiers) DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) Logger(org.slf4j.Logger) AASKeyDataType(opc.i4aas.AASKeyDataType) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) IOException(java.io.IOException) Test(org.junit.Test) SecurityMode(com.prosysopc.ua.stack.transport.security.SecurityMode) AASIdentifierTypeDataType(opc.i4aas.AASIdentifierTypeDataType) TimeUnit(java.util.concurrent.TimeUnit) DefaultAdministrativeInformation(io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation) ConfigurationException(de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationException) AddressSpaceException(com.prosysopc.ua.client.AddressSpaceException) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) Assert(org.junit.Assert) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) ValueChangeEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) Reference(io.adminshell.aas.v3.model.Reference) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) UaClient(com.prosysopc.ua.client.UaClient) ValueChangeEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) EventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Key(io.adminshell.aas.v3.model.Key) Test(org.junit.Test)

Example 3 with DataValue

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

the class OpcUaEndpointFullTest method testOpcUaEndpointFull.

/**
 * Test method for testing the OPC UA Endpoint
 *
 * @throws InterruptedException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testOpcUaEndpointFull() throws InterruptedException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    Assert.assertTrue("client not connected", client.isConnected());
    System.out.println("client connected");
    DataValue value = client.readValue(Identifiers.Server_ServerStatus_State);
    System.out.println(value);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(ServerState.Running.ordinal(), value.getValue().intValue());
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    // browse for AAS Environment
    List<ReferenceDescription> refs = client.getAddressSpace().browse(Identifiers.ObjectsFolder);
    Assert.assertNotNull("Browse ObjectsFolder Refs Null", refs);
    Assert.assertFalse("Browse ObjectsFolder Refs empty", refs.isEmpty());
    NodeId envNode = null;
    for (ReferenceDescription ref : refs) {
        if (ref.getBrowseName().getName().equals(TestDefines.AAS_ENVIRONMENT_NAME)) {
            envNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
            break;
        }
    }
    Assert.assertNotNull("AASEnvironment Null", envNode);
    // browse AAS Environment
    refs = client.getAddressSpace().browse(envNode);
    Assert.assertNotNull("Browse Environment Refs Null", refs);
    Assert.assertTrue("Browse Environment Refs empty", !refs.isEmpty());
    NodeId submodel1Node = null;
    for (ReferenceDescription ref : refs) {
        NodeId rid = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
        switch(ref.getBrowseName().getName()) {
            case TestDefines.FULL_SUBMODEL_1_NAME:
                submodel1Node = rid;
                break;
        }
    }
    Assert.assertNotNull("Submodel 1 Node not found", submodel1Node);
    testSubmodel1(client, submodel1Node);
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) ReferenceDescription(com.prosysopc.ua.stack.core.ReferenceDescription) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaClient(com.prosysopc.ua.client.UaClient) Test(org.junit.Test)

Example 4 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 5 with DataValue

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

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