Search in sources :

Example 6 with BrowsePathTarget

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

the class OpcUaEndpointFullTest method testWriteSubmodelElementCollectionValue3.

/**
 * Test method for writing a Value of a SubmodelElementCollection. 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 testWriteSubmodelElementCollectionValue3() 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.FULL_SUBMODEL_7_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SM_ELEM_COLL_O_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_MULTI_LAN_PROP_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("testWriteMultiLanguagePropertyValue Browse Result Null", bpres);
    Assert.assertEquals("testWriteMultiLanguagePropertyValue Browse Result: size doesn't match", 1, bpres.length);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteMultiLanguagePropertyValue ValueType Null", targets);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    // The DataElementValueMapper changes the order of the elements in some cases
    List<LocalizedText> newValue = new ArrayList<>();
    newValue.add(new LocalizedText("english test element", "en-us"));
    newValue.add(new LocalizedText("deutsches Test-Element", "de"));
    TestUtils.writeNewValueArray(client, writeNode, new ArrayList<>().toArray(LocalizedText[]::new), newValue.toArray(LocalizedText[]::new));
    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) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) 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 7 with BrowsePathTarget

use of com.prosysopc.ua.stack.core.BrowsePathTarget 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) ServerSocket(java.net.ServerSocket) 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 8 with BrowsePathTarget

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

the class OpcUaEndpointTest method testWriteMultiLanguagePropertyValue.

/**
 * 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 testWriteMultiLanguagePropertyValue() 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("testWriteMultiLanguagePropertyValue: 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_MULTI_LAN_PROP_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("testWriteMultiLanguagePropertyValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteMultiLanguagePropertyValue ValueType Null", targets);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    List<LocalizedText> oldValue = new ArrayList<>();
    oldValue.add(new LocalizedText("Example value of a MultiLanguageProperty element", "en-us"));
    oldValue.add(new LocalizedText("Beispielswert für ein MulitLanguageProperty-Element", "de"));
    // The DataElementValueMapper changes the order of the elements in some cases
    List<LocalizedText> newValue = new ArrayList<>();
    newValue.add(new LocalizedText("Beispielswert2 fuer ein anderes MulitLanguageProperty-Element", "de"));
    newValue.add(new LocalizedText("Example value of a MultiLanguageProperty element", "en-us"));
    TestUtils.writeNewValueArray(client, writeNode, oldValue.toArray(LocalizedText[]::new), newValue.toArray(LocalizedText[]::new));
    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) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) 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 9 with BrowsePathTarget

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

the class OpcUaEndpointTest method testWriteEntityType.

/**
 * Test method for writing the type 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 testWriteEntityType() 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("testWriteEntityType: 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.HasProperty, false, true, new QualifiedName(aasns, AASEntityType.ENTITY_TYPE)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteEntityType Browse Result Null", bpres);
    Assert.assertTrue("testWriteEntityType Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteEntityType Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteEntityType ValueType Null", targets);
    Assert.assertTrue("testWriteEntityType ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    TestUtils.writeNewValueIntern(client, writeNode, 0, 1);
    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 10 with BrowsePathTarget

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

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