use of com.prosysopc.ua.stack.core.RelativePathElement 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.core.RelativePathElement in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkAssetInformationNode.
/**
* Searches for the AssetInformation Node and checks the values
*
* @param client The OPC UA client
* @param baseNode The base node where the AssetInformation Node is
* searched.
* @param aasns The namespace index of the AAS namespace.
* @throws ServiceException If the operation fails
* @throws ServiceResultException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws StatusException If the operation fails
*/
public static void checkAssetInformationNode(UaClient client, NodeId baseNode, int aasns) throws ServiceException, ServiceResultException, AddressSpaceException, StatusException {
List<RelativePath> relPath = new ArrayList<>();
List<RelativePathElement> browsePath = new ArrayList<>();
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.ASSET_INFORMATION_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(baseNode, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("checkAssetInformationNode Browse(1) Result Null", bpres);
Assert.assertTrue("checkAssetInformationNode Browse(1) Result: size doesn't match", bpres.length == 1);
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("checkAssetInformationNode Browse AssetInfo Node Null", targets);
Assert.assertTrue("checkAssetInformationNode Browse AssetInfo targets empty", targets.length > 0);
NodeId assetInfoNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull(assetInfoNode);
Assert.assertNotEquals(NodeId.NULL, assetInfoNode);
checkType(client, assetInfoNode, new NodeId(aasns, TestDefines.AAS_ASSET_INFO_TYPE_ID));
checkAssetKindNode(client, assetInfoNode, aasns, AASAssetKindDataType.Instance);
checkBillOfMaterialNode(client, assetInfoNode, aasns);
checkAasPropertyFile(client, assetInfoNode, aasns, TestDefines.DEFAULT_THUMB_NAME, AASModelingKindDataType.Instance, "", "image/png", "https://github.com/admin-shell/io/blob/master/verwaltungsschale-detail-part1.png", 0);
List<AASKeyDataType> keyList = new ArrayList<>();
keyList.add(new AASKeyDataType(AASKeyElementsDataType.Asset, "http://customer.com/assets/KHBVZJSQKIY", AASKeyTypeDataType.IRI));
checkAasReferenceNode(client, assetInfoNode, aasns, TestDefines.GLOBAL_ASSET_ID_NAME, keyList);
Map<String, String> map = new HashMap<>();
map.put("DeviceID", "QjYgPggjwkiHk4RrQiYSLg==");
map.put("EquipmentID", "538fd1b3-f99f-4a52-9c75-72e9fa921270");
checkIdentifierKeyValuePairListNode(client, assetInfoNode, aasns, TestDefines.SPECIFIC_ASSET_ID_NAME, map);
}
use of com.prosysopc.ua.stack.core.RelativePathElement in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpoint2Test method testUpdateSubmodel.
/**
* Test method for updating a complete submodel (Operational Data).
*
* @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 testUpdateSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("testUpdateSubmodel: 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_OPER_DATA_NODE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_RANGE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.RANGE_MAX_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_OPER_DATA_NODE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_REL_ELEMENT_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, AASRelationshipElementType.SECOND)));
browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.KEYS_VALUE_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testUpdateSubmodel Browse Result Null", bpres);
Assert.assertTrue("testUpdateSubmodel Browse 1 Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testUpdateSubmodel Browse 1 Result 1 Good", bpres[0].getStatusCode().isGood());
Assert.assertTrue("testUpdateSubmodel Browse 1 Result 2 Bad", bpres[1].getStatusCode().isBad());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testUpdateSubmodel RangeMax Null", targets);
Assert.assertTrue("testUpdateSubmodel RangeMax empty", targets.length > 0);
// update submodel
// 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(AASSimple.SUBMODEL_OPERATIONAL_DATA_ID).build()).build());
msg.setValue(new DefaultSubmodel.Builder().idShort(TestDefines.SUBMODEL_OPER_DATA_NODE_NAME).identification(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("https://acplt.org/NewOperationalData").build()).administration(new DefaultAdministrativeInformation.Builder().version("1.1").revision("5").build()).kind(ModelingKind.INSTANCE).submodelElement(new DefaultRelationshipElement.Builder().idShort("ExampleRelationshipElement").category("Parameter").description(new LangString("Example RelationshipElement object", "en-us")).description(new LangString("Beispiel RelationshipElement Element", "de")).semanticId(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.GLOBAL_REFERENCE).value("http://acplt.org/RelationshipElements/ExampleRelationshipElement").idType(KeyType.IRI).build()).build()).first(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.SUBMODEL).value("https://acplt.org/Test_Submodel").idType(KeyType.IRI).build()).key(new DefaultKey.Builder().type(KeyElements.SUBMODEL_ELEMENT_COLLECTION).value("ExampleSubmodelCollectionOrdered").idType(KeyType.ID_SHORT).build()).key(new DefaultKey.Builder().type(KeyElements.PROPERTY).value("ExampleProperty").idType(KeyType.ID_SHORT).build()).build()).second(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.SUBMODEL).value("http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial").idType(KeyType.IRI).build()).key(new DefaultKey.Builder().type(KeyElements.ENTITY).value("ExampleEntity").idType(KeyType.ID_SHORT).build()).key(new DefaultKey.Builder().type(KeyElements.PROPERTY).value("ExampleProperty2").idType(KeyType.ID_SHORT).build()).build()).build()).build());
service.getMessageBus().publish(msg);
Thread.sleep(DEFAULT_TIMEOUT);
// check that the old element is not there anymore, but the new element
bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testUpdateSubmodel Browse Result old Null", bpres);
Assert.assertTrue("testUpdateSubmodel Browse 2 Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testUpdateSubmodel Browse 2 Result 1 Bad", bpres[0].getStatusCode().isBad());
Assert.assertTrue("testUpdateSubmodel Browse 2 Result 2 Good", bpres[1].getStatusCode().isGood());
// read a value of the new SubmodelElement
targets = bpres[1].getTargets();
Assert.assertNotNull("testUpdateSubmodel RelationshipElement Null", targets);
Assert.assertTrue("testUpdateSubmodel RelationshipElement empty", targets.length > 0);
List<AASKeyDataType> smeValue = new ArrayList<>();
smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial", AASKeyTypeDataType.IRI));
smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Entity, "ExampleEntity", AASKeyTypeDataType.IdShort));
smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Property, "ExampleProperty2", AASKeyTypeDataType.IdShort));
DataValue value = client.readValue(client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId()));
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertArrayEquals("new SubmodelElement value not equal", smeValue.toArray(AASKeyDataType[]::new), (AASKeyDataType[]) value.getValue().getValue());
System.out.println("disconnect client");
client.disconnect();
}
use of com.prosysopc.ua.stack.core.RelativePathElement in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkSubmodelRef.
/**
* Searches for the Submodel reference Node with the given name
*
* @param client The OPC UA Client
* @param baseNode The base node where the AssetInformation Node is
* searched.
* @param aasns The namespace index of the AAS namespace.
* @param name The name of the desired Node
* @param submodelNode The Submodel Node
* @throws ServiceException If the operation fails
* @throws ServiceResultException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws StatusException If the operation fails
*/
public static void checkSubmodelRef(UaClient client, NodeId baseNode, int aasns, String name, NodeId submodelNode) throws ServiceException, ServiceResultException, AddressSpaceException, StatusException {
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(baseNode, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("checkSubmodelRef Browse Result Null", bpres);
Assert.assertTrue("checkSubmodelRef Browse Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("checkSubmodelRef Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("checkSubmodelRef Target Null", targets);
Assert.assertTrue("checkSubmodelRef Target empty", targets.length > 0);
NodeId refNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("checkSubmodelRef RefNode Null", refNode);
checkType(client, refNode, new NodeId(aasns, TestDefines.AAS_REFERENCE_TYPE_ID));
// check AAS Reference
List<AASKeyDataType> refKeys = new ArrayList<>();
refKeys.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, name, AASKeyTypeDataType.IRI));
checkAasReference(client, refNode, aasns, refKeys);
// check Reference to Submodel
List<ReferenceDescription> refs = client.getAddressSpace().browse(refNode, BrowseDirection.Forward, Identifiers.HasAddIn);
Assert.assertEquals(1, refs.size());
NodeId smNode = client.getAddressSpace().getNamespaceTable().toNodeId(refs.get(0).getNodeId());
Assert.assertEquals(smNode, submodelNode);
}
use of com.prosysopc.ua.stack.core.RelativePathElement 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());
}
Aggregations