use of com.prosysopc.ua.stack.core.RelativePathElement in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointTest method testWriteRangeValue.
/**
* Test method for writing a range. Writes the property in the OPC UA Server
* and checks the new value in the server.
*
* @throws SecureIdentityException If the operation fails
* @throws IOException If the operation fails
* @throws ServiceException If the operation fails
* @throws StatusException If the operation fails
* @throws InterruptedException If the operation fails
* @throws ServiceResultException If the operation fails
*/
@Test
public void testWriteRangeValue() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("testWriteRangeValue: 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.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)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testWriteRangeValue Browse Result Null", bpres);
Assert.assertTrue("testWriteRangeValue Browse Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("testWriteRangeValue Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testWriteRangeValue ValueType Null", targets);
Assert.assertTrue("testWriteRangeValue ValueType empty", targets.length > 0);
NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
TestUtils.writeNewValueIntern(client, writeNode, 100, 111);
System.out.println("disconnect client");
client.disconnect();
}
use of com.prosysopc.ua.stack.core.RelativePathElement in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointTest method testAddSubmodel.
/**
* Test method for adding a complete submodel to an AAS.
*
* @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 testAddSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("testAddProperty: client connected");
aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
String submodelName = "NewSubmodelTest1";
// make sure the element doesn't exist 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, submodelName)));
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("testAddSubmodel Browse Result Null", bpres);
Assert.assertTrue("testAddSubmodel Browse Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("testAddSubmodel Browse Result Bad", bpres[0].getStatusCode().isBad());
// Send event to MessageBus
ElementCreateEventMessage msg = new ElementCreateEventMessage();
msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.ASSET_ADMINISTRATION_SHELL).value("http://customer.com/aas/9175_7013_7091_9168").build()).build());
msg.setValue(new DefaultSubmodel.Builder().idShort(submodelName).identification(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("https://acplt.org/NewSubmodelTest1").build()).administration(new DefaultAdministrativeInformation.Builder().version("0.9").revision("0").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 element is there now
bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testAddSubmodel Browse Result Null", bpres);
Assert.assertTrue("testAddSubmodel Browse Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("testAddSubmodel Browse Result Good", bpres[0].getStatusCode().isGood());
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 checkIdentificationNode.
/**
* Searches for the Identification Node in the given Node and checks the
* corresponding values.
*
* @param client The OPC UA Client
* @param baseNode The base node where the Identification Node is searched.
* @param aasns The namespace index of the AAS namespace.
* @param idType The expected IdType
* @param id The expected ID
* @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 checkIdentificationNode(UaClient client, NodeId baseNode, int aasns, AASIdentifierTypeDataType idType, String id) 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.IDENTIFICATION_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(baseNode, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("checkIdentificationNode Browse Result Null", bpres);
Assert.assertTrue("checkIdentificationNode Browse Result: size doesn't match", bpres.length == 1);
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("checkIdentificationNode Browse Target Node Null", targets);
Assert.assertTrue("checkIdentificationNode Browse targets empty", targets.length > 0);
checkIdentification(client, client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId()), aasns, idType, id);
}
use of com.prosysopc.ua.stack.core.RelativePathElement in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkAasPropertyFile.
/**
* Checks the File 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 mimeType The expected MimeType
* @param propValue The expected Value
* @param fileSize the expected File Size.
* @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 checkAasPropertyFile(UaClient client, NodeId node, int aasns, String name, AASModelingKindDataType kind, String category, String mimeType, String propValue, int fileSize) 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(node, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("checkAasPropertyFile Browse Property Result Null", bpres);
Assert.assertTrue("checkAasPropertyFile Browse Property Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("checkAasPropertyFile Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("checkAasPropertyFile Property Null", targets);
Assert.assertTrue("checkAasPropertyFile 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, new ArrayList<>());
relPath.clear();
browsePath.clear();
browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_MIME_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)));
browsePath.clear();
browsePath.add(new RelativePathElement(Identifiers.HasAddIn, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_FILE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(0, TestDefines.PROPERTY_SIZE_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(propertyNode, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("checkAasPropertyFile Browse Value & Type Result Null", bpres);
Assert.assertTrue("checkAasPropertyFile Browse Value & Type Result: size doesn't match", bpres.length == 3);
// MimeType
targets = bpres[0].getTargets();
Assert.assertNotNull("checkAasPropertyFile MimeType Null", targets);
Assert.assertTrue("checkAasPropertyFile MimeType empty", targets.length > 0);
DataValue value = client.readValue(targets[0].getTargetId());
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertEquals(mimeType, value.getValue().toString());
// Value
targets = bpres[1].getTargets();
Assert.assertNotNull("checkAasPropertyFile Value Null", targets);
Assert.assertTrue("checkAasPropertyFile value empty", targets.length > 0);
value = client.readValue(targets[0].getTargetId());
Assert.assertEquals(propValue, value.getValue().toString());
if (fileSize > 0) {
// File Size
if (bpres[2].getStatusCode().isBad()) {
System.out.println("checkAasPropertyFile File Status " + bpres[2].getStatusCode());
}
targets = bpres[2].getTargets();
Assert.assertNotNull("checkAasPropertyFile File Null", targets);
Assert.assertTrue("checkAasPropertyFile File empty", targets.length > 0);
value = client.readValue(targets[0].getTargetId());
Assert.assertEquals(fileSize, value.getValue().intValue());
}
}
use of com.prosysopc.ua.stack.core.RelativePathElement in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkIdentifierKeyValuePairListNode.
/**
* Searches for an IdentifierKeyValuePairList Node with the given Name and
* checks the corresponding values.
*
* @param client The OPC UA Client
* @param baseNode The base node where the desired Node is searched.
* @param aasns The namespace index of the AAS namespace.
* @param name The desired Name of the Node
* @param map The expected values.
* @throws ServiceException If the operation fails
* @throws ServiceResultException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws StatusException If the operation fails
*/
private static void checkIdentifierKeyValuePairListNode(UaClient client, NodeId baseNode, int aasns, String name, Map<String, String> map) 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("checkIdentifierKeyValuePairListNode Browse Result Null", bpres);
Assert.assertTrue("checkIdentifierKeyValuePairListNode Browse Result: size doesn't match", bpres.length == 1);
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("checkIdentifierKeyValuePairListNode Browse Target Node Null", targets);
Assert.assertTrue("checkIdentifierKeyValuePairListNode Browse targets empty", targets.length > 0);
NodeId listNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("checkIdentifierKeyValuePairListNode Ref Node Null", listNode);
Assert.assertNotEquals("checkIdentifierKeyValuePairListNode Ref Node Null", NodeId.NULL, listNode);
checkType(client, listNode, new NodeId(aasns, TestDefines.AAS_ID_KEY_VALUE_PAIR_LIST_ID));
List<NodeId> nodeList = new ArrayList<>();
List<ReferenceDescription> refs = client.getAddressSpace().browse(listNode);
for (ReferenceDescription ref : refs) {
NodeId nid = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
nodeList.add(nid);
}
for (NodeId node : nodeList) {
checkIdentifierKeyValuePairNode(client, node, aasns, map);
}
}
Aggregations