use of com.prosysopc.ua.stack.builtintypes.DataValue in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkVariableBool.
/**
* Searches for a Variable (as Property) with the given Name and checks the
* boolean Value
*
* @param client The OPC UA client
* @param node The desired node
* @param aasns The namespace index of the AAS namespace
* @param name The Name of the desired Property
* @param propValue The expected value of the Property.
* @throws ServiceException If the operation fails
* @throws StatusException If the operation fails
*/
public static void checkVariableBool(UaClient client, NodeId node, int aasns, String name, boolean propValue) throws ServiceException, StatusException {
List<RelativePath> relPath = new ArrayList<>();
List<RelativePathElement> browsePath = new ArrayList<>();
browsePath.add(new RelativePathElement(Identifiers.HasProperty, 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("checkPropertyBool Browse Result Null", bpres);
Assert.assertTrue("checkPropertyBool Browse Result: size doesn't match", bpres.length == 1);
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("checkPropertyBool Node Targets Null", targets);
Assert.assertTrue("checkPropertyBool Node targets empty", targets.length > 0);
DataValue value = client.readValue(targets[0].getTargetId());
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertEquals(propValue, value.getValue().booleanValue());
}
use of com.prosysopc.ua.stack.builtintypes.DataValue in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkAasPropertyString.
/**
* 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 checkAasPropertyString(UaClient client, NodeId node, int aasns, String name, AASModelingKindDataType kind, String category, AASValueTypeDataType valueType, String 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;
// if (valueType == AASValueTypeDataType.LocalizedText) {
// var = new Variant(LocalizedText.english(propValue));
// }
// else {
// var = new Variant(propValue);
// }
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 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, LocalizedText[] oldValue, LocalizedText[] newValue) throws ServiceException, StatusException, InterruptedException {
DataValue value = client.readValue(writeNode);
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertArrayEquals("intial value not equal", oldValue, (LocalizedText[]) 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, (LocalizedText[]) value.getValue().getValue());
}
use of com.prosysopc.ua.stack.builtintypes.DataValue in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpoint2Test method testUpdateSubmodelElement.
/**
* Test method for updating a SubmodelElement.
*
* @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 testUpdateSubmodelElement() throws SecureIdentityException, IOException, ServiceException, Exception {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("testUpdateSubmodelElement: client connected");
int aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
// make sure one of the old elements exists, the new element exists not yet
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_DOC_NODE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.OPERATING_MANUAL_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_DOC_PROPERTY_TITLE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
browsePath.clear();
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_DOC_NODE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.OPERATING_MANUAL_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_DOC_FILE_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("testUpdateSubmodelElement Browse Result Null", bpres);
Assert.assertTrue("testUpdateSubmodelElement Browse 1 Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testUpdateSubmodelElement Browse 1 Result 1 Good", bpres[0].getStatusCode().isGood());
Assert.assertTrue("testUpdateSubmodelElement Browse 1 Result 2 Good", bpres[1].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testUpdateSubmodelElement Property Value Null", targets);
Assert.assertTrue("testUpdateSubmodelElement Property Value empty", targets.length > 0);
// read the (old) value of the SubmodelElement
DataValue value = client.readValue(client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId()));
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertEquals("old SubmodelElement value not equal", "OperatingManual", value.getValue().toString());
String newValue = "New Test Value";
// update SubmodelElement
// Send update event to MessageBus
ElementUpdateEventMessage msg = new ElementUpdateEventMessage();
msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value(TestDefines.SUBMODEL_DOC_NAME).build()).key(new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.SUBMODEL_ELEMENT_COLLECTION).value(TestDefines.OPERATING_MANUAL_NAME).build()).build());
msg.setValue(new DefaultSubmodelElementCollection.Builder().kind(ModelingKind.INSTANCE).idShort("OperatingManual").value(new DefaultProperty.Builder().kind(ModelingKind.INSTANCE).idShort("Title").value(newValue).valueType("string").build()).ordered(false).allowDuplicates(false).build());
service.getMessageBus().publish(msg);
Thread.sleep(DEFAULT_TIMEOUT);
bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testUpdateSubmodelElement Browse 2 Result Null", bpres);
Assert.assertTrue("testUpdateSubmodelElement Browse 2 Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testUpdateSubmodelElement Browse 2 Result 1 Good", bpres[0].getStatusCode().isGood());
Assert.assertTrue("testUpdateSubmodelElement Browse 2 Result 2 Bad", bpres[1].getStatusCode().isBad());
// read the (new) value of the SubmodelElement
targets = bpres[0].getTargets();
Assert.assertNotNull("testUpdateSubmodelElement Property New Value Null", targets);
Assert.assertTrue("testUpdateSubmodelElement Property New Value empty", targets.length > 0);
NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
value = client.readValue(writeNode);
System.out.println("testUpdateSubmodelElement: writeNode: " + writeNode.toString());
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertEquals("new SubmodelElement value not equal", newValue, value.getValue().toString());
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 testOpcUaEndpoint.
/**
* Test method for testing the OPC UA Endpoint
*
* @throws InterruptedException If the operation fails
* @throws Exception If the operation fails
*/
@Test
public void testOpcUaEndpoint() throws InterruptedException, Exception {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("testOpcUaEndpoint: 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());
// 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 aasNode = null;
NodeId assetNode = null;
NodeId submodelDocNode = null;
NodeId submodelTechDataNode = null;
NodeId submodelOperDataNode = null;
for (ReferenceDescription ref : refs) {
switch(ref.getBrowseName().getName()) {
case TestDefines.SIMPLE_AAS_NAME:
aasNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
break;
case TestDefines.SIMPLE_ASSET_NAME:
assetNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
break;
case TestDefines.SUBMODEL_DOC_NODE_NAME:
submodelDocNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
break;
case TestDefines.SUBMODEL_OPER_DATA_NODE_NAME:
submodelOperDataNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
break;
case TestDefines.SUBMODEL_TECH_DATA_NODE_NAME:
submodelTechDataNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
break;
default:
break;
}
}
Assert.assertNotNull("AAS Node not found", aasNode);
Assert.assertNotNull("Asset Node not found", assetNode);
Assert.assertNotNull("Submodel Documentation Node not found", submodelDocNode);
Assert.assertNotNull("Submodel TechnicalData Node not found", submodelTechDataNode);
Assert.assertNotNull("Submodel OperationalData Node not found", submodelOperDataNode);
// check Browse and Display Names
TestUtils.checkBrowseName(client, aasNode, TestDefines.SIMPLE_AAS_NAME);
TestUtils.checkDisplayName(client, aasNode, "AAS:" + TestDefines.SIMPLE_AAS_NAME);
TestUtils.checkDisplayName(client, submodelDocNode, "Submodel:" + TestDefines.SUBMODEL_DOC_NODE_NAME);
aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
// Asset
testAsset(client, assetNode);
// Submodels
testSubmodelDoc(client, submodelDocNode);
testSubmodelOperationalData(client, submodelOperDataNode);
testSubmodelTechnicalData(client, submodelTechDataNode);
// AAS
refs = client.getAddressSpace().browse(aasNode);
Assert.assertNotNull("Browse AASNode Refs Null", refs);
Assert.assertFalse("Browse AASNode Refs empty", refs.isEmpty());
testAas(client, aasNode, submodelDocNode, submodelOperDataNode, submodelTechDataNode);
System.out.println("disconnect client");
client.disconnect();
}
Aggregations