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();
}
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();
}
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();
}
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++;
}
}
}
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);
}
Aggregations