use of com.prosysopc.ua.client.UaClient in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointFullTest method testWriteSubmodelElementCollectionValue.
/**
* Test method for writing a Value of a SubmodelElementCollection. 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 testWriteSubmodelElementCollectionValue() 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("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.FULL_SUBMODEL_4_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SM_ELEM_COLL_UO_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SMEC_REL_ELEM_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
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("testWriteSubmodelElementCollectionValue Browse Result Null", bpres);
Assert.assertTrue("testWriteSubmodelElementCollectionValue Browse Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("testWriteSubmodelElementCollectionValue Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testWriteSubmodelElementCollectionValue ValueType Null", targets);
Assert.assertTrue("testWriteSubmodelElementCollectionValue ValueType empty", targets.length > 0);
NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
// The DataElementValueMapper changes the order of the elements
List<AASKeyDataType> newValue = new ArrayList<>();
newValue.add(new AASKeyDataType(AASKeyElementsDataType.GlobalReference, "https://iosb.fraunhofer.de/TestValue1", AASKeyTypeDataType.IRI));
TestUtils.writeNewValueArray(client, writeNode, null, newValue.toArray(AASKeyDataType[]::new));
System.out.println("disconnect client");
client.disconnect();
}
use of com.prosysopc.ua.client.UaClient in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointFullTest method testCallOperationSuccess.
/**
* Test method for successfully calling an operation.
*
* @throws SecureIdentityException If the operation fails
* @throws IOException If the operation fails
* @throws ServiceException If the operation fails
* @throws ServiceResultException If the operation fails
* @throws MethodCallStatusException If the operation fails
*/
@Test
public void testCallOperationSuccess() throws SecureIdentityException, IOException, ServiceException, ServiceResultException, MethodCallStatusException {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("client connected");
aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
int serverns = client.getAddressSpace().getNamespaceTable().getIndex(AasServiceNodeManager.NAMESPACE_URI);
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.FULL_SUBMODEL_3_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_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.FULL_SUBMODEL_3_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(serverns, TestDefines.FULL_OPERATION_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testCallOperationSuccess Browse Result Null", bpres);
Assert.assertTrue("testCallOperationSuccess Browse Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testCallOperationSuccess Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testCallOperationSuccess Object Targets Null", targets);
Assert.assertTrue("testCallOperationSuccess Object Targets empty", targets.length > 0);
NodeId objectNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("testCallOperationSuccess objectNode Null", objectNode);
targets = bpres[1].getTargets();
Assert.assertNotNull("testCallOperationSuccess Method Targets Null", targets);
Assert.assertTrue("testCallOperationSuccess Method Targets empty", targets.length > 0);
NodeId methodNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("testCallOperationSuccess methodNode Null", methodNode);
Variant[] inputArguments = new Variant[1];
inputArguments[0] = new Variant("123454");
Variant[] outputs = client.call(objectNode, methodNode, inputArguments);
Assert.assertNotNull("testCallOperationSuccess output Arguments Null", outputs);
Assert.assertEquals("testCallOperationSuccess output Arguments length not equal", 1, outputs.length);
Assert.assertEquals("testCallOperationSuccess output Argument 0 not equal", new Variant("XYZ1"), outputs[0]);
System.out.println("disconnect client");
client.disconnect();
}
use of com.prosysopc.ua.client.UaClient in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointFullTest method testDeleteSubmodel.
/**
* Test method for deleting a complete submodel.
*
* @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 testDeleteSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("testDeleteSubmodel: client connected");
aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
// make sure the element exists
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.FULL_SUBMODEL_5_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
// add more elements to the browse path
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.IDENTIFICATION_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "Id")));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testDeleteSubmodel Browse Result Null", bpres);
Assert.assertTrue("testDeleteSubmodel Browse Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testDeleteSubmodel Browse Result 1 Good", bpres[0].getStatusCode().isGood());
Assert.assertTrue("testDeleteSubmodel Browse Result 2 Good", bpres[1].getStatusCode().isGood());
// Send event to MessageBus
ElementDeleteEventMessage msg = new ElementDeleteEventMessage();
msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("https://acplt.org/Test_Submodel2_Mandatory").build()).build());
service.getMessageBus().publish(msg);
Thread.sleep(DEFAULT_TIMEOUT);
// check that the element is not there anymore
bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testDeleteSubmodel Browse Result Null", bpres);
Assert.assertTrue("testDeleteSubmodel Browse Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testDeleteSubmodel Browse Result 1 Bad", bpres[0].getStatusCode().isBad());
Assert.assertTrue("testDeleteSubmodel Browse Result 2 Bad", bpres[1].getStatusCode().isBad());
System.out.println("disconnect client");
client.disconnect();
}
Aggregations