use of com.prosysopc.ua.stack.builtintypes.DataValue 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());
}
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 writeNewValueArray.
/**
* Writes the new value (array) into the given node and checks whether the value was written correctly.
*
* @param client The OPC UA Client.
* @param writeNode The node which should be written.
* @param oldValue The old value.
* @param newValue The new value.
* @throws ServiceException If the operation fails
* @throws StatusException If the operation fails
* @throws InterruptedException If the operation fails
*/
public static void writeNewValueArray(UaClient client, NodeId writeNode, AASKeyDataType[] oldValue, AASKeyDataType[] newValue) throws ServiceException, StatusException, InterruptedException {
DataValue value = client.readValue(writeNode);
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertArrayEquals("intial value not equal", oldValue, (AASKeyDataType[]) value.getValue().getValue());
client.writeValue(writeNode, newValue);
// wait until the write is finished completely
Thread.sleep(WRITE_TIMEOUT);
// read new value
value = client.readValue(writeNode);
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertArrayEquals("new value not equal", newValue, (AASKeyDataType[]) value.getValue().getValue());
}
use of com.prosysopc.ua.stack.builtintypes.DataValue in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method writeNewValueIntern.
/**
* Writes the new value into the given node and checks whether the value was written correctly.
*
* @param client The OPC UA Client.
* @param writeNode The node which should be written.
* @param oldValue The old value.
* @param newValue The new value.
* @throws ServiceException If the operation fails
* @throws StatusException If the operation fails
* @throws InterruptedException If the operation fails
*/
public static void writeNewValueIntern(UaClient client, NodeId writeNode, Object oldValue, Object newValue) throws ServiceException, StatusException, InterruptedException {
DataValue value = client.readValue(writeNode);
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
if (oldValue == null) {
Assert.assertTrue("intial null value not equal", value.getValue().isEmpty());
} else {
Assert.assertEquals("intial value not equal", oldValue, value.getValue().getValue());
}
client.writeValue(writeNode, newValue);
// wait until the write is finished completely
Thread.sleep(WRITE_TIMEOUT);
// read new value
value = client.readValue(writeNode);
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertEquals("new value not equal", newValue, value.getValue().getValue());
}
use of com.prosysopc.ua.stack.builtintypes.DataValue in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkAssetKind.
/**
* Checks the AssetKind value in the given Node. The Node must already be
* the AssetKind Node.
*
* @param client The OPC UA Client
* @param kindNode The Asset Node
* @param modelingKind The expected Asset value.
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws StatusException If the operation fails
* @throws ServiceResultException If the operation fails
*/
private static void checkAssetKind(UaClient client, NodeId kindNode, AASAssetKindDataType assetKind) throws ServiceException, AddressSpaceException, StatusException, ServiceResultException {
checkDisplayName(client, kindNode, TestDefines.ASSET_KIND_NAME);
checkType(client, kindNode, Identifiers.PropertyType);
DataValue value = client.readValue(kindNode);
Assert.assertEquals(assetKind.ordinal(), value.getValue().intValue());
}
Aggregations