use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandler method publishValueChangeEventMessage.
/**
* Publish a ValueChangeEventMessage to the message bus
*
* @param reference of the element
* @param oldValue the value of the element before the change
* @param newValue the new value of the element
*/
public void publishValueChangeEventMessage(Reference reference, ElementValue oldValue, ElementValue newValue) {
ValueChangeEventMessage eventMessage = new ValueChangeEventMessage();
eventMessage.setElement(reference);
eventMessage.setOldValue(oldValue);
eventMessage.setNewValue(newValue);
try {
this.messageBus.publish(eventMessage);
} catch (Exception e) {
e.printStackTrace();
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage in project FAAAST-Service by FraunhoferIOSB.
the class MessageBusInternalTest method init.
@BeforeClass
public static void init() {
valueChangeMessage = new ValueChangeEventMessage();
PropertyValue propertyValue = new PropertyValue();
propertyValue.setValue(new IntValue(100));
valueChangeMessage.setOldValue(propertyValue);
propertyValue.setValue(new IntValue(123));
valueChangeMessage.setNewValue(propertyValue);
errorMessage = new ErrorEventMessage();
errorMessage.setElement(property1Reference);
errorMessage.setErrorLevel(ErrorLevel.Error);
errorMessage.setThrowingSource(MessageBusInternalTest.class);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage 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();
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage 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();
}
Aggregations