Search in sources :

Example 11 with AASKeyDataType

use of opc.i4aas.AASKeyDataType 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.assertEquals("testWriteSubmodelElementCollectionValue Browse Result: size doesn't match", 1, bpres.length);
    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();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) AASKeyDataType(opc.i4aas.AASKeyDataType) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Aggregations

AASKeyDataType (opc.i4aas.AASKeyDataType)11 ArrayList (java.util.ArrayList)10 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)9 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)8 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)8 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)8 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)7 RelativePath (com.prosysopc.ua.stack.core.RelativePath)7 UaClient (com.prosysopc.ua.client.UaClient)5 Test (org.junit.Test)5 DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)3 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 StatusException (com.prosysopc.ua.StatusException)2 ElementUpdateEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage)2 Key (io.adminshell.aas.v3.model.Key)2 LangString (io.adminshell.aas.v3.model.LangString)2 Reference (io.adminshell.aas.v3.model.Reference)2 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)2 HashMap (java.util.HashMap)2